<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
input{
width: 40px;
}
</style>
</head>
<body>
<form id="box">
<input type="text" tabindex="1" maxlength="4" onkeyup="fun(this,this.value)"/>
<input type="text" tabindex="2" maxlength="4" onkeyup="fun(this,this.value)"/>
<input type="text" tabindex="3" maxlength="4" onkeyup="fun(this,this.value)"/>
</form>
</body>
</html>
<script type="text/javascript">
let oBox = document.getElementById("box");
function fun(a,b){
if(a.maxLength == b.length){
// tabIndex 属性设置或返回文本域的 tab 键控制次序
let next = a.tabIndex;
//form表单标签和其它有些不太一样
//form的elements属性返回包含表单中所有元素的数组
//form.length属性返回表单中元素的数目
if(next < oBox.length){
oBox.elements[next].focus();
}
}
}
</script>
文本框自动聚焦
最新推荐文章于 2022-11-03 16:20:24 发布