1.这个要使用js来判断是否选中,需要引用jquery
<script type="text/javascript" src="js/jquery-1.8.3.min.js" ></script><script type="text/javascript">
$(function(){
$("#all").change(function(){//判断全选框的改变
var flage =$(this).is(":checked")//全选选中为true,否则为false
$("input[type=checkbox]").each(function(){
$(this).prop("checked",flage)
})
})
})
</script>
<input type="checkbox" id="all" />全选
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="jquery-3.1.0.min.js"></script>
<style>
</style>
</head>
<body>
<input type="checkbox" checked>
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<button id="btn">全选</button>
<button id="btn1">取消全选</button>
<script>
$(document).ready(function () {
$("#btn").click(function () {
$(":checkbox").attr("checked",true)
})
$("#btn1").click(function () {
$(":checkbox").attr("checked",false)
})
})
</script>
</body>
</html>
需要引用jquery
<html><head>
<meta http-equiv="Content-Type" content="text/html charset=UTF-8">
<title>check test</title>
</head>
<body>
<form name="formGroup" id="formGroup" action="#" method="post" target="_self">
<table border="1" cellpadding="2" cellspacing="1" class="table_hide">
<tr class="table_title">
<td width="50" align="center" class="text_center">序号</td>
<td width="40" align="center" class="text_center">选择</td>
<td width="100" align="center"></td>
<td width="100" align="center"></td>
</tr>
<tr>
<td align="center" class="text_center">1</td>
<td align="center" class="text_center"><input name="groupCheckbox" type="checkbox" value="" class="input_hide"></td>
<td align="center"></td>
<td align="center"></td>
</tr>
<tr>
<td align="center" class="text_center">2</td>
<td align="center" class="text_center"><input name="groupCheckbox" type="checkbox" value="" class="input_hide"></td>
<td align="center"></td>
<td align="center"></td>
</tr>
<tr>
<td align="center" class="text_center">3</td>
<td align="center" class="text_center"><input name="groupCheckbox" type="checkbox" value="" class="input_hide"></td>
<td align="center"></td>
<td align="center"></td>
</tr>
<tr>
<td align="center">全选</td>
<!-- 复选框单击方式 -->
<td align="center"><input name="" type="checkbox" class="input_hide" onClick="CheckSelect(this.form)return false" value=""></td>
<!-- 按钮方式,本质无区别 -->
<td align="center"><input name="" type="button" class="input_hide" onClick="CheckSelect(this.form)return false" value="选/反选"></td>
<td align="center"></td>
</tr>
</table>
</form>
</body>
<script type="text/javascript">
// 选择或者反选 checkbox
function CheckSelect(thisform)
{
// 遍历 form
for ( var i = 0 i < thisform.elements.length i++)
{
// 提取控件
var checkbox = thisform.elements[i]
// 检查是否是指定的控件
if (checkbox.name === "groupCheckbox" && checkbox.type === "checkbox" && checkbox.checked === false)
{
// 正选
checkbox.checked = true
}
else if (checkbox.name === "groupCheckbox" && checkbox.type === "checkbox" && checkbox.checked === true)
{
// 反选
checkbox.checked = false
}
}
}
</script>
</html>
运行效果:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)