我有几个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语句中看到的那样。但是,如果声明似乎没有开火,有什么想法吗?谢谢!
发布于 2014-09-18 09:10:36
删除“。”在项目之前..。在使用hasClass时,不必提供类标识符
if ($(".open").hasClass("item<?php echo $outsourcing_count-1; ?>")) {
$("#next").hide();
}发布于 2014-09-18 09:11:41
您不需要使用PHP注入值来测试它是否是最后一项
if ($(".open").is(':last-child'))
{
// must be the last item
}可以,或者(如果它不是容器中的最后一个子容器),只需检查是否有一个next项:
if (!$(".open").next(".outsourcing").length)
{
// must be the last item
}不管怎样,你都明白了。只需要测试特定的DOM配置,而不是乱搞面板编号。如果不需要,不应该添加依赖项。
https://stackoverflow.com/questions/25908549
复制相似问题