$(this).prop('checked')不适用于检查Jquery的复选框

问题描述 投票:0回答:1

我有带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

javascript jquery html
1个回答
0
投票

如果要检查复选框/无线电选项是否已被选中,则可以使用.is()

$('.selectMakeup').each(function(){
    if($(this).is(':checked')){
        //Do Stuff
    }
});
© www.soinside.com 2019 - 2024. All rights reserved.