• jQuery1.3新特性深度分析(Event)


    .3版本的新特性,来看看究竟有什么用处

    jQuery.Event = function( src ){
        // Allow instantiation without the 'new' keyword
        // 允许初始化实例不需要new
        if( !this.preventDefault )
            return new jQuery.Event(src);
       
        // Event object
        // 事件对象存在
        if( src && src.type ){
            this.originalEvent = src;
            this.type = src.type;
            this.timeStamp = src.timeStamp;
        // Event type
        }else
            this.type = src;

        if( !this.timeStamp )
            this.timeStamp = now();
       
        // Mark it as fixed
        this[expando] = true;
    };

    function returnFalse(){
        return false;
    }
    function returnTrue(){
        return true;
    }

    // jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
    // http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
    //jQuery.Event符合w3c的DOM3标准
    jQuery.Event.prototype = {
        //定义preventDefault取消事件的默认动作
        preventDefault: function() {
            this.isDefaultPrevented = returnTrue;

            var e = this.originalEvent;
            if( !e )
                return;
            // if preventDefault exists run it on the original event
            if (e.preventDefault)
                e.preventDefault();
            // otherwise set the returnValue property of the original event to false (IE)
            e.returnValue = false;
        },
        //阻止事件冒泡
        stopPropagation: function() {
            this.isPropagationStopped = returnTrue;

            var e = this.originalEvent;
            if( !e )
                return;
            // if stopPropagation exists run it on the original event
            if (e.stopPropagation)
                e.stopPropagation();
            // otherwise set the cancelBubble property of the original event to true (IE)
            e.cancelBubble = true;
        },
       //可以阻止掉同一事件的其他优先级较低的侦听器的处理
        stopImmediatePropagation:function(){
            this.isImmediatePropagationStopped = returnTrue;
            this.stopPropagation();
        },
        isDefaultPrevented: returnFalse,
        isPropagationStopped: returnFalse,
        isImmediatePropagationStopped: returnFalse
    };

  • 相关阅读:
    写在彻底转向有道云笔记一个月之后
    KMP算法实现
    有道云笔记 V.S. 为知笔记
    卸载印象笔记,跟印象笔记说拜拜
    ExpandRegion for Sublime Text:快速选择文本
    Linux cat命令详解
    Vim安装插件
    Vim与正则表达式
    还没供暖
    在Linux命令行中设置并使用代理服务器
  • 原文地址:https://www.cnblogs.com/luluping/p/1532509.html
Copyright © 2020-2023  润新知