解决怎么让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();
}
});
$('input[type="checkbox"]').click(function(){
$('#qiandao').show();
});