<span> 缺少点击事件里面的<按钮>火狐上的元素 [英] Missing click event for <span> inside <button> element on firefox

查看:17
本文介绍了<span> 缺少点击事件里面的<按钮>火狐上的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我对按钮元素内的 span 元素的单击事件绑定操作时,我遇到了 Firefox 32 的问题.其他浏览器似乎运行良好.

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.

这里是说明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>

所以,我的建议是使用另一个 span 或 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>

希望对你有帮助...

注意:您的代码可以在 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;span&gt; 缺少点击事件里面的&lt;按钮&gt;火狐上的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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