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

查看:23
本文介绍了复选框上的 .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?

如果你不相信我,那么自己试试

推荐答案

onchange 在 IE 中仅在复选框失去焦点时触发.因此,如果您按 Tab 键,按几次空格,然后按 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天全站免登陆