Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何获取属性的复选框值_Jquery - Fatal编程技术网

Jquery 如何获取属性的复选框值

Jquery 如何获取属性的复选框值,jquery,Jquery,我想获取复选框的属性值。 我的代码给了我未定义的 $('#mytable').find('tr').each(function () { var row = $(this); if ( row.find('input[type="checkbox"]').is(':checked') ) { alert( $(this).attr("b_partner_id") ); } }

我想获取复选框的属性值。 我的代码给了我未定义的

$('#mytable').find('tr').each(function () {
            var row = $(this);

            if ( row.find('input[type="checkbox"]').is(':checked') ) {
                alert( $(this).attr("b_partner_id") );
            }
        });

指的是
if
块中的
tr
元素,因为您获得的
tr
元素
未定义
中不存在您的
b\u partner\u id
属性

相反,您需要使用
复选框
引用获取属性值

$('#mytable').find('tr').each(function () {
    var row = $(this),
        $check = row.find('input[type="checkbox"]');

    if ($check.is(':checked')) {
        alert($check.attr("b_partner_id"));
    }
});