[英]remove div even if single ul li empty inside the div
我有以下代码。
<div id="rem-download-ref" class="download-reference">
<ul>
<li><strong>Download »</strong></li>
<li><asp:Image ID="imgepub" runat="server" align="absmiddle" ImageUrl="/images/icon/epub.png" Visible="false" width="22" height="22" /><asp:HyperLink ID="HyperLinkePub" runat="server"
NavigateUrl='<%# Eval("epub_path").ToString() + Eval("epub_name").ToString() %>'
Visible="false">ePUB</asp:HyperLink>
</li>
<li><asp:Image ID="imgmobi" runat="server" align="absmiddle" ImageUrl="/images/icon/mobi.png" Visible="false" width="22" height="22" /><asp:HyperLink ID="HyperLinkMobi" runat="server"
NavigateUrl='<%# Eval("mobi_path").ToString() + Eval("mobi_name").ToString() %>'
Visible="false">mobi</asp:HyperLink>
</li>
</ul>
</div>
我需要的是如果任何<li>
为空,那么我想删除整个div。
如何使用javascript做到这一点?
您的要求不太明确。 但这就是你想要的吗?
$("#rem-download-ref li").each(function(i, v) {
if ($(v).text() == "") {
$("#rem-download-ref").remove();
break;
}
});
请不要忘记添加jQuery
<script type="text/javascript" src="http://jquery.com/src/jquery-latest.js"></script>
将您的<div>
为<asp:Panel>
。 然后,在容器的数据绑定事件上,如果epub_path
和mobi_path
为null或为空,则将面板的可见性设置为false。
如果没有更多代码,很难给出更详细的答案。 哪种控件正在执行数据绑定? GridView
? ListView
? Repeater
? 数据源是什么类型的对象?
看看是否有帮助,您可能需要将其包装到一个函数中或至少放置在rem-download-ref
,
确保所有元素内联没有空格
<div id="rem-download-ref" class="download-reference"><ul><li id="o1"><strong id="ccc">Download »</strong></li><li id="o2"></li></ul></div>
。
var dc = document.getElementById("rem-download-ref").firstChild
for (var n = 0; n <dc.childNodes.length; n++) {
//if (rem-download-ref not null and li not null remove rem-download-ref
if(dc.parentNode && dc.childNodes[n].firstChild==null){
dc.parentNode.removeChild(dc);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.