Methods for manipulating valueless attributes such as hidden and disable in jQuery

Source: Internet
Author: User

Generally, some hidden attributes are placed on some form submission pages.

For example, when modifying a record, the id of the record is embedded in the editing window.

On the display interface, you sometimes need to set the input or select box to disable to avoid modification.

Hidden in the following code does not work normally in IE
Copy codeThe Code is as follows:
<Input name = "role_name" id = "role_name" value = "Roy" disabled>
<Input name = "role_id" id = "role_id" hidden value = "3312">

Additional value should be added to standard writing.
Copy codeThe Code is as follows:
<Input name = "role_name" id = "role_name" value = "Roy" disabled = "disabled">
<Input name = "role_id" id = "role_id" hidden = "hidden" value = "3312">

Sometimes we need to edit the above two items on the current page. What should we do?

We can use
Copy codeThe Code is as follows:
$ ("# Role_name"). removeAttr ("disabled ");
$ ("# Role_id"). removeAttr ("hidden ");

Or
Copy codeThe Code is as follows:
$ ("# Role_name"). prop ("disabled", false );
$ ("# Role_id"). prop ("hidden", false );

$ ("# Role_name"). prop () returns a boolean value to check whether the property prop () method is enabled and whether the option is selected in the checked option.

Generally, prop () takes effect only when the write attribute name is used and boolean is used to control the attribute status.

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.