事件物件兼容 window.event只能在IE下運行,而不能在Firefox下運行,這是因為Firefox的event只能在事件發生的現場使用,Firefox必須從源處加入event作引數傳遞,IE忽略該引數,用window.event來讀取該event, 解決的方法: event = event || window.event 阻止事件冒泡兼容 stopPropagation()和cancelBubble,前者是方法,是標準的寫法,后者是屬性,賦值true表示阻止,是IE的寫法, 解決方法: 判斷stopPropagation是否存在,如果存在則用標準寫法否則則用IE的寫法,不可反過來判斷, event.stopPropagation ? event.stopPropagation() : event.cancelBubble=true; 阻止默認行為兼容 preventDefault() 和 returnValue() 解決方法: event.preventDefault?event.preventDefault():event.returnValue=https://www.cnblogs.com/gsdnb/p/false; return false;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/179046.html
標籤:JavaScript
