<script type="text/javascript" src="Scripts/jquery-1.4.1-vsdoc.js"></script>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$("#Button1").click(function(){
var obj = $("#CheckBoxList1");
if (obj.attr("checked",true)) {
alert("yes");
}
else {
alert("no");
}
//
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem Value="0">a</asp:ListItem>
<asp:ListItem Value="1">b</asp:ListItem>
<asp:ListItem Value="2">c</asp:ListItem>
<asp:ListItem Value="3">d</asp:ListItem>
</asp:CheckBoxList>
</div>始终是YES
没选中也是YEs
求解!!!!!!!!jqueryfunctionhtml
改成
if (obj.is(":checked" ) {
var obj = $("#CheckBoxList1 :checked");
if (obj.length > 0) {
alert("yes");
} else {
alert("no");
}
// 如果要获取具体的选中值,只需遍历即可
obj.each(function() {
// 逻辑
}
$("#id").prop("checked")
这个表示看不懂
$("div").find("#chkItem").attr('checked', true);
$("#unchk").attr('checked', false);
}
我用的是html的checkbox,这样是可以的
$("#Button1").click(function(){
var obj = $("#CheckBoxList1");
if (obj.prop("checked")) {
alert("yes");
}
else {
alert("no");
}
//
});
});
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("#btn").click(function(){
alert($("#chk1").is(":checked"));
});
$("#btnSelect").click(function(){
$("#chk1").prop("checked",true);
});
$("#btnUnSelect").click(function(){
$("#chk1").prop("checked",false);
});
});
</script>
</head>
<body>
<input type="checkbox" id="chk1" value="aa" />
<input type="button" id="btn" value="Alert" />
<input type="button" id="btnSelect" value="Select" />
<input type="button" id="btnUnSelect" value="UnSelect" />
</body>
</html>http://api.jquery.com/prop/
你用的控件应该是服务器控件不能直接用Id,要看一下html的源代码的控件Id是什么,或者用服务器控件的ClientId
$(function () {
$("#Button1").click(function () {
var hasAnyChecked = $("#<%= CheckBoxList1.ClientID%> input[type='checkbox']").prop("checked");
if (hasAnyChecked === true) {
alert("yes");
}
else {
alert("no");
}
// });
}); </script>
如果选中 checked属性值为checked
否则 checked是找不到的
lz不妨用$.each(obj,function(a,a_item){
alert(a+":"+a_item) //应该弹出0:【object之类的东西】
/*再试试这个
$.each(a_item,function(b,b_item){
alert(b+":"+b_item);//应该弹出对象的所有属性 事件等等
})
*/
})