以下是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