假设我有以下 html
复选框:
<input class="filters identity0" name="filters[Device][]" type="checkbox" value="ipad">
<input class="filters identity0 identity1 " name="filters[Device][]" type="checkbox" value="ipad">
<input class="filters identity identity2" name="filters[Device][]" type="checkbox" value="ipad">
我想显示其中至少有一个公共(public)类的复选框。我为实现此目的而编写的 jQuery 是:
$('label:not(:has('filters identity0'))').hide();
现在这应该隐藏前两个复选框,因为它们具有共同的 identity0
但它隐藏了所有它们。这是我正在尝试做的一个例子。任何有关此问题的帮助将不胜感激。
这就是我实际上在做的事情。
$('body').on('change', '.filters', function () {
if(this.checked){
var _class=$(this).attr('class');
$('label:not(:has('+_class+'))').hide();
console.log(_class);
}
});
最佳答案
您可以使用:
.hasClass("identity0");
关于javascript - 如何隐藏没有给定类集的复选框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45836153/