IE low-version browsers and other browsers are generally different, in order to achieve compatibility, you can use the following methods:/* Add event listener for elements compatible with various browsers */
if (div.attachevent) {//ie browser
Div.attachevent ("onclick", show);
}else{
Div.addeventlistener ("click", Show,false);
}
/* Same reason for element removal event listener compatible with various browsers */
if (div.detachevent) {
Div.detachevent ("onclick", show);
}else{
Div.removeeventlistener ("click", Show,false);} When a parent container (such as a Div) contains several subset containers (DIV), any click on a container (DIV) will trigger events for other containers. To solve such problems, the example is as follows://false event bubbling (from child element to parent Element) True: Event capture (from parent element to child element) Div1.addeventlistener ("click", Showconsole1,false); function ShowConsole1 (e) {
E = e | | window.event;//event bubbling processing prevents event bubbling if (e.stoppropagation) {
E.stoppropagation (); Non-IE
}else{
E.cancelbubble = true;
}
Console.log ("Div1"); } <a href= "https://www.baidu.com/" onclick= "Showbaidu" (event) > find him thousands of </a>/* three: Cancel the default event */
function Showbaidu (e) {
if (E.preventdefault) {/* Non IE browser */
E.preventdefault ();
}else{/*ie Browser */
E.returnvalue = false;
}
Console.log ("Don't jump! ");}
JS various browser compatibility issues