<script type="text/javascript">
$("#stu1").click(function () {
$("input[name='stu']").attr("checked", $(this).attr("checked"));
return false;
});
</script>
<asp:Repeater ID="repList" runat="server">
<HeaderTemplate>
<table>
<tr align="center">
<td ><asp:CheckBox ID="CheckBox1" name="stu1" runat="server" /></td>
<td bgcolor="#00FF22">商品ID</td>
<td bgcolor="#00FF22">名称</td>
<td bgcolor="#00FF22">单价</td>
<td bgcolor="#00FF22">描述</td>
<td bgcolor="#00FF22">操作</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr align="center" bgcolor="#00FFcc">
<td><asp:CheckBox ID="CheckBox2" name="stu" runat="server" /></td>
<td><%# Eval("ID") %></td>
<td><%# Eval("ShopName")%></td>
<td><%# Eval("Price")%></td>
<td><%# Eval("Desc")%></td>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
使用prop测试下,1.9之后的jquery改了
你全选的checkbox只有name,没有id好不。。选择器错了
$("input[name='stu1']").click(function () {
$("input[name='stu']").attr("checked", $(this).attr("checked"));
return false;
});
$(function() { $("#checkAll").click(function() { $('input[name="subBox"]').attr("checked",this.checked); }); var $subBox = $("input[name='subBox']"); $subBox.click(function(){ $("#checkAll").attr("checked",$subBox.length == $("input[name='subBox']:checked").length ? true : false); }); });靠直接复制竟然不行。。。。
<script src="http://code.jquery.com/jquery-1.4.4.min.js" type="text/javascript"></script> <script type="text/javascript">
$(function() {
$("#checkAll").click(function() {
$('input[name="subBox"]').attr("checked",this.checked);
});
var $subBox = $("input[name='subBox']");
$subBox.click(function(){
$("#checkAll").attr("checked",$subBox.length == $("input[name='subBox']:checked").length ? true : false);
});
});
</script>
</head>
<body>
<div>
<input id="checkAll" type="checkbox" />全选
<input name="subBox" type="checkbox" />项1
<input name="subBox" type="checkbox" />项2
<input name="subBox" type="checkbox" />项3
<input name="subBox" type="checkbox" />项4
</div>
</body>
</html>
看了半天也不知道,试了上面的班,只能跟帖,,,求此题原因。。
$("input[name='stu']").attr("checked", true);
全选是这样设置的,不是你那样写的
全选得遍历所有的checkbox
var x = $("input[type=checkbox][name="stu"]");
var bl = $(thisObj).attr("checked");
for (var i=0;i<x.length;i++){
if(!bl){ //取消操作
if($(x[i]).attr("checked")){
$(x[i]).removeAttr("checked");
}
}else{ //选中操作
$(x[i]).attr("checked",true);
}
}