求解 value="true" 的checkbox为什么不能选中

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js">

</head>
<body>
<div id="tabsList-3">
<input id = "1" type="checkbox" value="true" />
<input id = "2" type="checkbox" value="false" />
<input id = "3" type="checkbox" value="false" />
<input id = "4" type="checkbox" value="false" />
<input id = "5" type="checkbox" value="false" />
<input id = "6" type="checkbox" value="false" />
<input id = "7" type="checkbox" value="false" />
<input id = "8" type="checkbox" value="false" />
<input id = "9" type="checkbox" value="false" />

</div>
</body>
<script>
 $(document).ready(function(){
 $("#tabsList-3 input[type='checkbox']").each(function(){if ($(this).value == 

"true") {
                        $(this).attr("checked", true);}})

});

</script>
</html>
 if ($(this).value == "true"
 改成
 if (this.value == "true"

$(this).attr("checked", true) 改成$(this).prop("checked", true)

没看懂,跟value什么关系.
给每一个input取相同的名字,比如name="ids"
jquery获取所有多选框,

if ($(input[name=ids] : checked).size() == 0 ){
alert("没有选中");
return;
}

相反就用each循环拿到值做判断 然后提交表单什么的.

$(this).prop("checked", true)

取值不是应该用val()函数吗

选中与不选中的属性应该是checked,而不是true。如果想要选中,可以把checked的属性设置为tue或者checked

checkbox不是你这么玩的

$("#tabsList-3 input[type='checkbox']").each(function(){
if ($(this).is(":checked") {
$("#tabsList-3 input[type='checkbox']").prop("checked",true);
}
})

你这个input 标签里面的value值一般用作传递到后台的,跟页面显示没有多大的关系。
如果你想要选中的话,直接在input标签最后加上一个checked即可
eg:

checkbox选择是checked,不是value

checked='true'

貌似有个属性是checked,设置其为checked就可以了

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">





$(document).ready(function () { $("#tabsList-3 input[type='checkbox']").each(function () { if ($(this).val() =="true") { $(this).attr("checked", true); } }) });

图片说明