There are two troubles in browsers. The following provides two function solutions for reference and a demo to help you understand the two troubles I mentioned more intuitively.
-
- <Script language = "JavaScript">
-
- /* ---------------------------
- function: Stop event bubbling
- --------------------------- */
- function stopbubble (e) {
- // If an event object is provided, this is a non-IE browser
- If (E & E. stoppropagation)
- // Therefore, it supports the W3C stoppropagation () method
- E. stoppropagation ();
- else
- // otherwise, we need to use IE to cancel event bubbling.
- window. event. cancelbubble = true;
- }
- // block the default browser behavior
- function stopdefault (e) {
- // block the default browser action (W3C)
- If (E & E. preventdefault)
- E. preventdefault ();
- // method of blocking the default action of the function in IE
- else
- window. event. returnvalue = false;
- return false;
- }
-
- </SCRIPT>