Stop bubbling, to prevent the default event (to prevent capture)

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<ul id="b">
<li id="a">A</li>
<li>A</li>
<li>A</li>
<li>A</li>
<a href="http://caibaojian.com/javascript-stoppropagation-preventdefault.html" id="c">访问</a>
</ul>
<script>
window.onload=function () {
var a=document.getElementById("a");
var b=document.getElementById("b");
a.onclick=function () {
alert("xxx");
window.event? window.event.cancelBubble = true : e.stopPropagation();//阻止冒泡
}
B.onclick = function () {
Alert ( "bbbb");
}
c.onclick = function (E) {// prevent the default behavior of the browser, but bubble
IF (E && e.preventDefault) {
E. the preventDefault ();
}
// IE embodiment the default function to prevent the operation of
the else {
window.event.returnValue = to false;
}
return to false;

}
}
</ Script>
</ body>
</ HTML>

Guess you like

Origin www.cnblogs.com/cycczh/p/11666702.html