- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>按回車鍵 輸入框光標依次移動</title>
- <script type="text/javascript">
- <!--
- function enter(obj) {
- var allInputs =document.getElementsByTagName("input");
- var name = obj.name;
- var next = Number(name) + 1;
- if(next == allInputs.length+1) {
- next = 1;
- }
- if(event.keyCode =="13") {
- form1.elements[next-1].focus();
- }
- }
- //-->
- </script>
- </head>
- <body>
- <form name="form1">
- <input type="text" name="1" onkeydown="enter(this)" />
- <input type="text" name="2" onkeydown="enter(this)" />
- <input type="text" name="3" onkeydown="enter(this)" />
- <input type="text" name="4" onkeydown="enter(this)" />
- <input type="text" name="5" onkeydown="enter(this)" />
- </form>
- </body>
- </html>
按回車鍵 輸入框光標依次移動
思路:
找到當前光標input標籤
enter(obj),var name = obj.name;
回車響應事件
event.onkeydown = "13"
光標移動到下一個input
form1.elements[next-1].focus();
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.