= "TextBox2 new Value"; document.getElementById('<%=TextBox3.ClientID %>').value = "TextBox3 new Value"; } //]]> </script>
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>ASP.NET 2.0中TextBox控件与ReadOnly和Enabled属性</title> </head> <body> <form id="form1" runat="server"> <span>TextBox1 ReadOnly:</span> <asp:TextBox ID="TextBox1" runat="server" ReadOnly="True" Text="TextBox1 Old Value"></asp:TextBox><br /> <span>TextBox2 Enabled:</span> <asp:TextBox ID="TextBox2" runat="server" Enabled="False" Text="TextBox2 Old Value"></asp:TextBox><br /> <span>TextBox3 ReadOnly:</span> <asp:TextBox ID="TextBox3" runat="server" Text="TextBox3 Old Value"></asp:TextBox><br /> <br /> <asp:Button ID="Button2" runat="server" Text="修改新值" OnClientClick="SetNewValue();return false;" /> <asp:Button ID="Button1" runat="server" Text="提交" OnClick="Button1_Click" /> </form> </body> </html>
对于disabled的TextBox,在服务器端不能得到修改的值,如果实在要用这个属性,那之后使用隐藏表单域的方法来实现了。
ReadOnly属性的TextBox在客户端会展现成这样的标记:
<input readonly = "readonly">
Enabled属性的TextBox在客户端会展现成这样的标记: <input disabled="disabled">
按照W3C的规范:http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.12
设置为disabled的input将会有下面的限制:
·不能接收焦点 ·使用tab键时将被跳过 ·可能不是successful的
设置为readonly的input将会有下面的限制:
·可以接收焦点但不能被修改 ·可以使用tab键进行导航 ·可能是successful的
只有successful的表单元素才是有效数据,也即是可以进行提交。disabled和readonly的文本输入框只能通过脚本进行修改value属性。
http://dev.yesky.com/msdn/167/3003167.shtml 上一页 [1] [2] |