0
我需要找到所有沒有特定類的複選框。 這就是我所擁有的,這是行不通的。我需要檢查所有沒有名爲「功能」的複選框。獲取所有沒有特定類的複選框
var value = 'features';
$('input:checkbox[class!="'+value+'"]').attr("checked", "");
我需要找到所有沒有特定類的複選框。 這就是我所擁有的,這是行不通的。我需要檢查所有沒有名爲「功能」的複選框。獲取所有沒有特定類的複選框
var value = 'features';
$('input:checkbox[class!="'+value+'"]').attr("checked", "");
使用:not
var checkBoxes = $("input:checkbox:not(." + value + ")");
這是你想要什麼:fiddle here!
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
+1簡單和快速的答案。 – Lrrr 2014-09-25 14:35:30