为&LT失踪单击事件;跨度>里面<按钮和GT;在Firefox元 [英] Missing click event for <span> inside <button> element on firefox

查看:200
本文介绍了为&LT失踪单击事件;跨度>里面<按钮和GT;在Firefox元的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我'遇到问题与Firefox 32,当我绑定一个按钮元素中跨度元素的click事件采取行动。其他浏览器似乎效果很好。

I'am experiencing problem with Firefox 32 when I bind action on click event of span element inside a button element. Other browsers seems to works well.

下面的 code说明上的jsfiddle 的问题。

<span onClick="alert('test');">**Working**</span><br>
<button>inside a button <span onClick="alert('test');">**Not working**</span></button>

是否有人知道是什么原因,如果它是一个错误或功能?

Does anybody know why and if it's a bug or a feature ?

推荐答案

据我知点击子元素,因为它是嵌套在一个按钮内将无法正常工作。按钮是不是子元素的容器 - 只有文本

As far as i known clicking the children elements won't work because it is nested inside a button. A button is not container for child elements - only for text.

如果你尝试喜欢它下面总是告诉你单击该按钮。

If you try like below it always tell that you clicked the button.

      <button type="button" onclick="alert('You clicked the button!');">
         inside a button <span onClick="alert('clicked span');">**Not working**</span>
      </button>

所以,我的建议是使用另一个范围或一个div

So, my suggestion is to use another span or a div

      <div class="button_replace">
      inside a div <span onClick="alert('clicked span');">**working**</span>
      </div>

希望它可以帮助...

Hope it helps...

请注意:您code将在Chrome工作,但不能在Firefox和我的答案是使工作在Firefox替代解决方案。

Note: Your code will work in chrome but not in firefox and my answer is alternative solution for making work in firefox

这篇关于为&LT失踪单击事件;跨度&GT;里面&LT;按钮和GT;在Firefox元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆