
如何判断一个div下的checkbox是否选中
是用jquery判断的<divclass="lmf-name"><label>抵押物品:</label><span><inputtype="checkbox"/><em>...
是用jquery判断的
<div class="lmf-name">
<label>抵押物品:</label>
<span><input type="checkbox" /><em>房产</em></span>
<span><input type="checkbox" /><em>汽车</em></span>
<span><input type="checkbox" /><em>有无证券</em></span>
<span><input type="checkbox" /><em>其他</em></span>
</div> 展开
<div class="lmf-name">
<label>抵押物品:</label>
<span><input type="checkbox" /><em>房产</em></span>
<span><input type="checkbox" /><em>汽车</em></span>
<span><input type="checkbox" /><em>有无证券</em></span>
<span><input type="checkbox" /><em>其他</em></span>
</div> 展开
7个回答
展开全部
checkbox自身有个属性就是用来判断checkbox是否被选中了。
这个属性是checked。下面是简单的代码,仅供参考:
<body>
<div>
<input type="checkbox" id="chk" />
</div>
</body>
<script>
var oChk = document.getElementById('chk');
oChk.onclick = function(){
if(this.checked){
alert('选中');
} else {
alert('没有选中');
}
};
</script>
展开全部
$(".lmf-name :checkbox:checked") .length > 0 说明div下有选中checkbox
追问
那么是这样子写的吗?
if((".lmf-name:checkbox:checked").length>0){
return true;
}else{
alert("请选择");
return false;
}
追答
是的,请采纳~!
本回答被提问者和网友采纳

你对这个回答的评价是?
展开全部
<div>
<input type=checkbox id="ch_1">
<input type=checkbox id="ch_2">
<input type=checkbox id="ch_3">
<input type=checkbox id="ch_4">
<input type=checkbox id="ch_5">
<input type=button value="button" onclick="checkit()">
</div>
<script>
function checkit()
{
var chk = false;
for(var i=1;i<6;i++)
if(document.getElementById("ch_"+i).checked) chk=true;
if(!chk)alert("没有选择");
}
</script>
<input type=checkbox id="ch_1">
<input type=checkbox id="ch_2">
<input type=checkbox id="ch_3">
<input type=checkbox id="ch_4">
<input type=checkbox id="ch_5">
<input type=button value="button" onclick="checkit()">
</div>
<script>
function checkit()
{
var chk = false;
for(var i=1;i<6;i++)
if(document.getElementById("ch_"+i).checked) chk=true;
if(!chk)alert("没有选择");
}
</script>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-08-29
展开全部
$(".lmf-name :checkbox:checked") 获得所有选中的checkbox
if($(".lmf-name :checkbox:first").prop("checked") == true) 判断第一个checkbox是否选中
if($(".lmf-name :checkbox:first").prop("checked") == true) 判断第一个checkbox是否选中
更多追问追答
追问
只是判断这个div下是否有选中checkbox
追答
$(".lmf-name :checkbox").has(":checked")
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |