Home  >  Article  >  Web Front-end  >  How to set the area to be inoperable in jquery

How to set the area to be inoperable in jquery

藏色散人
藏色散人Original
2020-12-25 09:30:241643browse

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.

How to set the area to be inoperable in jquery

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn