我有:
<ul class="webServicesURLS">
<li><asp:HyperLink ID="restURL" runat="server" Text="REST" /></li>
<li><asp:HyperLink ID="bboxURL" runat="server" Text="BBox" /></li>
<li><asp:HyperLink ID="esbURL" runat="server" Text="ESB" /></li>
</ul>
如果数据库中存在这样的链接,则在代码后面添加 href 链接。
我想隐藏<li>
没有添加任何 href 链接,使用 jQuery,如果我没有任何 href 链接,则隐藏 <ul>
.
最佳答案
您可以组合:not()和 :has()与 has attribute选择器和 :visible选择器分别:
$("li:not(:has(a[href]))").hide();
$("ul:not(:has(li:visible))").hide();
关于c# - 如果 href 为空则隐藏 li 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6898922/