简单的全选和反选功能以及选中传值实现

//两个按钮

<input class="btn-primary" type="button" value="全选" id="selectBtn" onclick="selectAll()"/>
<input class="btn-primary" type="button" value="反选" id="selectBtn1" onclick="reverse()"/>

//全选和反选方法

function selectAll(){
$("#contentTable:checkbox").attr("checked",true);
$("#selectBtn").attr("onclick","reverse()");
}

function reverse(){
$("#contentTable:checkbox").each(function(){
$(this).attr("checked",!$(this).attr("checked"));
});
$("#selectBtn").attr("onclick","selectAll()");
}

//表单

<table id="contentTable" >
<tr>
<th></th><th>序号</th><th>...</th>
</tr>
<c:forEach items="${list}" var="list" varStatus="index">
<tr>
<td><input name="items" type="checkbox" value="${list.id}"/></td>
<td>${index.index+1}</td>

<td>...</td>
</tr>
</c:forEach>
</table>

 

//需要传入后台的id值

var ids="";
$("[name=items]:checkbox:checked").each(function(){
ids+=$(this).val()+",";
});

posted @ 2018-12-25 16:59  地上有代码  阅读(343)  评论(0编辑  收藏  举报