1. 程式人生 > >Asp.net中, Javascript 操作textBox的屬性應用()

Asp.net中, Javascript 操作textBox的屬性應用()

console val 屬性 ria asp bits vertica lin disabled

If a control is disabled it cannot be edited and its content is excluded when the form is submitted.If a control is readonly it cannot be edited, but its content (if any) is still included with the submission.

即: 當ReadOnly=True時,控件ID在前後天仍可以被查詢到。而當Diabled=True, 或者當Visible=True時,一旦Form被前臺遞交,其ID將不再被前臺識別;此時,TextBox空間和Label空間功能將相差無幾。

實際代碼中,由於Label控件的局限性,很多時候借用TextBox控件,但顯示時何Label一樣。如下代碼

<asp:Textbox ID="lblComment" runat="server" Width="200" ReadOnly="true" Visible="True" BorderWidth="0px" BorderStyle="None" >

</asp:Textbox>

簡單分析如下: 將 BorderWidth 設置為0,BorderStyle設置為None,其顯示將和Label一樣。Readonly設置為True,內部文字將不會被編輯。

下文增加一個js的控件屬性修改function

function ShowComment(selectedcontrol, control1, control2, judgePara, width1, width2, msg) { if (control1 != null && control2 != null) { if (selectedcontrol.value == judgePara) { control1.value = msg; control2.style.width = width1; } else { control1.value = ""; control2.style.width = width2; } }}

其調用方法

<aspx:Textbox ID="txtCodeKubun" runat="server" ImeMode="Disabled" Width="30px" TabIndex="1" onFocus="OnGreen(‘txtCodeKubun‘)" onkeyup="TxtChange(this,document.getElementById(‘cmbCodeKubun‘))" onblur="TxtChangeBlur(this,document.getElementById(‘cmbCodeKubun‘))" onchange="ShowComment(this,document.getElementById(‘lblComment‘), document.getElementById(‘txtComment‘), ‘013‘,‘185px‘,‘400px‘,‘*Comment: how are you!‘)" MaxLength="3" LengthAsBytes="true"> </aspx:Textbox>

Asp.net中, Javascript 操作textBox的屬性應用()