Print this operating table after the current row row row checkbox checkbox id

Print this operating table after the current row row row checkbox checkbox id

<%-- data-id为自定义属性,传入的是后台id --%>
<input type="checkbox" data-id="${xxx}">   

<script>
// 拿到所有含data-id属性的的input
var arr = $("input[data-id]");

// 遍历数组
arr.each(function () {
	// 当为选中状态时  打印当前id
    if($(this).prop('checked') == true{
        console.log($(this).data("id"))
    }
});
</script>
若想以1,2,3,4这种格式打印出,则需要:
// 遍历数组
var ids = "";
arr.each(function () {
	// 当为选中状态时  打印当前id
    if($(this).prop('checked') == true{
    	// 把每个id后面加上一个“,”
        var id = $(this).data("id") + ","
        ids += id;
    }
    // 把最后一个逗号截取掉(从0截取到倒数第二位)
    ids.splice(0,ids.length - 1);
});
console.log(ids)  // 1,2,3,4,5,6

Guess you like

Origin blog.csdn.net/a5252145/article/details/95174096
Row