2023年6月21日发(作者:)
jQuery的浏览器兼容性策略(转载)之前写过⼀篇⽇志(/?id=34),说FF没有cancelBubble,所以要做兼容,其实多虑了,JQ已经为我们做好兼容性了。也就是说,要阻⽌冒泡,直接使⽤$("a").click(function(e) {opagation();})这样即可。她还修正了preventDefault ,target ,relatedTarget,pageX/Y,(确定按了键盘或者⿏标上的哪个按键。)多的不说,⼤家⾃⼰看代码吧(jQuery 1.2.3 /line:2093-2149)[quote] fix: function(event) {// store a copy of the original event object// and clone to set read-only propertiesvar originalEvent = event;event = ({}, originalEvent);// add preventDefault and stopPropagation since// they will not work on the tDefault = function() {// if preventDefault exists run it on the original eventif (tDefault)tDefault();// otherwise set the returnValue property of the original event to false (IE)Value = false;};opagation = function() {// if stopPropagation exists run it on the original eventif (opagation)opagation();// otherwise set the cancelBubble property of the original event to true (IE)Bubble = true;};// Fix target property, if necessaryif ( ! ) = ment || document; // Fixes #1925 where srcElement might not be defined either// check if target is a textnode (safari)if ( pe == 3 ) = Node;// Add relatedTarget, if necessaryif ( !dTarget && ement )dTarget = ement == ? ent : ement;// Calculate pageX/Y if missing and clientX/Y availableif ( == null && X != null ) {var doc = ntElement, body = ; = X + (doc && Left || body && Left || 0) – (Left || 0); = Y + (doc && Top || body && Top || 0) – (Top || 0);}// Add which for key eventsif ( ! && ((de || de === 0) ? de : e) ) = de || e;// Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs)if ( !y && y )y = y;// Add which for click: 1 == left; 2 == middle; 3 == right// Note: button is not normalized, so don't use itif ( ! && ) = ( & 1 ? 1 : ( & 2 ? 3 : ( & 4 ? 2 : 0 ) ));return event;},[/quote]
2023年6月21日发(作者:)
jQuery的浏览器兼容性策略(转载)之前写过⼀篇⽇志(/?id=34),说FF没有cancelBubble,所以要做兼容,其实多虑了,JQ已经为我们做好兼容性了。也就是说,要阻⽌冒泡,直接使⽤$("a").click(function(e) {opagation();})这样即可。她还修正了preventDefault ,target ,relatedTarget,pageX/Y,(确定按了键盘或者⿏标上的哪个按键。)多的不说,⼤家⾃⼰看代码吧(jQuery 1.2.3 /line:2093-2149)[quote] fix: function(event) {// store a copy of the original event object// and clone to set read-only propertiesvar originalEvent = event;event = ({}, originalEvent);// add preventDefault and stopPropagation since// they will not work on the tDefault = function() {// if preventDefault exists run it on the original eventif (tDefault)tDefault();// otherwise set the returnValue property of the original event to false (IE)Value = false;};opagation = function() {// if stopPropagation exists run it on the original eventif (opagation)opagation();// otherwise set the cancelBubble property of the original event to true (IE)Bubble = true;};// Fix target property, if necessaryif ( ! ) = ment || document; // Fixes #1925 where srcElement might not be defined either// check if target is a textnode (safari)if ( pe == 3 ) = Node;// Add relatedTarget, if necessaryif ( !dTarget && ement )dTarget = ement == ? ent : ement;// Calculate pageX/Y if missing and clientX/Y availableif ( == null && X != null ) {var doc = ntElement, body = ; = X + (doc && Left || body && Left || 0) – (Left || 0); = Y + (doc && Top || body && Top || 0) – (Top || 0);}// Add which for key eventsif ( ! && ((de || de === 0) ? de : e) ) = de || e;// Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs)if ( !y && y )y = y;// Add which for click: 1 == left; 2 == middle; 3 == right// Note: button is not normalized, so don't use itif ( ! && ) = ( & 1 ? 1 : ( & 2 ? 3 : ( & 4 ? 2 : 0 ) ));return event;},[/quote]
发布评论