这些代码在IE(我的是IE8)上测试没问题,在火狐(20.0)和谷歌(23.0..)浏览器上前两次可以,再点击就不行了,一直没弄懂是什么原因。有兴趣的一起探讨一下吧
.HTML代码
<html><head>
<title>测试</title>
<link type="text/css" href="../css/css.css" rel="stylesheet"/>
<script type="text/javascript" src="../js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../js/js.js"></script>
</head><body class="main"> <fieldset id="attachments">
<legend>附件列表</legend>
<br>
<table>
<thead>
<tr id="attachmenstTitle">
<th><input id="chkall" type="checkbox"/></th>
<th>文件名</th>
<th>编码</th>
<th>版本</th>
<th>状态</th>
</tr>
</thead>
<tbody>
<tr>
<td><input name="sub" type="checkbox"/></td>
<td>施工方案</td>
<td>JLY-PRJ-FA-001</td>
<td>1</td>
<td>发布</td>
</tr>
<tr>
<td><input name="sub" type="checkbox"/></td>
<td>施工方案</td>
<td>JLY-PRJ-FA-001</td>
<td>1</td>
<td>发布</td>
</tr>
</tbody>
</table>
<br>
</fieldset>
</body>
</html>
.jQuery代码
$(document).ready(function(){
//复选框全选/全不选
$("input[type=checkbox]#chkall").bind("click",function(){
$("[name=sub]:checkbox").attr("checked", this.checked);
});
});jQueryCheckBox火狐浏览器
.HTML代码
<html><head>
<title>测试</title>
<link type="text/css" href="../css/css.css" rel="stylesheet"/>
<script type="text/javascript" src="../js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../js/js.js"></script>
</head><body class="main"> <fieldset id="attachments">
<legend>附件列表</legend>
<br>
<table>
<thead>
<tr id="attachmenstTitle">
<th><input id="chkall" type="checkbox"/></th>
<th>文件名</th>
<th>编码</th>
<th>版本</th>
<th>状态</th>
</tr>
</thead>
<tbody>
<tr>
<td><input name="sub" type="checkbox"/></td>
<td>施工方案</td>
<td>JLY-PRJ-FA-001</td>
<td>1</td>
<td>发布</td>
</tr>
<tr>
<td><input name="sub" type="checkbox"/></td>
<td>施工方案</td>
<td>JLY-PRJ-FA-001</td>
<td>1</td>
<td>发布</td>
</tr>
</tbody>
</table>
<br>
</fieldset>
</body>
</html>
.jQuery代码
$(document).ready(function(){
//复选框全选/全不选
$("input[type=checkbox]#chkall").bind("click",function(){
$("[name=sub]:checkbox").attr("checked", this.checked);
});
});jQueryCheckBox火狐浏览器
解决方案 »
- js实现秒表后并实现每次暂停自动记录时间
- jquery 弹出一个层 显示动态信息 插件,推荐一个 谢谢
- 如何实现导航栏可下拉【在线等】
- alert 的内容太多,使得 alert 框超过显示器屏幕,下面不分内容就看不到了,这个框又不能缩小,请问如何显示
- 如何显示和隐藏层,谢谢各位?
- javascript 设置指定页面的图片背景和背景属性
- 急救!用操作cookie的方式怎么实现用户浏览产品的浏览记录!急!急!急
- 请问这段代码是什么意思?请详细说明
- 跨页面访问,该如何办?请老大看看!
- 如何禁止chrome鼠标拖动文字?
- extjs 同一个store返回不同的值,gridpanel还是显示最初的值【在线急等】
- JQUERY或者是JS的右下角弹窗
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
//name 是html表单专用于区别各组 chechbox 的属性, 不要用id(必须唯一)或者其它属性
function getValues() {
var aV = getCheckboxValues("a");
var bV = getCheckboxValues("b");
var cV = getCheckboxValues("c");
var result = "a组选中值: " + (aV=="" ? "未选中任何值" : aV) + "\n" +
"b组选中值: " + (bV == "" ? "未选中任何值" : bV) + "\n" +
"c组选中值: " + (cV == "" ? "未选中任何值" : cV);
alert(result);
}
function getCheckboxValues(name) {
return $(":checkbox[name="+name+"]:checked").map(function(){
return $(this).val();
}).get().join(",");
}
function chkAll(obj) {
var name = $(obj).attr("name");
//也许你觉得我写得太复杂, 但jquery 版本众多, 可以学点东西总是好的
//1. jquery 1.6 以上
//$(":checkbox[name=" + name.substring(0, 1) + "]").prop("checked", $(obj).prop("checked"));
//2. jquery 1.6 以下
//$(":checkbox[name=" + name.substring(0, 1) + "]").attr("checked", $(obj).attr("checked"));
//3. 通用写法
$(":checkbox[name=" + name.substring(0, 1) + "]").each(function () {
this.checked = obj.checked;
});
}
</script>
</head>
<body>
<div >
<span>第1组(a):<input type="checkbox" name="aAll" onclick="chkAll(this)" />全选/全不选</span>
<input type="checkbox" name="a" value="a1" checked="checked" />a1
<input type="checkbox" name="a" value="a2" checked="checked" />a2
<input type="checkbox" name="a" value="a3" />a3
<input type="checkbox" name="a" value="a4" />a4<br />
<span>第2组(b):<input type="checkbox" name="bAll" onclick="chkAll(this)" />全选/全不选</span>
<input type="checkbox" name="b" value="b1" />b1
<input type="checkbox" name="b" value="b2" checked="checked" />b2
<input type="checkbox" name="b" value="b3" checked="checked" />b3
<input type="checkbox" name="b" value="b4" />b4<br />
<span>第3组(c):<input type="checkbox" name="cAll" onclick="chkAll(this)" />全选/全不选</span>
<input type="checkbox" name="c" value="c1" />c1
<input type="checkbox" name="c" value="c2" />c2
<input type="checkbox" name="c" value="c3" checked="checked" />c3
<input type="checkbox" name="c" value="c4" checked="checked" />c4<br />
<br />
<input type="button" value="查找每组的选中的值" onclick="getValues()" />
</div>
</body>
</html>
<head>
<title>测试</title>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
</head>
<body class="main">
<fieldset id="attachments">
<legend>附件列表</legend>
<br>
<table>
<thead>
<tr id="attachmenstTitle">
<th><input id="chkall" type="checkbox"/></th>
<th>文件名</th>
<th>编码</th>
<th>版本</th>
<th>状态</th>
</tr>
</thead>
<tbody>
<tr>
<td><input name="sub" type="checkbox"/></td>
<td>施工方案</td>
<td>JLY-PRJ-FA-001</td>
<td>1</td>
<td>发布</td>
</tr>
<tr>
<td><input name="sub" type="checkbox"/></td>
<td>施工方案</td>
<td>JLY-PRJ-FA-001</td>
<td>1</td>
<td>发布</td>
</tr>
</tbody>
</table>
<br>
<script>
$("#chkall").click(function () {
if ($(this).attr("checked"))
$("table tbody tr").find("input[type='checkbox']").attr("checked", true);
else
$("table tbody tr").find("input[type='checkbox']").attr("checked", false);
}) </script>
</fieldset>
</body>
</html>
前些天有事,忘记打分了,不好意思哈。现在结贴吧