我有 UL 标签,其中包含 Li 和许多类名
,
我想显示
那些类名相同
的Li并隐藏其他的。
这里 <强> JSFiddle DEMO
例如,如果我点击 class1,那么“John,Michle,Alex”将可见,其余的都必须隐藏
编辑: 隐藏列表时也对 Li 进行排序
答案:
通过将 $(this).show();
更改为
$(this).parent('Li').show();
解决了我的空格问题:)
最佳答案
您在 jsfiddle 中犯了一个简单的错误。 这是 fix .
我改变了线路:
if ($('#emplistName Ul Li Span').hasClass(className) === true) {
至:
if ($(this).hasClass(className) === true) {
关于jquery - 如何使用 Jquery 显示/隐藏选定的 Li,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15174205/