<input class="textBox" type="text" id="aaaa" name="aaaa"  
  size="25" maxlength="64" value="ddddddddddddddd"/> 
在打开窗口时,选中文本框中的“请输入用户名”,这样用户就可以直接输入了,
onfocus= "this.select() "这样是不行的,
但我试过onload= "this.select() "又不好用,
大虾们帮帮忙

解决方案 »

  1.   

    onload="selectText()"
    绝对可以
      

  2.   

    function G(s){return document.getElementById(s)}
    window.onload=function(){
      setTimeout(function(){
        G('aaaa').select();
      },100);
    }
      

  3.   

    <script>
    function selectText(){
    var o=document.getElementById("aaa");
    o.focus();
    o.select();
    }
    window.onload=selectText;
    </script>
    <input type="text" name="aaa" id="aaa" value="hello world">
      

  4.   

    最简单的方法将这段代码放到页面底下,要比 aaaa 这个INPUT的位置靠下,比这个靠前了会提示找不到aaa的<script>
    document.getElementById("aaa").focus();
    </script>这样就可以了
      

  5.   

    发个用JQuery的例子<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Set textbox on focus after page load</title>
    <script src="../../lib/jquery/jquery-1.4.2.js"></script>
    <script>
        $(document).ready(function(){
            $('#aaa').focus();
        });
    </script>
    </head>
    <body>
    aaa: <input type="text" name="aaa" id="aaa" value="aaa"><br/>
    bbb: <input type="text" name="bbb" id="bbb" value="bbb"><br/>
    </body>
    </html>