The content of this article is about js compatibility issues: a summary of js event compatibility methods (with examples), which has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
1. Compatibility of event objects
对象.事件=function(e){ var e= e || event; }
2. Compatibility of keyboard event objects
e.keyCode || e.which
3. Compatibility of js preventing event bubbling
对象.事件=function(e){ var e = e || event; e.stopPropagation?e.stopPropagation():e.cancelBubble=true; }
4. JS browser compatibility: compatibility of preventing browser default behavior
对象.事件=function(e){ var e = e || event; e.preventDefault?e.preventDefault():e.returnValue=false; } 或者 return false
5 , Compatibility of obtaining the event source in the delegate event
对象.事件=function(e){ var target = e.target || e.srcElement; }
6. Compatibility of obtaining the page scroll distance
document.documentElement.scrollTop || document.body.scrollTOP
Related recommendations:
js event source window.event.srcElement compatibility writing method (detailed explanation)
js gets keyboard key response event (compatible with various browsers)_javascript skills
Native JS binding pulley scroll event compatible with common browsers_javascript skills
The above is the detailed content of js compatibility issues: summary of js event compatibility methods (with examples). For more information, please follow other related articles on the PHP Chinese website!