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
    };

  • 相关阅读:
    CSS:关于CSS Hack
    JS数据交互:动态从数据库中获取数据填充Select
    Oracle数据库—— 事务处理与并发控制
    Java 实现任意N阶幻方的构造
    Java 实现奇数阶幻方的构造
    Web前端开发笔试&面试_03
    任意多边形的几何变换
    关于网站劫持
    mysql 出现Host 'localhost' is not allowed to connect to this MySQL server 错误
    mysql 导入表数据中文乱码
  • 原文地址:https://www.cnblogs.com/luluping/p/1532509.html
Copyright © 2011-2022 走看看