我想获得复选框的属性值的值.我的代码给了我undefined
$('#mytable').find('tr').each(function () {
var row = $(this);
if ( row.find('input[type="checkbox"]').is(':checked') ) {
alert( $(this).attr("b_partner_id") );
}
});
Run Code Online (Sandbox Code Playgroud)
this是指块中的tr元素if,因为您获取b_partner_id的tr元素中不存在您的属性undefined.
相反,您需要使用checkbox引用获取属性值
$('#mytable').find('tr').each(function () {
var row = $(this),
$check = row.find('input[type="checkbox"]');
if ($check.is(':checked')) {
alert($check.attr("b_partner_id"));
}
});
Run Code Online (Sandbox Code Playgroud)