下面是我的代码,我想使用 JQuery 通过中间出现的值来隐藏“li”。
HTML:
<ul id="tagCloud">
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
<li>Item5</li>
</ul>
这段代码的输出是:
Item1
Item2
Item3
Item4
Item5
我想使用 JQuery 按其值隐藏第三个“li”。
我想要这样的输出:
Item1
Item2
Item4
Item5
我该怎么做?谢谢。
最佳答案
您可以使用 :contains
隐藏包含 Item3
的任何内容
$('#tagCloud li:contains(Item3)').hide();
或更具体地使用过滤器
$('#tagCloud li').filter(function() {
return $(this).text() === 'Item3';
}).hide();
或不区分大小写
$('#tagCloud li').filter(function() {
return $(this).text().toLowerCase() === 'item3';
}).hide();
关于javascript - 使用 JQuery 按值隐藏列表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23588903/