• 时间对象冒泡行为和默认行为


    冒泡行为:

        <div style=" 200px;height: 200px;background-color: red;">
            <input type="button" value="按钮" />
        </div>    
    $(function(){
        
        $('input').bind('click',function(e){
            alert('input');
        });
        
        $('div').bind('click',function(e){
            alert('div');
        });
        
        $(document).bind('click',function(e){
            alert('document');
        });
        
    });

    阻止冒泡行为:

    $(function(){
        
        $('input').bind('click',function(e){
            e.stopPropagation(); //禁止冒泡
            alert('input');
        });
        
        $('div').bind('click',function(e){
            e.stopPropagation(); //禁止冒泡
            alert('div');
        });
        
        $(document).bind('click',function(e){
            alert('document');
        });
        
    });

    网页元素默认行为阻止:

    //<a href="http://www.baidu.com" target="_blank">百度</a>
    $(function(){
        
        $('a').click(function(e){
            e.preventDefault(); //阻止点击的默认行为,不会跳转
            alert('百度');
        });
        
    });

    既阻止冒泡有阻止默认行为:

    可以:

        $('a').click(function(e){
            alert('百度');
            e.stopPropagation();
            e.preventDefault(); //阻止点击的默认行为,不会跳转
        });
        
        //简写方法
        $('a').click(function(e){
            alert('百度');
            return false;
        });
  • 相关阅读:
    JavaBasics-15-多线程
    4.10 SpringCloud微服务技术栈
    4.3 Linux操作系统_Unix操作系统
    4.2 互联网项目架构演进
    4.1 微服务框架_引言
    4.6 Redis
    SpringBoot
    docker-dockerfile实战构建文件
    docker 安装私有仓库 registry(离线)
    基础K8S搭建(20209.08亲测成功)
  • 原文地址:https://www.cnblogs.com/by-dxm/p/6390573.html
Copyright © 2020-2023  润新知