获取没有特定类的所有复选框

Get all checkboxes without certain class

本文关键字:复选框 获取      更新时间:2023-09-26

我需要找到所有没有特定类的复选框。这就是我所拥有的,但这不起作用。我需要选中所有没有类名称为"features"的复选框。

var value = 'features';
$('input:checkbox[class!="'+value+'"]').attr("checked", "");

使用:not

var checkBoxes = $("input:checkbox:not(." + value + ")");

这就是你想要的:小提琴在这里!

var cname = "features";
$('input:checkbox:not(.'+cname+')').each(function () {
        $(this).prop('checked', true);
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" name="vehicle" value="one" class="features">one<br>
<input type="checkbox" name="vehicle" value="two" class="two">two<br>
<input type="checkbox" name="vehicle" value="three" class="three">three<br>
<input type="checkbox" name="vehicle" value="four" class="features" > four