HTML select onchange 可访问性问题
我们有一个使用 select
元素的 onchange
来触发移动到新页面的请求。
过去,我读过的网络可访问性文献通常建议不要这样做。这是因为它打破了用户的期望,并且浏览器(特别是 IE < 6)即使在使用键盘移动选项时也会触发更改事件,使得仅使用键盘的用户无法做出选择。
当通过鼠标或 Enter 键实际选择选项时,IE6+ 和我测试过的所有其他更现代的浏览器都会触发 select
onchange
。对相关应用程序的分析表明,早期的 IE 浏览器基本上已被淘汰 (< 0.01%)
鉴于我们的用户将能够仅使用键盘正确操作这些 select
元素,那么此功能是否应该仍然存在被认为是无障碍的障碍吗?这种行为如今似乎很常见,我也想知道它是否真的仍然以一种有意义的方式打破了用户的期望?
编辑:如果选择
通过鼠标或键盘获得焦点,IE 的行为会有所不同。当使用鼠标聚焦时,通过选项进行键盘输入不会触发 onchange
,但是当通过键盘按 Tab 键进行聚焦时,onchange
会在箭头穿过时触发。
We have a request to use a select
element's onchange
to trigger a move to a new page.
In the past, web accessibility literature I've read has generally advised against doing this. This was on the grounds that it breaks user expectation, and browsers (particularly IE < 6) fired the change event even when moving through options with the keyboard, making it impossible for keyboard-only users to make a selection.
IE6+ and all other more modern browsers I have tested fire the select
onchange
when an option is actually selected by mouse or enter key. Analytics for the application in question show that earlier IE browsers are essentially eradicated (< 0.01%)
Given that our users will be able to operate these select
elements properly with a keyboard only, should this feature still be considered an impediment to accessibility? This behavior seems so common nowadays that I wonder also if it really still does break user expectation in a meaningful way?
EDIT: IE behaves differently if the select
is focused with the mouse or keyboard. When focused with the mouse, keyboarding through options does not fire onchange
but when tabbing to focus it via keyboard, the onchange
does fire when arrowing through.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
select
元素的onchange
事件在页面之间导航绝对可以对仅使用键盘的用户造成可访问性问题。至少有 一种使用
onchange< 创建可访问的
select
元素的方法/code> handlers并且它自 2004 年以来一直出现在互联网上!
直接链接到 Accessible Select 代码。
Using the
onchange
event of theselect
element to navigate between pages can definitely pose an accessibility problem for keyboard-only users.There is at least one method of creating accessible
select
elements withonchange
handlers and it has been on the interwebs since 2004!Direct link to the Accessible Select code.
我同意你的观点,这种类型的功能很常见。然而,大多数网站使用链接而不是
I agree with you that this type of functionality is very common. However, most sites use links instead of a
<select>
to achieve the effect (if I'm not mistaken). I.E. it's the standard (pun intended).