Missing click event for lt;spangt; inside lt;buttongt; element on firefox(lt;spangt; 缺少点击事件里面的lt;按钮gt;火狐上的元素)
问题描述
当我对按钮元素内的 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
这篇关于<span> 缺少点击事件里面的<按钮>火狐上的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:<span> 缺少点击事件里面的<按钮
基础教程推荐
- 检查 HTML5 拖放文件类型 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- Bokeh Div文本对齐 2022-01-01
