通过键盘事件判断敲击的是那个按键,如果是回车,判断所在input然后自定义那个input获得焦点

解决方案 »

  1.   

    input命名是不規則的,是用記錄的id命名的,
      

  2.   

    无所谓,事件绑定在input控件上,然后通过每一个控件调用函数时把自己this或者自己的ID传到事件调用的函数上就可以分辨了
      

  3.   

    用tabindex  排序(横向)点回车用TAB来代替:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
            "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
        <title></title>
        <script type="text/javascript">
          document.onkeydown = function(){
    if (event.keyCode==13) {
      event.keyCode = 9;
    }
      }
        </script>
    </head>
    <body>
    <table>
        <tr>
            <td>
                <input type="text" tabindex="1"/>
            </td>
            <td>
                <input type="text" tabindex="2"/>
            </td>
            <td>
                <input type="text" tabindex="3"/>
            </td>
        </tr>
         <tr>
            <td>
                <input type="text" tabindex="4"/>
            </td>
            <td>
                <input type="text" tabindex="5"/>
            </td>
            <td>
                <input type="text" tabindex="6"/>
            </td>
        </tr>
    </table>
    </body>
    </html>
      

  4.   

    上面一个demo ;按自己的需求变更。
      

  5.   

    为什么在问问题的时候不先搜索一下论坛?前几天才有人问的http://topic.csdn.net/u/20090321/18/d0ebe17d-6522-4bb0-bfad-f91755a011bf.html
      

  6.   

    楼上的代码 在IE下都是没问题的 但涉及到event.keyCode的兼容是挺麻烦的如果要兼容FF 可以用这个
    <!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>
      <title> new document </title> </head> <body>
      <table>
    <tr>
    <td><input type="text" id="a1" tabIndex="1"/></td>
    <td><input type="text" id="a4" tabIndex="4"/></td>
    <td><input type="text" id="a7" tabIndex="7"/></td>
    </tr>
    <tr>
    <td><input type="text" id="a2" tabIndex="2"/></td>
    <td><input type="text" id="a5" tabIndex="5"/></td>
    <td><input type="text" id="a8" tabIndex="8"/></td>
    </tr>
    <tr>
    <td><input type="text" id="a3" tabIndex="3"/></td>
    <td><input type="text" id="a6" tabIndex="6"/></td>
    <td><input type="text" id="a9" tabIndex="9"/></td>
    </tr>
      </table>
        <script type="text/javascript">
      <!--
    document.onkeydown = function(e){
    var e = e || window.event;
    var keyCode = e.keyCode || e.which;
    var oTarget = e.srcElement || e.target;
    if(keyCode == 13){
    if(oTarget.type == "text"){
    var tabIndex = oTarget.tabIndex;
    tabIndex++;
    }
    }
    var oInput = document.getElementsByTagName("input");
    for(var i =0;i < oInput.length;i++){
    if(oInput[i].type == "text" && oInput[i].id.indexOf('a') != -1){
    if(oInput[i].tabIndex == tabIndex){
    oInput[i].focus();
    }
    }
    }
    }
      //-->
      </script>
     </body>
    </html>