如何在jQuery中处理两个进程

how to handle two processes in jQuery

本文关键字:两个 进程 处理 jQuery      更新时间:2023-09-26

下面的代码只处理包含setInterval的脚本,而其他脚本是不可访问的。

我应该如何处理这两个脚本?

<html>
<head>
    <title>Top News</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script type="text/javascript" src="jquery/jquery-1.5.2.js"></script>
</head>
<body>
    <div class="top-new-content">
        <div class="one" style="position: absolute; left: 10px; top: 10px; background:yellow;width:300px;height:100px; border: 1px #979797 solid">
            <img src="image/news/img.jpg" width="100px" height="50px" />
        </div>
        <div class="two" style="position: absolute; left: 10px; top: 10px;background:yellow;width:300px;height:100px; border: 1px #979797 solid">
            two two two two two two two ...
        </div>
        <div class="three" style="position: absolute; left: 10px; top: 10px; background:yellow;width:300px;height:100px; border: 1px #979797 solid">
            three three three three three ...
        </div>
    </div>
    <div class="top-news-category" style="position: absolute; left: 10px; top: 111px; border: 1px #979797 solid; border-top: none; background-color: yellow">
        &nbsp;<span id="a">One |</span>
        <span id="b">Two |</span>
        <span id="c">Three</span>&nbsp;
    </div>
</body>
<script type="text/javascript">
    $(document).ready(function(){
        setInterval(function() {
            $('div.one').fadeIn(1000);
            $('div.two').fadeOut(1000);
            $('div.three').fadeOut(1000);
            $("*").delay(3000);
            $('div.two').fadeIn(1000);
            $('div.one').fadeOut(1000);
            $('div.three').fadeOut(1000);
            $("*").delay(3000);
            $('div.three').fadeIn(1000);
            $('div.one').fadeOut(1000);
            $('div.two').fadeOut(1000);
            $("*").delay(3000);
        }, 0);
    });
</script>
<script type="text/javascript">
    $(document).ready(function(){
        $(".top-news-category #a").click(function(){
            $("div.one").fadeIn("slow", "linear");
            $("div.two").fadeOut("slow", "linear");
            $("div.three").fadeOut("slow", "linear");
        });
        $(".top-news-category #b").click(function(){
            alert("TWO");
            $("div.one").fadeOut("slow", "linear");
            $("div.three").fadeOut("slow", "linear");
            $("div.two").fadeIn("slow", "linear");
        });
        $(".top-news-category #c").click(function(){
            $("div.one").fadeOut("slow", "linear");
            $("div.three").fadeOut("slow", "linear");
            $("div.three").fadeIn("slow", "linear");
        });
    });
</script>

hi ammar我已经通过答案检查进行了编辑。

setInterval(function() {
    $('div.one').fadeIn(1500);
    $('div.two').fadeOut(1500);
    $('div.three').fadeOut(1500);
    $("*").delay(15000);
    $('div.two').fadeIn(1500);
    $('div.one').fadeOut(1500);
    $('div.three').fadeOut(1500);
    $("*").delay(15000);
    $('div.three').fadeIn(1500);
    $('div.one').fadeOut(1500);
    $('div.two').fadeOut(1500);
    $("*").delay(15000);
}, 100000);

当您研究setInterval方法描述时,第一个参数是函数,第二个参数是需要一次又一次执行函数的持续时间(以毫秒为单位(。先前您已将其指定为0,这导致了问题。希望这对你有帮助,。。。。

问题是你没有在document.ready上运行你的第一个代码段。试着把它包装在$(document).ready(...上,它应该可以正常工作。

脚本标记需要在结束标记之前位于内部。此外,我建议用"documentready"来包装这两个脚本标记。

JQuery中使用文档就绪的最干净/最短方式。

$(function() {
    ...my code here...
});