如果它 children 从 parent 中删除 href,否则
If it has children remove href from parent, else
我有一个包含子 ul 和 sub-sub ul 的菜单项列表。对于 sub-sub uls 我想从 parent 中删除 href 只有当 parent 有 children.
这是我目前所知道的,不太确定如何将其转换为 if -> else 语句。
$('#menu-sidebar-menu > li > ul:has(li) > a').children(['li']).find('a:first').removeAttr('href');
<li class="cat-item cat-item-89"><a href="#" title="Detailed posts for products.">Products</a>
<ul class='children'>
<li class="cat-item cat-item-100"><a href="#" title="Detailed posts for products.">ALL</a>
</li>
<li class="cat-item cat-item-94"><a href="#" title="Post about products for Ducati sportbikes.">Ducati</a>
</li>
<li class="cat-item cat-item-91"><a href="#" title="Posts about products for Honda sportbikes.">Honda</a>
<ul class='children'>
<li class="cat-item cat-item-104"><a href="#" title="testing">CBR 1000RR</a>
</li>
<li class="cat-item cat-item-103"><a href="#" title="TESTING">CBR 600RR</a>
</li>
</ul>
</li>
<li class="cat-item cat-item-93"><a href="#" title="Post about products for Kawasaki sportbikes.">Kawasaki</a>
非常感谢您的任何意见。
塞尔吉奥
是这样的吗?
$.each($("ul > li"), function (index, obj) {
if ($(obj).has("ul").length) {
$(obj).has("ul").find("a:first").removeAttr("href");
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li class="cat-item cat-item-89"><a href="#" title="Detailed posts for products.">Products</a>
<ul class='children'>
<li class="cat-item cat-item-100"><a href="#" title="Detailed posts for products.">ALL</a>
</li>
<li class="cat-item cat-item-94"><a href="#" title="Post about products for Ducati sportbikes.">Ducati</a>
</li>
<li class="cat-item cat-item-91"><a href="#" title="Posts about products for Honda sportbikes.">Honda</a>
<ul class='children'>
<li class="cat-item cat-item-104"><a href="#" title="testing">CBR 1000RR</a>
</li>
<li class="cat-item cat-item-103"><a href="#" title="TESTING">CBR 600RR</a>
</li>
</ul>
</li>
<li class="cat-item cat-item-93"><a href="#" title="Post about products for Kawasaki sportbikes.">Kawasaki</a>
</li>
</ul>
我有一个包含子 ul 和 sub-sub ul 的菜单项列表。对于 sub-sub uls 我想从 parent 中删除 href 只有当 parent 有 children.
这是我目前所知道的,不太确定如何将其转换为 if -> else 语句。
$('#menu-sidebar-menu > li > ul:has(li) > a').children(['li']).find('a:first').removeAttr('href');
<li class="cat-item cat-item-89"><a href="#" title="Detailed posts for products.">Products</a>
<ul class='children'>
<li class="cat-item cat-item-100"><a href="#" title="Detailed posts for products.">ALL</a>
</li>
<li class="cat-item cat-item-94"><a href="#" title="Post about products for Ducati sportbikes.">Ducati</a>
</li>
<li class="cat-item cat-item-91"><a href="#" title="Posts about products for Honda sportbikes.">Honda</a>
<ul class='children'>
<li class="cat-item cat-item-104"><a href="#" title="testing">CBR 1000RR</a>
</li>
<li class="cat-item cat-item-103"><a href="#" title="TESTING">CBR 600RR</a>
</li>
</ul>
</li>
<li class="cat-item cat-item-93"><a href="#" title="Post about products for Kawasaki sportbikes.">Kawasaki</a>
非常感谢您的任何意见。
塞尔吉奥
是这样的吗?
$.each($("ul > li"), function (index, obj) {
if ($(obj).has("ul").length) {
$(obj).has("ul").find("a:first").removeAttr("href");
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li class="cat-item cat-item-89"><a href="#" title="Detailed posts for products.">Products</a>
<ul class='children'>
<li class="cat-item cat-item-100"><a href="#" title="Detailed posts for products.">ALL</a>
</li>
<li class="cat-item cat-item-94"><a href="#" title="Post about products for Ducati sportbikes.">Ducati</a>
</li>
<li class="cat-item cat-item-91"><a href="#" title="Posts about products for Honda sportbikes.">Honda</a>
<ul class='children'>
<li class="cat-item cat-item-104"><a href="#" title="testing">CBR 1000RR</a>
</li>
<li class="cat-item cat-item-103"><a href="#" title="TESTING">CBR 600RR</a>
</li>
</ul>
</li>
<li class="cat-item cat-item-93"><a href="#" title="Post about products for Kawasaki sportbikes.">Kawasaki</a>
</li>
</ul>