复选框上的.click和.change之间的区别 [英] What the difference between .click and .change on a checkbox

查看:750
本文介绍了复选框上的.click和.change之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在环顾四周,为一个复选框添加一个事件,我会认为人们会使用 .change 设置一个更改事件,但我发现,使用 .click

I was looking around to add an event to a checkbox and I would have thought people would use .change to set up a change event but instead I found that people are using .click

有什么原因吗?他们似乎都与点击事件和键盘更改工作正常。我错过了什么?

Is there a reason for this? They both seem to work fine both with clicked events and with keyboard changes. Am I missing something?

如果您不相信我,请 试试自己

If you don't believe me then try it out yourself

推荐答案

onchange IE仅在复选框失去焦点时触发。所以如果你tab到它,击中空间几次,选项卡,你只会得到一个 onchange 事件,但几个 onclick 事件。

onchange in IE only fires when the checkbox loses focus. So if you tab to it, hit space a few times, tab out, you'll only get one onchange event, but several onclick events.

注意:这是一个非常,非常,非常罕见的时候,当IE的行为是正确的。

Note: this is one of the very, very, very rare times when IE's behavior is correct (according to spec) and other browsers are wrong.

这篇关于复选框上的.click和.change之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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