JavaScript设置或获取元素tab顺序|Element tabIndex 属性
定义与用法
tabIndex 属性可设置或返回元素的 tab 键控制次序。
语法格式
HTMLElementObject.tabIndex= tabIndex
示例代码
改变三个链接的 tab 排序:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>奔月教程(runoon.com)</title>
<script>
function changeTabIndex() {
document.getElementById('1').tabIndex = "3";
document.getElementById('2').tabIndex = "2";
document.getElementById('3').tabIndex = "1";
}
</script>
</head>
<body>
<p><a id="1" href="https://www.runoon.com">1</a></p>
<p><a id="2" href="https://www.runoon.com">2</a></p>
<p><a id="3" href="https://www.runoon.com">3</a></p>
<input type="button" onclick="changeTabIndex()" value="Change TabIndex">
</body>
</html>
浏览器支持
属性 | |||||
---|---|---|---|---|---|
tabIndex | Yes | Yes | Yes | Yes | Yes |
所有主要浏览器都支持 tabIndex 属性