完善tab页面定位
當我們用錨點定位到頁面某個元素時,接下來按tab的話是想進入到目前元素(?id="content")的下一個連接 <a href="#content">Skip to Content</a><!-- other links --><div id="content"><!-- your content here -->
</div> 但是chrome 和 ie 有問題,按tab是選中 skip to Content之后的那個連接,修復方法就是在定位之后選中 content,通過修改 tabIndex window.addEventListener("hashchange", function(event) {var element = document.getElementById(location.hash.substring(1)); //location.hash.substring(1) 指的是被點擊的連接的href中的contentif (element) {if (!/^(?:a|select|input|button|textarea)$/i.test(element.tagName)) {element.tabIndex = -1;}element.focus();}}, false); tabIndex的值,根據W3C的規定,范圍在0到 32767,通常只有表單元素可以設為focus,但是通過把tabIndex設置為-1,并且調用元素的focus函數,任何元素也可以實現(除了opera)
轉載于:https://www.cnblogs.com/chuangweili/p/5162747.html
總結
- 上一篇: 阅读《Oracle内核技术揭秘》的读书笔
- 下一篇: 重构手法(一)之重新组织函数