小编Roh*_*hra的帖子

隐藏空<li>

<li>如果它们是空的或者如果有任何空白,我想隐藏所有<li>.

我是这样做的:

$("li:empty").filter(function(i,v){return $.trim($(v).text()).length == 0;}).css('display', 'none');
Run Code Online (Sandbox Code Playgroud)

这是错误的语法吗?

如果我创建一个类使空<li>隐形,它工作正常.像这样:

$("li[class='hideLi']").filter(function(i,v){return $.trim($(v).text()).length == 0;}).css('display', 'none');
Run Code Online (Sandbox Code Playgroud)

但我不知道哪个<li>是空的.

任何人都可以帮助我PLZ.display=none如果<li>是空的我想做.

这是我的代码: -

<script src="http://code.jquery.com/jquery-latest.js"></script>




<script>
  $(document).ready(function(){
    $("td:empty").css('display', 'none');
     $("div:empty").css('display', 'none');
     $(!$.trim('li:empty')).hide();
     $("li[class='hideLi']").filter(function(i,v){return $.trim($(v).text()).length == 0;}).css('display', 'none');
  });
  </script>

<ul>
  <li style="border:red solid 1px ">HI</li>
  <li style="border:green solid 1px ">  </li>
    <li style="border:blue solid 1px " class="hideLi">  </li>
  </ul>
Run Code Online (Sandbox Code Playgroud)

谢谢,

html jquery trim hide html-lists

7
推荐指数
2
解决办法
4277
查看次数

标签 统计

hide ×1

html ×1

html-lists ×1

jquery ×1

trim ×1