<script>
window.onload=function()
{
 document.form1.textfield.value="xxxx"
}
</script>
<form name="form1">
<input type="text" name="textfield" readonly="true">
</form>

解决方案 »

  1.   


    <input type="text" id="a" readonly/>
    <script>
        document.getElementById("a").value = "abcde";
    </script>
      

  2.   

     我把代码发给大家看看
    <td >
    <asp:TextBox ID="txtEtno" ReadOnly="true" onfocus="this.select();" runat="server"  MaxLength="6" CssClass="txtBoxInputDis" 
    onkeyup="OnDeleteKeyDown()" onkeypress="OnDeleteKeyDown()" TabIndex="6"></asp:TextBox>
    </td>function OnDeleteKeyDown()
    {
        if (event.keyCode == 9)
        {
            return true;
        }
        if (event.keyCode == 46 || event.keyCode == 8)
        {
            document.getElementById("ctl00_Main_txtEtno").value = "";
            return true;
        }
        else 
        {
            event.returnValue = false;
        }     
    }
      

  3.   

    document.getElementById("ctl00_Main_txtEtno").value = ""; 
    是得到TextBox ID="txtEtno" ID
      

  4.   

    我的目的是
    让文本框得到焦点的时候就全选中,按Backspace和Delete键就全删除
    按其他键无效
    本来去掉ReadOnly="true"已经实现了
    但切换输入发之后其他键又可以输入了,就屏蔽不掉了。 麻烦大侠帮帮忙
      

  5.   

    document.getElementById("ctl00_Main_txtEtno").value = ""; 
    改成
    document.getElementById("<%=txtEtno.ClientID%>").value = ""; 
      

  6.   

    另外设定readonly后鼠标点击输入框是不会触发onmousedown onmouseup onkeypress等事件的
      

  7.   

    if (event.keyCode == 46  ¦ ¦ event.keyCode == 8) 
        { 
            document.getElementById("ctl00_Main_txtEtno").value = ""; 
            return true; 
        } 
    我把上面的改成下面的
    是有值的,当新增在后台取到的还是原来的值
    if (event.keyCode == 46  ¦ ¦ event.keyCode == 8) 
        { 
            document.getElementById("ctl00_Main_txtEtno").value = ""; 
            alert(document.getElementById("ctl00_Main_txtEtno").value);
            return true; 
        } 
      

  8.   

    另外设定readonly后鼠标点击输入框是不会触发onmousedown onmouseup onkeypress等事件的
    这段打错是设定readonly后鼠标单击在输入框内是不会得到焦点的,所以无法触发onkey系列事件
      

  9.   

    按tab取得焦点是会触发,但按鼠标取不到焦点吧
      

  10.   

    用alert()调试一下这里    if (event.keyCode == 46  ¦ ¦ event.keyCode == 8) 
        { 
            alert(document.getElementById("ctl00_Main_txtEtno").value );
            document.getElementById("ctl00_Main_txtEtno").value = ""; 
            return true; 
        } 看取到document.getElementById("ctl00_Main_txtEtno").value 值没有?
      

  11.   

    对,没有焦点,但是可以触发key事件~~~
      

  12.   

    document.getElementById("ctl00_Main_txtEtno").value 值的值是空,和设置的一样效果,
    就是点击保存事件,已经Page_Load就变原来的值了
    并且检查过没有重新赋值过
      

  13.   

    就是点击保存事件,一进Page_Load就变原来的值了
      

  14.   

    是不是.net机制里面
    js对readonly属性的控件赋值是没有记忆功能的?
      

  15.   

    你的意思就是说....用js改变的value...和提交到服务器上的值不一致?
      

  16.   

    是的
    readonly去掉就一样了
      

  17.   

    那你取值时,就用Request.Form
    不要直接读取ReadOnly的TextBox
      

  18.   

    请问一下这个怎么取值Request.Form 
      

  19.   

    ReadOnly的TextBox的值只能用Request.Form接受值
      

  20.   

    Request.Form  我直接点出来的key怎么都是int型的 啊
    控件id是string型的啊 
    你用TextBox的Id是aaa的给小弟举个例子
    谢谢了
      

  21.   

    你生成页面的时候查看他的Nam属性值....Request.Form["Name属性的值"]就可以再服务器端获得他的String类型的值了...如果我没有猜错的话是
    你是写在一个数据绑定控件上的...
    应该是:
    Request.Form["ctl00_Main_txtEtno"]
      

  22.   

    <asp:TextBox ID="txtEtno" ReadOnly="true" onfocus="this.select();" runat="server"  MaxLength="6" CssClass="txtBoxInputDis"  
    onkeyup="OnDeleteKeyDown()" onkeypress="OnDeleteKeyDown()" TabIndex="6"> </asp:TextBox>Response.Write(Request.Form["txtEtno"]);
      

  23.   

    [align=left]if (Request.Form["ctl00_Main_txtEtno"] != null)
                [align=left]{
                    string ss = Request.Form["ctl00_Main_txtEtno"].ToString();
                }
                if (Request.Form["txtEtno"] != null)
                {
                    string ssww = Request.Form["txtEtno"].ToString();
                }
                if (Request["ctl00_Main_txtEtno"] != null)
                {
                    string ss = Request.Form["ctl00_Main_txtEtno"].ToString();
                }
                if (Request["txtEtno"] != null)
                {
                    string ssww = Request.Form["txtEtno"].ToString();
                }[/align][/align]
    全是null值
      

  24.   

     我换一种方法解决了
    但区分不了delete键和小键盘上的delete键啊
    请问怎么样区分delete键和小键盘上的delete键啊
      

  25.   

    是readonly还是Enable=false的?这个要分清楚,。详细讲解参加
    http://blog.csdn.net/net_lover/archive/2006/09/25/1282127.aspx
      

  26.   

    可以用这样设置只读属性在pagelode里可以设置textbox.Attribute("ReadOnly","ReadOnly"),好想直接设置只读是取不到值还是付不上值具体忘了!
      

  27.   

     问题已经解决了,主要是参考tt03030576和youbl 的方法实现的。
    我是这样取到值的
    if (Request.Form["ctl00$Main$txtEtno"] != null)
    {
        txtEtno.Text = Request.Form["ctl00$Main$txtEtno"].ToString();
    }
    ctl00$Main$这部分是继承了框架页面的
    现在结贴了。
      

  28.   


    是的,readonly的只能那样取值,这是.net安全性的一种措施。
      

  29.   

    不能用服务器控件的ReadOnly=“true”,这样当然得不到,服务器端会认为这个控件只读,对属性的更改也无效应该在Page_Load中txtEtno.Attributes.Add("readonly", "readonly");设置
      

  30.   

    asp.net 2.0中的viewstate会对控件控制,对只读的控件回发到服务器会和viewstate对比,用户通过客户端脚本修改的数据会无效,禁用viewstate试试 相关资料http://www.cnblogs.com/wildfish/archive/2007/03/06/665168.aspx
      

  31.   

    asp.net中,设置了控件的readonly属性,你在前台用JS更改然后再在后台取值是不会变的,简单的解决方案:page_load()
    {
    yourTextBox.Attributes.Add("readonly","true");
    }代码写得不规范,但就这个意思,这样整了之后你在前台更改后就生效