jQuery彈框阻止冒泡

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>定時(shí)器彈框</title>
    <style type="text/css">
        .pop_con{
            display: none;/*默認(rèn)不顯示,用定時(shí)器顯示*/
        }
        .pop{
            width: 400px;
            height: 300px;
            background-color: #fff;
            border: 1px solid #000;
            position: fixed;/*使用固定定位*/
            left: 50%;/*左上角位于頁面中心*/
            top: 50%;
            margin-left: -200px;/*讓div向左偏移半個(gè)寬度、向上偏移半個(gè)高度,使div位于頁面中心*/
            margin-top: -150px;
            z-index: 9999;/*彈窗在最前面*/
        }
        /*遮罩樣式*/
        .mask{
            position: fixed;
            width: 100%;
            height: 100%;
            background-color: #000;
            left: 0;
            top: 0;
            /*設(shè)置透明度30%,兼容IE6、7、8*/
            opacity: 0.3;
            filter: alpha(opacity=30);
            z-index: 9990;/*遮罩在彈窗后面*/
        }
    </style>
    <script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
    <script type="text/javascript">
        $(function(){
            $('#btn').click(function() {
                $('#pop').show();
                return false;
            });
            $('#shutoff').click(function() {
                $('#pop').hide();
            });
            //點(diǎn)彈框以外的地方,也能讓彈框消失
            $(document).click(function(){
                // setTimeout(function(){
                //  $('#pop').hide();
                // },2000);

                $('#pop').hide();
            });
            $('.pop').click(function() {
                return false;
            });
            
            //阻止默認(rèn)行為(原來超鏈接可跳轉(zhuǎn)到百度,阻止后無法跳轉(zhuǎn))
            $('#link1').click(function() {
                return false;
            });
        })
    </script>
</head>
<body>
    <h1>首頁標(biāo)題</h1>
    <p>頁面內(nèi)容</p>
    <a  id="link1">百度網(wǎng)</a>
    <input type="button" name="" value="彈出" id="btn">

    <div class="pop_con" id="pop">
        <div class="pop">
            <h3>提示信息!</h3>
            <a href="#" id="shutoff">關(guān)閉</a>
            <input type="text" name="">
        </div>
        <!-- 遮罩層 -->
        <div class="mask"></div>
    </div>
</body>
</html>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容