javascript - 解决怎么让checkbox打勾时将id的qiandao显出来?
PHP中文网
PHP中文网 2017-04-11 09:57:05
[JavaScript讨论组]

解决怎么让checkbox打勾时将id的qiandao显出来?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<p>
    <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>
</p>
<p id="qiandao" style="display: none;">
       wwwww
</p>
<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>
PHP中文网
PHP中文网

认证0级讲师

全部回复(2)
伊谢尔伦

按照题主思路完善了一下代码

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();
});
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号