使用Javascript停止元素事件的传播。非常简单,看代码:

[code lang=”js” highlight=”8″]
function stopPropagation(e) {
if (e && e.stopPropagation) e.stopPropagation(); //W3C;
else window.event.cancelBubble = true; //only ie;
}

<div onclick="alert(‘div000000000000’);">
DIV 000000000000000000
<a onclick="alert(‘div1111111’); stopPropagation(event);" href="javascript:void(0);">DIV 111111111111</a
</div>
[/code]

使用Javascript取消浏览器的默认动作。无话可讲,看代码:

[code lang=”js” highlight=”6″]
function preventDefault(e) {
if (e && e.preventDefault) e.preventDefault(); //W3C;
else window.event.returnValue = false; //only ie;
}

<a onclick="preventDefault(event);" href="http://www.google.com" target="_blank">www.google.com</a>
[/code]