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/