Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery:在<;p>;,除了一个,把所有的都藏起来。然后重复_Javascript_Jquery - Fatal编程技术网

Javascript jQuery:在<;p>;,除了一个,把所有的都藏起来。然后重复

Javascript jQuery:在<;p>;,除了一个,把所有的都藏起来。然后重复,javascript,jquery,Javascript,Jquery,我的代码基本上是正确的。它隐藏某个类的所有标记,然后单击即可旋转到下一个标记。我希望它在到达最后一个标记时重置,并再次显示第一个标记,但它没有。我做错了什么 下面是javascript代码: $(document).ready(function() { var curPoem=1; if ($("h2.title").length==1) { break; } else { $("h2.title").eq(0).after("\<sup\>\<small style='fo

我的代码基本上是正确的。它隐藏某个类的所有
标记,然后单击即可旋转到下一个标记。我希望它在到达最后一个
标记时重置,并再次显示第一个标记,但它没有。我做错了什么

下面是javascript代码:

$(document).ready(function() {
var curPoem=1;

if ($("h2.title").length==1) { break; }
else { $("h2.title").eq(0).after("\<sup\>\<small style='font-size: 10px; margin: 0 10px; float: right; position: relative; right: 50px; bottom: 30px;' \>Click the title to change the poem\<\/small\>\<\/sup>") }

$("p.lit").not($("p.lit:eq(0)")).hide();
$("p.lit").eq(0).show();
$("h2.title").not($("h2.title:eq(0)")).hide();

$("h2.title").eq(0).bind("click", function()
    {   $("p.lit").not($("p.lit:eq("+curPoem+")")).hide();
        $("p.lit").eq(curPoem).show();

        $("h2.title").eq(0).empty();
        for (i=0; i<$("h2.title").length-1; i++)
        {   $("h2.title").eq(0).append(litTitle[curPoem]);
        }
        document.title=litTitle[curPoem]+" by "+author;

        if (curPoem<$("h2.title").length)
        {   curPoem=(curPoem+1);
        }
        else if (curPoem==$("h2.title").length)
        {   curPoem=1;
        }
    });
});
$(文档).ready(函数(){
var=1;
如果($($h2.title”).length==1{break;}
else{$(“h2.title”).eq(0)。在(\\单击标题以更改诗歌\\”)之后
$(“p.lit”).not($((“p.lit:eq(0)”)).hide();
$(“p.lit”).eq(0.show();
$($h2.title”).not($($h2.title:eq(0)”).hide();
$(“h2.title”).eq(0).bind(“单击”,函数()
{$(“p.lit”).not($($(p.lit:eq(“+curPoem+”)).hide();
$(“p.lit”).eq(curPoem.show();
$(“h2.title”).eq(0).empty();

对于(i=0;i这不是一个完整的示例,但我抓起了您的代码并进行了尝试,得到了以下结果:

我用“返回”替换了“中断”,它纠正了这个错误

另外:我认为您修改
curPoem
索引的逻辑有点不正确。它从1开始,变为2,然后保持不变。您需要旋转回零。这就是我使用的:

if (curPoem<$("h2.title").length)
{
    curPoem++;
}
if (curPoem==$("h2.title").length)
{
    curPoem=0;
}

if(curpoemin)包括一些示例HTML请求示例添加的示例,以及它当前使用的各种变量。谢谢。是的,我昨天实际使用了它。我以前不能,因为我的大脑被炸了。
if (curPoem<$("h2.title").length)
{
    curPoem++;
}
if (curPoem==$("h2.title").length)
{
    curPoem=0;
}