HTML:
<a href='http://www.jsfiddle.net'><span>link</span></a>
脚本:
$('span').click(function(event) {
window.open('http://www.google.com');
event.stopImmediatePropagation();
//The line below does prevent jsfiddle.net from loading on the right.
//event.preventDefault();
});
$('a').click(function() {
//This function is not triggered as event propagation has been stopped.
alert('You will never see this.');
});
在演示中单击“链接”将打开 google.com 和 jsfiddle.net。我的问题来了:为什么<a>
(在这种情况下打开 jsfiddle.net)的默认行为被其子项(<span>
在这种情况下)继承?有什么规格可以参考吗?提前致谢。