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

  • 相关阅读:
    C#中如何调用Delphi写的Dll
    正则表达式与抓取是网页图片
    Jmeter使用基础笔记认识Jmeter
    mac下Redis安装和使用
    Jmeter逻辑控制器ForEach Controller
    Jmeter BeanShell PreProcessor使用笔记
    Jmeter使用笔记之断言
    Mac在python3环境下安装virtualwrapper遇到的问题
    Jmeter使用基础笔记写一个http请求
    使用SQLSERVER的扩展存储过程实现远程备份与恢复
  • 原文地址:https://www.cnblogs.com/luluping/p/1532509.html
Copyright © 2020-2023  润新知