document.getElementById('XXX').focus();

解决方案 »

  1.   


    window.onload = function()
    {
    document.getElementById("id").focus();
    }
      

  2.   

    我是按照下面写的,结果在eclipse中可以获得焦点,但是一用浏览器打开就不行了,不管是用IE还是谷歌或者其他的浏览器,这是什么原因呢?<form>
    用户名:<input name="name" ><br>
    密码: <input  name="password" type="password">
         <input name="submit" type="submit" value="提交">
    </form>
    <script type="text/javascript">
         window.onload = function()
         {
          document.getElementById("name").focus();
         }
    </script>
      

  3.   

    document.getElementById<input name="name"  id='name'><br>