JS Dynamic Control read-only property of the input box

Source: Internet
Author: User

Set the read-only property of the input box as readonly= "true" it's killing me. The following is true:

<class= "Inuptxt ac_input"  type= "text"  ID= "tt"  name= "tt"  readonly= "readonly">

Read-only property of the input box: readonly

When added as read-only in the page, you can add readonly= "readonly" directly in input, but if you want to change it by clicking the button, you need to do so via JS (or jquery).

The most recent use of this, finally found that the previous time to write this JS control why always so depressed, originally, JS in the ReadOnly, disabled and other property settings, there is a small bug (at least I think): First,  document.getElementById ("id"). readonly = "true"; Set input to read-only, but when passed document.getElementById ("id"). readonly= "false" to remove the read-only attribute, there is no effect, at this time, you need to false outside the quotation marks to remove the JS statement to work properly.

Report:

1. jquery set and Cancel read-only properties by ID property

Set read-only: $ ("#id"). attr ("ReadOnly", "true");

Cancel Read-only: $ ("#id"). attr ("ReadOnly", false);//note false without quotation marks!!!

2. jquery bulk Set and cancel read-only properties

/* in the div with ID sa, all input boxes */

Set read-only: $ ("#sa input"). attr ("ReadOnly", "true");

Cancel Read-only: $ ("#sa input"). attr ("ReadOnly", false);

Thank you: 39154615

The following HelloWorld are written:

<Script>    //Initialize the Voucherno text box$ (document). Ready (function () {        varVoucherno= $("#voucherNo"); Voucherno.attr ("readOnly","true"); Voucherno.css ('Background-color','#DEDEDE');    }); //Voucherno Style    functionChangestyle () {varPaymentmode= $("#paymentMode"). Val (); //$ ("#tt"). CSS (' Background-color ', ' #DEDEDE ');//no problem.        varVoucherno= $("#voucherNo"); if(Paymentmode!='Geneva'){//no problem .voucherno.attr ("readOnly","true"); Voucherno.css ('Background-color','#DEDEDE'); } Else{voucherno.attr ("readOnly",false); Voucherno.css ('Background-color','#FFFFFF'); }    }</Script>

JS Dynamic Control read-only property of the input box

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.