hal*_*web 92
tabindex分配按以下方式处理(对于支持该tabindex属性的元素):
这些信息来自:http://www.w3.org/TR/html401/interact/forms.html#adef-tabindex
Alo*_*hci 22
这比Alan Haggai Alavi的答案要复杂一些.
在解析之后,IE8和Opera就像HTML4规范所说的那样.然而,Firefox和Chrome使用DOM命令.这对于像这样的格式错误的标记很重要.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Test case 1</title>
</head>
<body>
<form>
<table>
<tr><td><input id="first" value="first in the character stream" tabindex="0"></td></tr>
<div><input id="second" value="second in the character stream" tabindex="0"></div>
</table>
<form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
您可能会争辩说,由于格式错误,所有投注都会被取消,那么JavaScript呢?
考虑这种情况:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Test case 2</title>
<script type="text/javascript">
moveFirst = function()
{
var f = document.getElementById("first");
f.parentNode.removeChild(f);
document.body.appendChild(f);
}
</script>
</head>
<body>
<form>
<table>
<tr><td><input id="first" value="first in the character stream" tabindex="0"></td></tr>
<tr><td><div><input id="second" value="second in the character stream" tabindex="0"></div></td></tr>
</table>
<form>
<div onclick="moveFirst()">move</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,当用户点击"移动"时,IE8,Firefox,Chrome和Opera都使用DOM顺序,而不是字符流顺序.
最后,HTML5几乎不能保证tabindex为0的元素之间的Tab键顺序,只是声明它应该遵循平台约定.