Using jquery to dynamically add or delete attributes

Source: Internet
Author: User

The current project has the following needs:

First look at the figure ^

 

Requirements:

1. When you click Export excel, the text box below cannot be modified if you select export or export without pagination.

2. When you click "export by page", the value in the first text box can be modified, but the value in the second text box cannot be manually modified, but it will change with the input value in the first text box.

 

Implementation:

I will not talk about how to do this page. Let's look at the key points and how to dynamically add attribute values:

Function changeattr () {// onchange event add and remove read-only attributes
VaR radios = Document. Forms [0]. Radio;
For (VAR I = 0; I <radios. length; I ++ ){
If (radios [2]. Checked = true ){
Remattr (); // select the export check box to remove the disabled attribute of the text box.
Break;
} Else {
Addattr ();
Break; // If the selected single-choice button is determined, the loop will jump out.
}
}
}

 

Function remattr (){

$ ("# Sheet"). ATTR ("disabled", false); // remove the disabled attribute

}

 

Function addattr (){

$ ("# Sheet"). ATTR ("disabled", true); // Add the disabled attribute

}

Note: sheet here is the ID value in the first text box. Here we use jquery, But what if Javascript is used?

Document. getelementbyid ("sheet"). Disabled = false;

 

 

 

 

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.