javascript - 解决怎么让checkbox打勾时将id的qiandao显出来?
本文介绍了javascript - 解决怎么让checkbox打勾时将id的qiandao显出来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
解决怎么让checkbox打勾时将id的qiandao显出来?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div>
<input type="checkbox" id="viphuiyuan"> <label for="viphuiyuan" style="display:inline-block;">VIP</label>
<input type="checkbox" id="laibing"> <label for="laibing" style="display:inline-block;">来宾</label>
<input type="checkbox" id="shangjia"> <label for="shangjia" style="display:inline-block;">商家</label>
<input type="checkbox" id="shidai"> <label for="shidai" style="display:inline-block;">市代</label>
</div>
<div id="qiandao" style="display: none;">
wwwww
</div>
<script src="//cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
<script>
function mycheckbox(){
if(isclick()){
$("#qiandao").css('display','block');
}
}
function isclick() {
var falg = 0;
$("input[type='checkbox']").each(function () {
if ($(this).checked) {
falg += 1;
}
})
if (falg > 0)
return true;
else
return false;
}
mycheckbox();
</script>
</body>
</html>
解决方案
按照题主思路完善了一下代码
function isChecked() {
var flag = 0;
$("input[type='checkbox']").each(function () {
if (this.checked) {
flag += 1;
}
});
return flag;
}
$("input[type='checkbox']").click(function(){
if(isChecked()){
$("#qiandao").show();
}else{
$("#qiandao").hide();
}
});
这篇关于javascript - 解决怎么让checkbox打勾时将id的qiandao显出来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文