可能重复:
如果我还没有使用 bind 或 click 将事件处理程序绑定到它,我可以调用 jquery click() 来跟踪 <a> 链接吗?
我写了以下代码。
<div style="background-color:orange">Click me to open the link
<br>
<a target="_blank" href="http://example.com">Link</a>
</div>
<script>
jQuery('div').click(function(){
jQuery('a').click();
});
jQuery('a').click(function(e){
alert('It came here!');
e.stopPropagation();
return true;
});
</script>
但是链接打不开。
更新:将目标属性添加到 A 标记。