zoukankan      html  css  js  c++  java
  • 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
    };

  • 相关阅读:
    Socket
    利用Python自动生成暴力破解的字典
    【转】六年测试工作的思考1
    【转】手机测试入行三年的感想
    【转】移动测试人员的未来:测试开发技术的融合
    【转】一个互联网项目即将结束的软件测试经验总结
    【转】电子商务网站测试经验总结
    【转】六年软件测试感悟-从博彦到VMware
    使用PL/SQL删除百万条记录的大表
    【转】百万级数据查询优化
  • 原文地址:https://www.cnblogs.com/luluping/p/1532509.html
Copyright © 2011-2022 走看看