我有带HTML的复选框:
<input type="checkbox" class="selectMakeup" name="needsPartNumber">
[可能有很多具有相同类的复选框。我想遍历每个选中的复选框。
$('.selectMakeup').each(function(){
console.log($(this).html())
console.log($(this).prop('checked'))
if($(this).prop('checked')){
//Do Stuff
}
})
console.log($(this).html())
返回
<input type="checkbox" name="needsPartNumber">
但是console.log($(this).prop('checked'))
返回undefined
。
如果要检查复选框/无线电选项是否已被选中,则可以使用.is()
:
$('.selectMakeup').each(function(){
if($(this).is(':checked')){
//Do Stuff
}
});