且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

设置像按钮这样的链接是不是很难进行访问?

更新时间:2023-12-03 09:33:28

关于何时使用< a href> 的一些一般提示a < button> < input type =submit>

Some general tips on when to use an <a href> versus a <button> or <input type="submit">:


  • 如果用户要访问新页面(或页面上的锚点),请使用< a href> 规范)。

  • 如果用户正在更改当前页面上的状态,请使用< button> spec )。

  • 如果用户正在提交形式,你se < input type =submit> < button type =submit> ( spec )。

  • If the user is going to a new page (or anchor on the page), use a <a href> (spec).
  • If the user is changing a state on the current page, use <button> (spec).
  • If the user is submitting a form, use <input type="submit"> or <button type="submit"> (spec).

我警告不要更改具有角色属性的元素的默认角色,因为这最终会导致一些混淆和某些辅助技术可能会发生冲突。这些也违反了首先和使用ARIA的第二规则。

I caution against changing the default role of an element with the role attribute, as that can ultimately cause some confusion and potentially conflict for some assistive technology. These also violate the first and second rules of ARIA use.

考虑键盘体验。按Enter键可以触发超链接(< a href> )。但是按Enter键或空格键可以触发真正的< button> 。当超链接具有焦点并且用户按下空格键时,页面将滚动一个屏幕。某些辅助技术的用户会根据所使用的元素预期行为。

Consider the keyboard experience as well. A hyperlink (<a href>) can be fired by pressing the enter key. But a true <button> can be fired by pressing the enter key or the space bar. When a hyperlink has focus and the user presses the space bar, the page will scroll one screenful. Users of some assistive technology will expect behavior based on the element used.

我认为值得一提的是,空格键触发的事件仅在释放密钥时触发,然后使用Enter键会在您按下键时(在释放之前)立即触发事件。

I think it’s also worth mentioning that events triggered by a space bar only fire when the key is released, whereas using the Enter key will fire the event as soon as you press the key down (prior to releasing it).

因此,请使用正确的元素开始使用上面的列表,然后根据你的需要设置它的样式。

So start with the right element for the task using the list above, then style it to look however you want.