<!-- jQuery全选(全不选择) --> <form action=""> <table> <tr> <td><input type="checkbox" name="checkName" value="旅游" onclick="unCheckAll(this,'allCheckName')"/> 旅游 </td> </tr> <tr> <td><input type="checkbox" name="checkName" value="看书" onclick="unCheckAll(this,'allCheckName')"/> 看书 </td> </tr> <tr> <td><input type="checkbox" name="checkName" value="上网" onclick="unCheckAll(this,'allCheckName')"/> 上网 </td> </tr> <tr> <td><input type="checkbox" name="allCheckName" onclick="checkAll(this,'checkName')"/> 全选</td> </tr> <tr> <td><input type="button" value="取得被选中的值" onclick="checkedValue()"/></td> </tr> </table> </form>
?
?
/*
* 绑定批量选定/非选
* object:点击的对象
* checkName:checkBox的名称
*/
function checkAll(object,checkName){
var bool = $(object).attr("checked");
$(":checkbox[name='"+checkName+"']").attr("checked",bool);
}
function unCheckAll(object,allCheckName){
var bool = $(object).attr("checked");
if(bool == false){
$(":checkbox[name='"+allCheckName+"']").attr("checked",bool);
}
}
function checkedValue(){
$(":checkbox[name='checkName']").each(function(){
var name = $(this).val();
alert(name);
});
}
?