zoukankan      html  css  js  c++  java
  • 点击页面其他地方的时候,让弹出框消失

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>阻止冒泡</title>
    <style type="text/css">
    .block_opacity{
    100%;
    height: 100%;
    z-index: 1;
    opacity: 0.5;
    background: #cccccc;
    filter: alpha(opacity=50);
    top:0;
    left: 0;
    position: fixed;
    display: none;
    }
    .block{
    400px;
    height: 300px;
    position: absolute;
    margin-left: -200px;
    margin-top: -150px;
    top:50%;
    left: 50%;
    z-index: 2;
    background:red;
    display: none;
    }
    </style>
    </head>
    <body>
    <div class="block_opacity" ></div>
    <div class="block" id="block">
    <input type="text" />
    </div>
    <input type="button" onclick="aa()" value="点击" id="bb" />
    <script type="text/javascript" src="jquery-1.9.1.min.js"></script>
    <script type="text/javascript">
    function aa () {
    $(".block_opacity,.block").show();
    }

    $(document).on("click",function(e){
    var e=e || window.event;
    var target=e.target || e.srcElement;
    if(target.id=="bb") return;
    $(".block_opacity,.block").hide();
    });
    //阻止时间冒泡
    $("#block").click(function(e){
    stopBubble(e);
    });

    function stopBubble(e){
    if (e && e.stopPropagation)
    e.stopPropagation();
    else
    window.event.cancelBubble=true;
    }

    </script>
    </body>
    </html>

  • 相关阅读:
    图片文件重命名
    MySql基础学习-Sql约束
    MySql基础学习-库表操作
    java内存模型
    数据库常用函数整理
    linux用户管理
    Db2数据库在Linux下的安装和配置
    图像金字塔
    特征值与特征向量
    齐次线性方程组
  • 原文地址:https://www.cnblogs.com/xiaotaiyang/p/3858595.html
Copyright © 2011-2022 走看看