如果第一个和第二个匹配的元素检查了prop,如何检查each((函数?
$(document).on('click', '#submitBtn', function(e) {
var $this = $(this),
$checkboxItems = $('input:checkbox[name="checkbox-acceptance"]');
$checkboxItems.each(function( index ){
// if index 0 and index 1 have .prop( 'checked ' ) do stuff ..
}
})
您不想为此使用each
。只需使用简单的索引检查值:
if ($checkboxItems[0].checked && $checkboxItems[1].checked)
我不知道each
函数的存在,但是如果你需要检查数组的前两个元素是否为真,我会使用@David Thomas解决方案
$checkboxItems.slice(0,2).every((el) => el.value);