以下 onClick 代码仅适用于 Chrome。在 Opera 和 Firefox 中,该按钮仅在单击时隐藏,而不打开链接。
<div>
<button>
<a onClick="window.open('http://www.google.ro', 'sharer',
'toolbar=0,status=0,width=500,height=325');"
href="javascript: void(0)"><img src=""/></a>
</button>
</div>
JavaScript:
<script type='text/javascript'>//<![CDATA[
$(function(){
$("button").click(function() {
$(this).parent().hide();
})
});//]]>
如何解决这个问题?
最佳答案
button
元素中禁止使用 a
元素。
来自the W3.org on the button element :
there must be no interactive content descendant.
互动内容描述here 。其中列出了 a
。
这个想法是按钮处理交互。这就是为什么浏览器被允许不让后代接收事件。
就您而言,您只需将窗口打开操作绑定(bind)到 button
元素上即可。
关于JavaScript onClick 仅适用于 Chrome,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15569104/