jquery点击按钮打开div弹出层,再次点击任意地方关闭弹出层

一:纯div写法

先上效果图,这个是纯div

<button type="button" class="blue" id="btnSYWRW" onclick="SYWRW()" style="100px; border:none; color:white;"><span class="iconfont" style="position:relative;top:1px;"></span>&nbsp;首要污染物</button>


<%--首要污染物占比饼图--%>
<div id="SYWRW" style="display:none; position: fixed;top: 0px;left: 0px;right: 0px;bottom: 0px;margin: auto; z-index:101;background:rgba(0,0,0,0.7);">
     <div id="echartsSYWRW" style="margin: auto; margin-top: 10px; width:500px;         
          height:500px;">弹出的div</div>
</div>



<script>

function SYWRW() {
            $("#SYWRW").show();
        }

//点击页面其他地方关闭
document.onclick = function (e) {
    //判断点击的地方是否为“更多”按钮和弹出层是否显示
    if (!$(e.target).is("#btnSYWRW") && $("#SYWRW").is(":visible") == true) {
        $("#SYWRW").hide();
    }
}

</script>

二:调用第三方组件layer

效果图

去网上下载相关js组件,应用到项目中

<script src="../Js/layer-v3.1.1/layer/layer.js"></script>

<html>
<head>
<script src="../Js/tableHead.js"></script>
<head>
<body>
<button type="button" class="blue" id="btnSYWRW" onclick="aa()" style="width:95px; border:none; color:white;"><span class="iconfont" style="position:relative;top:1px;"></span>&nbsp;首要污染物</button>

<script>
function aa(data, type) {
            w = $(window).width(); //浏览器时下窗口可视区域宽度 
            h = $(window).height(); //浏览器时下窗口可视区域高度

            //弹窗尺寸
            w1 = w * 0.9;
            h1 = h * 0.9;

            //w = w < 1000 ? 1000 : w * 0.98;

            var dataStr = compileStr(JSON.stringify(data));

            layer.open({
                type: 2,
                title: '',
                shadeClose: true,
                shade: true,
                shade: 0.8,
                area: [w1 + 'px', h1 + 'px'],
                resize: false,
                content: '/Statistics/DataExaminationSYWRW.aspx?data=' + dataStr + '&type=' + type//type 1:1首要污染物占比饼图 2:污染物各因子贡献率
            });
        }
</script>
<body>
<html>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一个程序员_zhangzhen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值