为什么复选框的点击处理程序没有在FF中被触发,当它的标签被点击了? [英] Why is a checkbox's click handler not fired in FF, when its label is shift clicked?

查看:136
本文介绍了为什么复选框的点击处理程序没有在FF中被触发,当它的标签被点击了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用下面的代码,当点击标签时,为什么FF中的复选框的点击处理程序不被触发? Chrome和IE11都会触发它。

 < script> 
function show(event){
alert((event.srcElement || event.target).id);
};
< / script>
< input type =checkboxid =checkboxonclick =show(event); />
< label for =checkboxid =labelonclick =show(event);> Click me!< / label>

小提琴: http://jsfiddle.net/66XP4/2/

解决方案

与在Firefox中单击不同的默认操作。前者扩展了文本选择。后者执行激活。由于激活是点击复选框触发,你没有得到一个点击它。就像你没有右键点击标签一样。


With the following code, when shift clicking the label, why isn't the checkbox's click handler fired in FF? Both Chrome and IE11 fires it.

<script>
    function show(event) {
        alert((event.srcElement||event.target).id);
    };
</script>
<input type="checkbox" id="checkbox" onclick="show(event);" />
<label for="checkbox" id="label" onclick="show(event);">Click me!</label>

Fiddle: http://jsfiddle.net/66XP4/2/

解决方案

Shift-clicking has a different default action than just clicking in Firefox. The former extends the text selection. The latter performs activation. Since activation is what fires the click on the checkbox, you're not getting a click on it. Just like you don't with a right-click on the label.

这篇关于为什么复选框的点击处理程序没有在FF中被触发,当它的标签被点击了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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