[HTML5] Focus management using CSS, HTML, and JavaScript

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[HTML5] Focus management using CSS, HTML, and JavaScript相关的知识,希望对你有一定的参考价值。

Something important to consider when coding a web application is managing the user‘s focus. For keyboard and screen reader users, we must ensure their focus is not dropped as content is deleted or shown in new contexts. Skip links also provide a way for users to get past a lot of content. In this lesson, you‘ll learn html, CSS and javascript techniques for focus management that can be applied to many situations.

 

For example, you have a list of items, when you want to delete an item, you and want auto foucs on next item‘s delete button.

All what you need to do is to find next item, and send focus onto it.

    $(.btn-delete).on(click, function() {
        $(this).parent().remove();
        listItems.find(.btn-delete).first().focus();
    });

 

Next thing if you want the items which are out of foucs managmenet not to have the outline when you nav around the page.

[tabindex="-1"] {
    outline: 0;
}

 

To build a skip links: It hidden by default, but when we use Tab keyboard, it will shows up.

  <ul class="skip-links">
    <li><a href="#main">Main content</a></li>
    <li><a href="#footer">Global footer</a></li>
  </ul>
ul.skip-links {
    list-style: none;
    position: absolute;
}
    ul.skip-links a {
        background-color: #fff;
        display: block;
        left: -999999px;
        padding: 1em;
        position: absolute;
    }
    ul.skip-links a:focus {
        left: 0;
    }

 

以上是关于[HTML5] Focus management using CSS, HTML, and JavaScript的主要内容,如果未能解决你的问题,请参考以下文章

在 WKWebView 中调用 <input type="text"> 上的 .focus() 会导致键盘延迟

200 classList 属性

视频流传输协议

iOS webview html5 移动端 软键盘弹起遮挡输入框

e107 Bootstrap CMS(内容管理系统)v2,带有PHP、MySQL、HTML5、jQuery和Twitter Bootstrap。问题讨论室:https://gitter.im/e107

js为啥我的focus获得焦点无效