用Checkbox來控制文字框是否為灰色不可編輯,

來源:互聯網
上載者:User

用Checkbox來控制文字框是否為灰色不可編輯,


(1)點擊 CheckBox使得輸入框可以使用,否則為灰色不能使用

<li>            <span class="sample_li_left"> <asp:CheckBox ID="gqsj" runat="server" Checked onclick="doDisabled(this.checked);"/>到期時間:</span>                <span>                   <input id="expireTime" name="expireTime" type="text" class="time_text" onfocus="WdatePicker({dateFmt: 'yyyy-MM-dd',maxDate:'%y-%M-%d'})" runat="server" />                </span>                 </li>

相應的js函數為:
function doDisabled(checked) {if(checked){ $("#expireTime").get(0).disabled = ""; //$("#expireTime").addClass('time_text'); $("#expireTime").css('background','url(../images/time.gif) #ffffdc no-repeat right top');}else{ $("#expireTime").attr('disabled','disabled'); $("#expireTime").css('background','#CCCCCC'); }}


遺留問題為:
//$("#expireTime").addClass('time_text');  與$("#expireTime").css('background','url(../images/time.gif) #ffffdc no-repeat right top');


應該是一樣的,但是後者可以 前者不行。


參考:http://blog.csdn.net/delongcpp/article/details/8171826

將HTML文字框設為不可編輯文字框。

 

方法1: onfocus=this.blur()
<input type="text" name="input1" value="不可編輯文字框" onfocus=this.blur()>

方法2:readonly
<input type="text" name="input1" value="不可編輯文字框" readonly>

<input type="text" name="input1" value="不可編輯文字框" readonly="true">

方法3: disabled
<input type="text" name="input1" value="不可編輯文字框" disabled>

 

讓文字框變灰不可輸入:

<input type="text" name="test" disabled="disabled" style="background:#CCCCCC"/>

不可輸入還可以用上述三種方法

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.