表单如下:
<input name="R0" id="R0" type="text"  size="3" maxlength="1">
<input name="R1" id="R1" type="text"  size="3" maxlength="1">
<input name="R2" id="R2" type="text"  size="3" maxlength="1">
<input name="R3" id="R3" type="text"  size="3" maxlength="1">
问题一:页面加载完后,光标自动定位到R0表单
问题二:在R0表单输入1,回车后跳转到R1,输入2回车后跳转到R2,输入3回车后跳转到R3

解决方案 »

  1.   

    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>新建网页 1</title>
    <script>
    function window_onload(){
    $("R0").focus();
    }
    function $(id){
    return document.getElementById(id);
    }
    function key_down(obj){
    if(event.keyCode==13){//判断回车
    var v = obj.value;
    if(v=="1"){
    $("R1").focus();
    }else if(v=="2"){
    $("R2").focus();
    }else if(v=="3"){
    $("R3").focus();
    }
    }
    }
    </script>
    </head><body onload="window_onload()">
    <input name="R0" id="R0" type="text"  size="3" maxlength="1" onkeydown="key_down(this)"> 
    <input name="R1" id="R1" type="text"  size="3" maxlength="1"> 
    <input name="R2" id="R2" type="text"  size="3" maxlength="1"> 
    <input name="R3" id="R3" type="text"  size="3" maxlength="1">
    </body></html>
      

  2.   

    兼容FF的
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>新建网页 1</title>
    <script>
    function window_onload(){
        $("R0").focus();
    }
    function $(id){
        return document.getElementById(id);
    }
    function key_down(s,e){
        if(e.keyCode==13){//判断回车
            if(s=="1"){$("R1").focus();}
            else if(s=="2"){$("R2").focus();}            
            else if(s=="3"){$("R3").focus();}
        }
    }
    </script>
    </head><body onload="window_onload()">
    <input name="R0" id="R0" type="text"  size="3" maxlength="1" onkeyup="key_up(this.value,event)"> 
    <input name="R1" id="R1" type="text"  size="3" maxlength="1"> 
    <input name="R2" id="R2" type="text"  size="3" maxlength="1"> 
    <input name="R3" id="R3" type="text"  size="3" maxlength="1">
    </body></html>
      

  3.   

    3楼作废,由于拷贝了1楼代码,忘记改函数名了,汗~
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>新建网页 1</title>
    <script>
    function window_onload(){
        $("R0").focus();
    }
    function $(id){
        return document.getElementById(id);
    }
    function key_up(s,e){
        if(e.keyCode==13){//判断回车
            if(s=="1"){$("R1").focus();}
            else if(s=="2"){$("R2").focus();}            
            else if(s=="3"){$("R3").focus();}
        }
    }
    </script>
    </head><body onload="window_onload()">
    <input name="R0" id="R0" type="text"  size="3" maxlength="1" onkeyup="key_up(this.value,event)"> 
    <input name="R1" id="R1" type="text"  size="3" maxlength="1"> 
    <input name="R2" id="R2" type="text"  size="3" maxlength="1"> 
    <input name="R3" id="R3" type="text"  size="3" maxlength="1">
    </body></html>
      

  4.   

    <!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>无标题页</title>
        <script type="text/javascript">
        var $=function(id)
        {
          return document.getElementById(id);
        }
        function ShowTar()
        {
          $("R0").focus();
        }
        function key_down(Target)
        {
          if(event.keyCode==13)
          { 
           if(Target=="R0")
           {
             $("R1").focus();
           }
           else if(Target=="R1")
           {
              $("R2").focus();
           }
           else if(Target=="R2")
           {
              $("R3").focus();
           }
          }
        }
        </script>
    </head>
    <body onload="ShowTar()">
    <input name="R0" id="R0" type="text"  size="3" maxlength="1" onkeydown="key_down(id)"/> 
    <input name="R1" id="R1" type="text"  size="3" maxlength="1" onkeydown="key_down(id)"/> 
    <input name="R2" id="R2" type="text"  size="3" maxlength="1" onkeydown="key_down(id)"/> 
    <input name="R3" id="R3" type="text"  size="3" maxlength="1" onkeydown="key_down(id)"/></body>
    </html>