請參閱下面的代碼/ HTML。我有一個帶有「onclick」事件處理程序的DIV內部的「href」的錨點。如果我點擊錨點,瀏覽器會打開一個新選項卡並執行「onclick」。如果用戶點擊了錨點,我想抑制「onclick」的執行。在錨點的onclick中返回「false」會啓動href。這裏有什麼解決方案?執行錨點的href,但不是底層DIV的「onclick」?
<html>
<head>
<script>
function clicky()
{
alert("Click!");
}
</script>
</head>
<body>
<div id="adiv" onclick="clicky()" style="border:1px solid black;background-color:red;width:400px;height:300px;">
<a href="http://www.gohere.but.dont.execute.onclick.com" target="_blank">a link</a>
</div>
</body>
</html>
勒
http://stackoverflow.com/questions/387736/how-to-stop-event-propagation-with-inline-onclick-attribute的可能的複製。 – 2010-10-20 15:05:29