[color=blue]1.方式一[/color]
[color=blue]2.方式二[/color]
[color=blue]2.方式三[/color]
<script type="text/javascript">
$(function() {
$("#cc").click(function() {
$("input[@name='c']").each(function() {
$(this).attr("checked", true);
});
});
$("#cc").click(function() {
$("input[@name='c']").each(function() {
$(this).attr("checked", false);
});
});
});
</script>
<input type='checkbox' id='c' name='c' value='10' />UserA
<input type='checkbox' id='c' name='c' value='11' />UserB
<input type='checkbox' id='c' name='c' value='12' />UserC
<input type="button" id='c' name=" id="cc" value="全选/取消" />
[color=blue]2.方式二[/color]
$("#cc").click(
function(){
if(this.checked){
$("input[name='c']").each(function(){this.checked=true;});
}else{
$("input[name='c']").each(function(){this.checked=false;});
}
}
);
<input type='checkbox' id='c' name='c' value='10' />UserA
<input type='checkbox' id='c' name='c' value='11' />UserB
<input type='checkbox' id='c' name='c' value='12' />UserC
<input type="button" id='c' name="cc" id="cc" value="全选/取消" />
[color=blue]2.方式三[/color]
<script type="text/javascript">
function checkAll(){
var check_del = document.getElementsByName("c");
var check_delAll = document.getElementById("cc");
if(check_delAll.checked) {
alert(cc.length);
for(var m=0; m < check_del.length; m++) {
check_del[m].checked = true;
}
}else{
for(var m=0; m < check_del.length; m++) {
check_del[m].checked = false;
}
}
}
</script>
<input type='checkbox' id='c' name='c' value='10' />UserA
<input type='checkbox' id='c' name='c' value='11' />UserB
<input type='checkbox' id='c' name='c' value='12' />UserC
<input type="button" id='c' name="cc" id="cc" value="全选/取消" />