Http://www.softwhy.com/forum.php? Mod = viewthread & amp; tid = 9287,

Source: Internet
Author: User

Http://www.softwhy.com/forum.php? Mod = viewthread & tid = 9287,

How does jQuery set form elements to read-only or unavailable:
In practical applications, sometimes you need to dynamically set the form element to read-only or unavailable based on the actual situation. This problem is of course very simple. This chapter is suitable for beginners, it is negligible for experienced users. The following describes how to implement this function through code instances.
The code example is as follows:

<! DOCTYPE html> 

The above code can set the two text boxes to read-only and unavailable. However, there is not only one way to achieve this effect. The following is a summary:
Set to read-only or unavailable:
Method 1:

$("#top").attr("readonly","readonly");$("#bottom").attr("disabled","disabled");

Method 2:

$("#top").attr("readonly",true);$("#bottom").attr("disabled",true);

Cancel read-only or unavailable:
Method 1:

$("#top").attr("readonly",false);$("#bottom").attr("disabled",false);

Method 2:

$("#top").attr("readonly",false);$("#bottom").attr("disabled",false);

To determine whether it is selected or set to unavailable:

$("#top").prop("readonly");$("#bottom").prop("disabled");

We recommend that you use the prop () function. For more information, see the difference between the prop () method and the attr () method.

The original address is: http://www.softwhy.com/forum.php? Mod = viewthread & tid = 9287.

For more information, see: http://www.softwhy.com/jquery/

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.