html代码:
<th style="width:4%;line-height: 15px;padding: 0px;" name="duo">
全选<input type="checkbox" name="onc" οnclick="check()"/></th>
<input type="checkbox" name="riskId" /></td>
<input type="checkbox" name="riskId" /></td>
<input type="checkbox" name="riskId" /></td>
<input type="checkbox" name="riskId" /></td>
js代码:
function check(){
var x=$("input:checkbox[name=onc]:checked");
if(x.length==1){
$("input[name='riskId']").attr("checked",true);
}else {
$("input[name='riskId']").attr("checked",false);
}
}
如上,当使用如上jsp时,第一次选中与反选全选框时,可以实现全选与反选的功能,但当再次点击时,js失效,网上查了一些方法,将 attr换为 prop即可。