jQuery鼠标的.click()是通过键盘导航启动的 [英] jQuery mouse's .click() is launched by keyboard navigation

查看:174
本文介绍了jQuery鼠标的.click()是通过键盘导航启动的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现jQuery 点击事件的奇怪行为。如果我们使用键盘导航(辅助功能选项),点击是通过Enter或Space启动的(具体取决于我们使用的HTML元素)。

I've found strange behavior of jQuery click event. If we are using keyboard navigation (accessibility case), click is launched by Enter or Space (it depends, which HTML element we are using ).

on jsfiddle,您可以尝试在Result框架中使用键盘导航,然后点击在不同的情况下启动:

There is a test page on jsfiddle, You could try to navigate with keyboard in Result frame, and click is launched in different situations :

http://jsfiddle.net/DCXhN/9/ ​​

在jQuery手册中,我找到了以下内容点击活动的说明:

In jQuery manual, I have found following description of click event :

>当鼠标指针在元素上方时,点击事件被发送到元素,鼠标按钮被按下并释放。任何HTML元素都可以接收此事件。

是否正常?如果是正常行为,如何只拦截鼠标点击事件?

Is it normal ? How to intercept only mouse click events if it's normal behavior ?

推荐答案

是的,这是正常的。 JQuery文档是正确的,但有点不完整。有关 WC3网站的更多详情,例如:

Yes, this is normal. The JQuery documentation is correct, but a bit incomplete. There's more details on the WC3 site - eg:


注意:为了最大的可访问性,鼓励内容作者在定义自定义控件的激活行为时使用点击事件类型,而不是其他指向设备事件类型mousedown或mouseup,这是更具体的设备。虽然点击事件类型具有其在指针设备(例如,鼠标)中的起源,但是后续实现增强已经将其扩展到该关联之外,并且它可以被认为是用于元素激活的设备无关事件类型。
Note: For maximum accessibility, content authors are encouraged to use the click event type when defining activation behavior for custom controls, rather than other pointing-device event types such as mousedown or mouseup, which are more device-specific. Though the click event type has its origins in pointer devices (e.g., a mouse), subsequent implementation enhancements have extended it beyond that association, and it can be considered a device-independent event type for element activation.

或者换句话说,对于某些元素,click()本质上是一个逻辑事件,

Or, put another way, for some elements, click() is essentially a logical event rather than a device-specific event.

如果您只想回应鼠标输入,可以使用mousedown / up事件 - 但请注意,您必须将自己的UI键盘可单独访问(例如,使用keydown / press / etc事件提供键盘等效)。

If you really want to only respond to mouse input, you can use the mousedown/up events - but keep in mind you'll then have to make your UI keyboard accessible separately (eg. using keydown/press/etc events to provide a keyboard equivalent).

这篇关于jQuery鼠标的.click()是通过键盘导航启动的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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