我在html文件中有一个动态树形菜单。其结构是-
<ul id="cat_menu" class="cat_menu">
<li><a href="#">iPods</a></li>
<li><a href="#">iPads</a></li>
<li><a href="#">iPhones</a>
<ul>
<li><a href="#">3GS</a></li>
<li><a href="#">4G</a></li>
</ul>
</li>
</ul>这是一个垂直的树菜单。菜单没问题。但我想显示一个小箭头,如果一个导航有潜航器。就像第三个。我想在"iPhones“导航中显示一个箭头。为此,我必须确定nav是否有潜艇。我试着用jquery-
$(document).ready(function(){
$("ul#cat_menu li").each(function(){
if($(this:has(ul))){
$(this).css('background','red');//I will use code here for arrow.
}
})
});但它不起作用。有什么帮助吗??提前谢谢。
发布于 2011-05-09 17:57:50
试试这个;
$("ul#cat_menu li").each(function(){
if($('ul',this).length){
$(this).css('background','red');//I will use code here for arrow.
}
})发布于 2011-05-09 18:01:11
您的整个实现可以替换为:
// nothing happens if there are no matches, no need for a condition
// or the `.each` since ul#cat_menu li's are implicitly iterated
$("ul#cat_menu li").find('ul > li').css("border", "1px solid red");https://stackoverflow.com/questions/5935209
复制相似问题