按回車鍵 輸入框光標依次移動

思路:
找到當前光標input標籤
    enter(obj),var name = obj.name;
回車響應事件      
  event.onkeydown = "13"
光標移動到下一個input
  form1.elements[next-1].focus();      
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>按回車鍵 輸入框光標依次移動</title>
  6. <script type="text/javascript">
  7. <!--
  8. function enter(obj) {
  9.     var allInputs =document.getElementsByTagName("input");
  10.     var name = obj.name;
  11.     var next = Number(name) + 1;
  12.     if(next == allInputs.length+1) {
  13.         next = 1;
  14.     }
  15.     
  16.     if(event.keyCode =="13") {
  17.         form1.elements[next-1].focus();
  18.     }
  19. }
  20. //-->
  21. </script>
  22. </head>
  23. <body>
  24. <form name="form1">
  25. <input type="text" name="1" onkeydown="enter(this)" />
  26. <input type="text" name="2" onkeydown="enter(this)" />
  27. <input type="text" name="3" onkeydown="enter(this)" />
  28. <input type="text" name="4" onkeydown="enter(this)" />
  29. <input type="text" name="5" onkeydown="enter(this)" />
  30. </form>
  31. </body>
  32. </html>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章