Home >Web Front-end >JS Tutorial >How to set the area to be inoperable in jquery
How to set the area inoperable in jquery: first create a code sample file; then set the page element to be non-editable by applying the disabled and readonly attributes to the element.
The operating environment of this tutorial: windows7 system, jquery1.10.0 version, Dell G3 computer.
Recommendation: jquery video tutorial
Jquery’s API provides methods for applying disabled and readonly attributes to elements. These two attribute methods can make elements inoperable. Let's take a look at how jQuery sets the area to be inoperable.
jquery sets page elements to be non-clickable, non-editable, and read-only:
$("input").attr('readonly', true); $("textarea").attr('readonly', true); $(':radio').attr('disabled', true); $(':checkbox').attr('disabled', true); $(':button').attr('disabled', true); $('a').removeAttr('onclick'); $('select').attr('disabled', true);
Example:
$('form').find('input,textarea,select').not('.btn btn-primary,.back').attr('disabled','disabled');
The above code means to change the style of the form to . The elements of btn btn-primary and .back are all set to read-only.
If the page also has an a tag, you can use the $('a').removeAttr('onclick'); listed above to remove the click event of the a tag.
attr() method sets or returns the attributes and values of the selected element.
When this method is used to return an attribute value, the value of the first matching element is returned.
When this method is used to set attribute values, one or more attribute/value pairs are set for the matching element.
The above is the detailed content of How to set the area to be inoperable in jquery. For more information, please follow other related articles on the PHP Chinese website!