这是麻烦的功能。我不能正确找到嵌套UL
元素:查找列表项的子元素
function showContentAgency(id){
$.post("assets/includes/contentAgency.php?id=id", {id: id}, function(data){
$(this).parent().find("ul").html(data).show();
$(this).addClass("nav-active");
});
}
这里的点击功能:
$("ul.top-level").on("click", "ul.top-level li.agency a", function (event) {
var numbs = $(this).attr("href").match(/id=([0-9]+)/)[1];
$("ul.top-level li a").removeClass("nav-active");
$(this).addClass("nav-active");
showContentAgency(numbs);
event.preventDefault();
});
我的HTML看起来像这样:
<ul class="top-level" style="display: block; ">
<li class="agency"><a href="contentAgency.php?id=6" class="">Agency Name</a>
<ul>
<!--Content in here -->
</ul>
</li>
</ul>
唉唉!是的,谢谢。它的工作,我欣赏它。 – Yahreen 2012-03-23 17:49:47
+1打我(和我发布相同的东西)。 – 2012-03-23 17:50:28