全选Js
<th><input type="checkbox" value="" id="checkedAll" onclick="change()">全选</th>
<td><input type="checkbox" name="checkedId" value="${item.deviceId}"></td>
对应的function:
function change() { var checklist = document.getElementsByName ("checkedId"); if(document.getElementById("checkedAll").checked) { for(var i=0;i<checklist.length;i++) { checklist[i].checked = 1; } }else{ for(var j=0;j<checklist.length;j++) { checklist[j].checked = 0; } } }
获取被选中checkbox
var deviceIdStr = ''; var checklist = document.getElementsByName ("checkedId"); for(var i=0;i<checklist.length;i++) { if(checklist[i].checked){ deviceIdStr = deviceIdStr + ","+ checklist[i].value; } }