Home > Web Front-end > JS Tutorial > body text

js compatibility issues: summary of js event compatibility methods (with examples)

不言
Release: 2018-08-11 14:37:15
Original
2270 people have browsed it

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;
}
Copy after login

2. Compatibility of keyboard event objects

e.keyCode || e.which
Copy after login

3. Compatibility of js preventing event bubbling

对象.事件=function(e){
    var e = e || event;
    e.stopPropagation?e.stopPropagation():e.cancelBubble=true;
    
}
Copy after login

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
Copy after login

5 , Compatibility of obtaining the event source in the delegate event

对象.事件=function(e){
    var target = e.target || e.srcElement;
}
Copy after login

6. Compatibility of obtaining the page scroll distance

document.documentElement.scrollTop || document.body.scrollTOP
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!