*举例:取消a链接跳转
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>取消默认事件</title>
</head>
<style>
.div1 {
width: 300px;
height: 300px;
background: red;
}
.div2 {
width: 100px;
height: 100px;
background: yellow;
}
</style>
<body>
<a href="http://www/baidu.com" id="newA">baidu </a>
</body>
<script>
newA.onclick = function(e) {
if (e.preventDefault) {
e.preventDefault();
} else {
e.returnValue = false;
}
}
</script>
</html>