这有什么问题?我试图隐藏所有空的李.
$(document).ready(function() {
$("#details li").each(function() {
if ($(this).length == 0) {
$(this).css({ display: "none" }); ;
}
});
});
Run Code Online (Sandbox Code Playgroud)
标记:
<ul id="details">
<li>Lorem Ipsum</li>
<li>Lorem Ipsum</li>
<li>Lorem Ipsum</li>
<li>Lorem Ipsum</li>
<li></li>
<li></li>
<li>Lorem Ipsum</li>
<li>Lorem Ipsum</li>
<li>Lorem Ipsum</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
先感谢您
我想你想要的是.text()长度,就像这样:
$(function() {
$("#details li").each(function() {
if ($(this).text().length == 0) {
$(this).css({ display: "none" }); ;
}
});
});
Run Code Online (Sandbox Code Playgroud)
或者更短一些:
$("#details li").filter(function() {
return $(this).text().length == 0;
}).hide();
Run Code Online (Sandbox Code Playgroud)
还是略有不同的支票,你的目的的作品中,@礼貌拉斐尔:
$("#details li:empty").hide();
Run Code Online (Sandbox Code Playgroud)