jquery选中checkbox


jquery选中checkbox:
$(function(){
$("[value = bb]:checkbox").attr("checked", true);//$("[name = sortid]:eq(0)").attr("checked", true); check the first radio
});
选中的个数:
$("input[name = myname]:checked").length

<script type="text/javascript">

$(function(){
$("[value = bb]:checkbox").attr("checked", true);
});

function judgecheckbox(){
$("input[type='checkbox']").attr('name');
if($("input[name=myname]:checked").length==0) //获得选中的数量
{
alert("请选择分类信息");
return false;
}
return true;
}

</script>
</head>

<body>
This is my JSP page.
<br>

<form>
我喜欢自行车: <input type="checkbox" name="myname" value="aa" > <br />
我喜欢汽车: <input type="checkbox" name="myname" value="bb">
<a onclick="judgecheckbox()">查看</a>
</form>

</body>
</html>

原文地址:https://www.cnblogs.com/tshua/p/5709723.html