按钮和链接键盘触发器

编程入门 行业动态 更新时间:2024-10-27 10:21:40
本文介绍了按钮和链接键盘触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在进行研究时,我遇到了此声明:

警告:使用按钮角色标记链接时要小心。 按钮预计会使用空格键触发,而链接预计将使用 Enter 键触发。 b $ b

  • 有谁知道为什么不同的按键用于按钮/链接?

  • 同时触发空间和 Enter ?

  • 在阅读本文之前,作为用户,我不知道何时使用 Space 或 Enter 。

    快速浏览一下Google,看看他们做了些什么。

    • For 链接 空格向下滚动和 Enter 触发器
    • > 空格和 Enter 触发器

    解决方案

  • 按钮是表单元素。 如果您选择复选框元素,空格将切换复选框,而输入将提交表单。

    所以为了保持一致,按钮的操作方式也是一样的。实际上,他们同时接受 enter 和 space ,没有任何区别。

  • 不仅可以,但你必须

    阅读 ARIA的第三条规则:

    例如,如果使用role = button元素必须能够获得焦点并且用户必须能够使用输入(在WIN OS上)或返回(MAC OS)和空格键来激活与元素相关联的动作。

  • 这是出于历史原因,并非在任何官方建议中已经定义,据我所知

    例如2000年的一个旧bug( https ://bugzilla.mozilla/show_bug.cgi?id = 56495 )已经指出,空格键预计在按钮上工作。也许是Windows行为的继承。

  • While doing research I came across this statement:

    Warning: Be careful when marking up links with the button role. Buttons are expected to be triggered using the Space key, while links are expected to be triggered using the Enter key.

  • Does anyone know why a different key is used for buttons / links?

  • Is it ok to trigger using both Space and Enter?

  • Before reading this I, as a user, would have had no idea when to use Space or Enter.

    Had a quick look at Google to see what they do.

    • For links Space scrolls down and Enter triggers
    • For buttons both Space and Enter trigger

    解决方案

  • Buttons are form elements.

    If you select a checkbox element, space will toggle the checkbox while enter will submit the form.

    So to be coherent, buttons act the same way. In practice, they accept both enter and space without any difference.

  • It is not only ok but you have to

    Read inside the Third rule of ARIA:

    For example, if using role=button the element must be able to receive focus and a user must be able to activate the action associated with the element using both the enter (on WIN OS) or return (MAC OS) and the space key.

  • This is for historical reason, not that it has been defined in any official recommendation, as far as I know

    For instance an old bug from 2000 (bugzilla.mozilla/show_bug.cgi?id=56495) already stated that space bar was expected to work on buttons. Maybe an inheritance from Windows behavior.

  • 更多推荐

    按钮和链接键盘触发器

    本文发布于:2023-11-12 04:57:54,感谢您对本站的认可!
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:触发器   按钮   键盘   链接

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!