隐藏" next"最后一项的按钮

时间:2014-09-18 09:07:45

标签: php jquery hide

我有几个div,访问者可以使用“上一个”和“下一个”按钮翻阅。这是我写的代码,工作正常:

$("#next").click(function(){
    $(".open").removeClass("open").fadeOut(200, function(){ // remove .open from current opened detail and fade out
        $(this).next(".outsourcing").addClass("open").fadeIn(400); // add .open to next detail and fade in
        if ($(".open").hasClass(".item<?php echo $outsourcing_count-1; ?>")) {
            $("#next").hide();
        }
    })
});

在最后一项上,我想隐藏“下一步”按钮。最后一项不是包含div中的最后一个子项,因此我使用PHP将其标记为特殊类,如上面的if语句所示。但if声明似乎没有解雇,任何想法?谢谢!

2 个答案:

答案 0 :(得分:1)

删除“。”在item之前..当你使用hasClass

时,你不必给出类标识符
 if ($(".open").hasClass("item<?php echo $outsourcing_count-1; ?>")) {
            $("#next").hide();
        }

答案 1 :(得分:0)

您不需要使用PHP注入值来测试它是否是最后一项

if ($(".open").is(':last-child')) 
{
      // must be the last item
}

会做,或者(如果它不是该容器中的最后一个子节点)只检查是否有next项:

if (!$(".open").next(".outsourcing").length) 
{
      // must be the last item
}

无论如何,你得到了这个想法。只测试特定的DOM配置,而不是搞乱面板编号。如果您不需要,则不应添加依赖项。

相关问题