checkbox全选 全不选

第一次随笔,写点技术上的小东西,关于全选 全不选的,请大家多多指教!

 

<table class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th><input type="checkbox" name="ckb" id="check" onClick="Quanxuan()"></th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr class="odd gradeX">
<td><input type="checkbox" name="xuanzhe"> </td>
<td>1</td>
<td>设备集报表</td>
<td class="center"><input type="button" id="Dayin" value="打印"></td>
</tr>
<tr class="even gradeC">
<td><input type="checkbox" name="xuanzhe"></td>
<td>2</td>
<td>分户报表</td>
<td class="center"><input type="button" id="Dayin" value="打印"></td>
</tr>

</tbody>
</table>
</div>

<script type="text/javascript">

//全选或全不选判断

function Quanxuan(){
$.each($("input[name=xuanzhe]"), function(i) {
if ($("#check").prop("checked") == true) {
$(this).prop("checked", true);
}
else{
$(this).removeAttr("checked");
}
});
}

//打印前判断
function PLDayin(){
var k=0;
$.each($("input[name=xuanzhe]"), function(i) {
if($(this).prop("checked")==true){
k++;
}
});
if(k>0){
alert("批量打印成功!");
}else{
alert("请选择打印的类型!");
}
}
</script>

 

posted @ 2016-08-25 10:19  华季  阅读(347)  评论(0编辑  收藏  举报