<input class="textBox" type="text" id="aaaa" name="aaaa" 
                   size="25" maxlength="64"/>在输入用户名时,想要将原来在text中的所有文本设置为选中,用JS怎么实现,求教

解决方案 »

  1.   


    <input id="TBselect" name=TBsou size=25 onMouseOver="this.focus()" onBlur="if (this.value =='') this.value='请填入姓名'" onFocus="this.select()" onClick="if (this.value=='请填入姓名') this.value=''"type="text"  value="请填入姓名"/>
      

  2.   

    <input class="textBox" type="text" id="aaaa" name="aaaa"  
      size="25" maxlength="64" onfocus= "this.select() "/>
      

  3.   

    在打开该窗口时,就选中其中的文本,焦点位于文本框中,不是onfocus,我试过onload也不行,高手们,帮帮忙
      

  4.   

    function selectText() {
    var Textbox1 = document.getElementById(“text”);
    Textbox1.focus();
    Textbox1.select();
    }
      

  5.   

    <input type="text" onfocus="this.select();" name="dd" value="请输入">
    <script>
    document.getElementById("dd").select();
    </script>
    像这样就可以解决你的问题了。
      

  6.   

    用jquery试试吧!应该还是可以的!不需要onload!
      

  7.   

    jquery应该怎么写呀,可以给我一个实例吗?谢谢
      

  8.   

      在onload函数里面加一个设置焦点的函数试试
      

  9.   

    //导入JQuery框架,需要联网才好用
    <script language="javascript" src="src=" http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
    <script language="javascript">
    $(function(){
    //此代码的意思是获取第一个文本,如果你要获取的文本不是第一个,那么依次往上加就可以了
    $(":text:eq(0)").select();})
    </script>
      

  10.   

    错了,多复制了个src,把src="删掉,不好意思
      

  11.   

    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script type="text/javascript">
    function lo(){
    document.getElementById("aaa").select();
    }
    </script>
    </head><body onload="lo()">
    <input type="text" id="aaa" value="test"  />
    </body>
    </html>复制查看即可
      

  12.   

    <html>
    <head>
    <script type="text/javascript">
      window.onload = function(){
        var oInput = document.getElementsByTagName("input")[0];
    oInput.focus();
    oInput.select();
      }
    </script>
    </head>
    <body>
    <input type="text" name="username" value="check"/>
    </body>
    </html>
      

  13.   

    页面载入load函数里让文本框获得焦点 textbox1.focus(),然后在 textbox1.select()选中话说这种知识点性质的问题你自己百度下,还比在论坛里来问更快找到答案
      

  14.   


    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Email.WebForm1" %><!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 runat="server">
        <title></title>    <script src="jquery/jquery-1.4.2.min.js" type="text/javascript"></script>
        
        <script>
            $(document).ready(function() {
              $("#TextBox1").focus();
                   });    </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        </div>
        </form>
    </body>
    </html>
    我这是用jquery实现的,记住先下载jquery-1.4.2.min.js文件,jquery官网有
    <script src="jquery/jquery-1.4.2.min.js" type="text/javascript"></script>
    这是引用地址
      

  15.   

    <body onload="default_date();">function default_date(){
    var today;
    today = new Date();
    var yy = today.getYear();
    if(yy<1900) yy = yy+1900;
    var MM = today.getMonth()+1;
    if(MM<10) MM = '0' + MM;
    var dd = today.getDate();
    if(dd<10) dd = '0' + dd;
    str = yy + "-" + MM + "-" + dd;
    textobj=document.getElementById("t5");
    textobj.value=str;
    textobj.select();
    }