无法测试每个循环中检查的输入

Seb*_*lia 1 html javascript checkbox jquery

我有一个简单的输入复选框元素的对象,并希望检查每个循环检查哪些和做东西.复选框位于表tr中的几个复选框中td.

这是我的代码:

$('table.occupancy-table').on('change', '.minimum_stay input', function() {
    var minimumStayInputs = $(this).closest('tr').find('input');
    $(minimumStayInputs).each(function(){
        if(this.prop('checked')) {
        //do stuff
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我this在每个循环中使用console.log ,我会得到如下数据:

<input id="R11520" type="checkbox" name="minimum_stay[152][1442786400]" value="checked"> <input id="R11521" type="checkbox" name="minimum_stay[152][1442872800]" value="checked">...

但是,我总是得到一个错误Uncaught TypeError: this.prop is not a functionthis.prop('checked').我也试过.is(":checked")了同样的结果.

任何想法可能是什么原因?

如果您需要样本html,或者我应该创建小提琴,请告诉我.

ade*_*neo 5

this 循环内部是本机DOM元素,从jQuery中解包.

它必须再次包装

$('table.occupancy-table').on('change', '.minimum_stay input', function() {
    var minimumStayInputs = $(this).closest('tr').find('input');
    $(minimumStayInputs).each(function(){
        if ( $(this).prop('checked') ) {
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

您也可以使用本机this.checked,或者如果您正在尝试计算它们

$(this).closest('tr').find('input:checked').length
Run Code Online (Sandbox Code Playgroud)