请参阅下面的代码/ 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