jQuery.event.special.change = { setup: function() { //rformElems = /^(?:input|select|textarea)$/i if ( rformElems.test( this.nodeName ) ) { // IE不会在check/radio失焦前触发change事件; 在属性更改后触发它的click事件 // 在special.change.handle中会吞掉失焦触发的change事件. // 这里任然会在check/radio失焦后触发onchange事件. if ( this.type === "checkbox" || this.type === "radio" ) { jQuery.event.add( this, "propertychange._change", function( event ) { if ( event.originalEvent.propertyName === "checked" ) { this._just_changed = true; } }); jQuery.event.add( this, "click._change", function( event ) { if ( this._just_changed && !event.isTrigger ) { this._just_changed = false; } // Allow triggered, simulated change events (#11500) jQuery.event.simulate( "change", this, event, true ); }); } return false; } // 事件代理; 懒惰模式为后代input节点添加change事件处理 jQuery.event.add( this, "beforeactivate._change", function( e ) { var elem = e.target; if ( rformElems.test( elem.nodeName ) && !jQuery._data( elem, "changeBubbles" ) ) { jQuery.event.add( elem, "change._change", function( event ) { if ( this.parentNode && !event.isSimulated && !event.isTrigger ) { jQuery.event.simulate( "change", this.parentNode, event, true ); } }); jQuery._data( elem, "changeBubbles", true ); } }); }, handle: function( event ) { var elem = event.target; // 吞掉本地单选框和复选框的change事件,我们在上面已经出发了事件 if ( this !== elem || event.isSimulated || event.isTrigger || (elem.type !== "radio" && elem.type !== "checkbox") ) { return event.handleObj.handler.apply( this, arguments ); } }, }
OK,到此,事件系统也告一个段落了,谢谢大家多多支持。
您可能感兴趣的文章: