//------------------------------------
// 全/反选
// param checkName checkbox的name属性
//------------------------------------
function choose(checkName){
var checkBoxArray = document.getElementsByName(checkName);
for(var i=0;i<checkBoxArray.length;i++){
checkBoxArray[i].click();
}
}
测试:
<table>
<tr><th><a href="javascript:choose('ids')">反选</a></th></tr>
<tr><td><input type='checkbox' name='ids' value='1'/></td></tr>
<tr><td><input type='checkbox' name='ids' value='2'/></td></tr>
<tr><td><input type='checkbox' name='ids' value='3'/></td></tr>
<tr><td><input type='checkbox' name='ids' value='4'/></td></tr>
<tr><td><input type='checkbox' name='ids' value='5'/></td></tr>
<tr><td><input type='checkbox' name='ids' value='6'/></td></tr>
</table>