全选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;
            }

        }

 

posted @ 2018-03-23 16:23  烟味i  阅读(181)  评论(0编辑  收藏  举报