javascript 一個文本框輸入完畢后自動跳轉到下一個文本框的方法


<!DOCTYPE html>
<html>
<head>
<title>js24.html</title>

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

<!-- 輸入完畢之后光標自動移動到下一個框的方法 -->

<script type="text/javascript">

function moveNext(object,index){

if(object.value.length == 4){

document.forms[0].elements[index+1].focus();
}

}

function showResult(){

var f = document.forms[0];
var result="";

for(var i = 0; i<4 ;i++){

result += f.elements[i].value;
}

alert(result);

}
</script>

</head>

<body onload = "document.forms[0].elements[0].focus();">
<form>
<input type = "text" size = 3 maxlength=4 onkeyup = "moveNext(this,0);">-
<input type = "text" size = 3 maxlength=4 onkeyup = "moveNext(this,1);">-
<input type = "text" size = 3 maxlength=4 onkeyup = "moveNext(this,2);">-
<input type = "text" size = 3 maxlength=4 onkeyup = "moveNext(this,3);"><br>

<input type = "button" value = "顯示所有" onclick = "showResult();">
</form>
</body>
</html>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM