其他分享
首页 > 其他分享> > jQery基础,事件冒泡个默认行为stopImmediatePropagation(); preventDefault();

jQery基础,事件冒泡个默认行为stopImmediatePropagation(); preventDefault();

作者:互联网

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .father {
            width: 200px;
            height: 200px;
            background: red;
        }

        .son {
            width: 100px;
            height: 100px;
            background: blue;
        }
    </style>
    <script src="../jquery-3.3.1.js"></script>
    <script>
        $(function () {
            // $(".son").click(function (event) {
            //     alert("son");
            //     // return false;
            //     event.stopImmediatePropagation();
            // });
            // $(".father").click(function () {
            //     alert("father");
            // });


            //给a标签添加事件
            $("a").click(function(event){
                alert("弹出注册框");
                // return false;
                //event.stopImmediatePropagation();点击后回跳转
                event.preventDefault();//点击后不会跳转
            })
        })

    </script>
</head>

<body>
    <div class="father">
        <div class="son"></div>
    </div>
    <a href="https://www.bilibili.com/">bilibili干杯!</a>
    <form action="http://www.taobao.com">
        <input type="text">
        <input type="submit">
    </form>
</body>

</html>
event.stopImmediatePropagation();点击后回跳转
event.preventDefault();//点击后不会跳转

标签:function,jQery,stopImmediatePropagation,preventDefault,father,son,跳转,event
来源: https://blog.csdn.net/Mr_aswl/article/details/114287252