HTML DOM tabIndex 属性
JavaScript基础 2022-06-08 16:29:48小码哥的IT人生shichen
HTML DOM tabIndex 属性
定义和用法
tabIndex 属性可设置或返回确认按钮的 tab 键控制次序。
语法
submitObject.tabIndex=tabIndex
实例
下面的例子可显示表单元素的 tab 键控制次序:
<html>
<head>
<script type="text/javascript">
function showTabIndex()
{
var email=document.getElementById('email').tabIndex;
var r1=document.getElementById('submit1').tabIndex;
document.write("Tab index of email: " + email);
document.write("<br />");
document.write("Tab index of submit button: " + r1);
}
</script>
</head>
<body>
<form>
Email: <input type="text" id="email" tabIndex="1"
size="25" value="someone@example.com" />
<br />
<input type="submit" id="submit1" tabIndex="2" />
<br /><br />
<input type="button" onclick="showTabIndex()" value="Show tabIndex" />
</form>
</body>
</html>
TIY
完整实例【显示表单元素的 tab 键控制次序】:
<html>
<head>
<script type="text/javascript">
function showTabIndex()
{
var email=document.getElementById('email').tabIndex;
var r1=document.getElementById('submit1').tabIndex;
document.write("Tab index of email: " + email);
document.write("<br />");
document.write("Tab index of submit button: " + r1);
}
</script>
</head>
<body>
<form>
Email: <input type="text" id="email" tabindex="1" size="25" value="someone@example.com" />
<br />
<input type="submit" id="submit1" tabindex="2" />
<br /><br />
<input type="button" onclick="showTabIndex()" value="Show tabIndex" />
</form>
</body>
</html>
可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html