以下是JavaScript的除外。变化让孩子在jQuery中拥有GrandChildren
function showContent(layer, animate) { $("#background").show(); $("footer").hide(); $("#announcement").hide(); $("#content").html($("#" + layer + "_html").comments()); $("nav").children().each(function() { if ($(this).attr("id").search(layer) == -1) { $(this).addClass("inactive"); } else { $(this).removeClass("inactive"); } }); if (animate == true) { $('html,body').animate({scrollTop: $("nav").offset().top - 16 - 40}, 200, "swing"); } // setUpHover(); setupFullScreen(); setupImageViewers(); setupHovers(); // Load analytics tracking setTimeout(function() { $("#tracker").attr("src", "/track/" + layer + "/") }, 500); window.location.hash = layer; } // Set up the on click functions for the different menus $("nav").children().click(function() { showContent($(this).attr("id").split("_")[1], true); });
这里是HTML的摘录:
现在,这里是我的问题。有了这个js和html,它就可以做到这一点。然而,当我在导航里面添加一个需要DIV这样它打破:
我想这个问题是在原JS以上,大约有(“NAV”)两行儿童和想象。我的新代码,他们现在实际上是孙子或其他人。所以很可能需要对这两条线进行微小的调整,但不知道该如何调整。
在此先感谢!
用'find'替换'children'。 –
这太有趣了,我刚刚根据我的发现在您的评论之前尝试过:http://www.hackosis.com/jquery-descendants-and-children/但是它没有工作:( – cchiera