Home  >  Article  >  Web Front-end  >  How to batch set attributes readonly and disabled in jquery_jquery

How to batch set attributes readonly and disabled in jquery_jquery

WBOY
WBOYOriginal
2016-05-16 17:02:291748browse

Jquery's API provides methods for applying disabled and readonly attributes to elements, which are recorded here. As follows:
1.readonly

Copy code The code is as follows:

 $('input ').attr("readonly","readonly")//Set the input element to readonly
 $('input').removeAttr("readonly");//Remove the readonly attribute of the input element

  if($('input').attr("readonly")==true)//Determine whether the input element has the readonly attribute set

Methods for setting the readonly attribute and canceling the readonly attribute for the element There are also the following two types:
 $('input').attr("readonly",true)//Set the input element to readonly
 $('input').attr("readonly",false) //Remove the readonly attribute of the input element

$('input').attr("readonly", "readonly") // Set the input element to readonly
$('input').attr ("readonly","")//Remove the readonly attribute of the input element

2.disabled

Copy code The code is as follows:

 $('input').attr("disabled","disabled")//Set the input element to disabled
 $(' input').removeAttr("disabled");//Remove the disabled attribute of the input element

 if($('input').attr("disabled")==true)//Determine whether the input element is The disabled attribute has been set

There are two other ways to set the disabled attribute and cancel the disabled attribute for an element:
Copy code The code is as follows:

 $('input').attr("disabled",true)//Set the input element to disabled
 $('input ').attr("disabled",false)//Remove the disabled attribute of the input element

Copy code The code is as follows:

 $('input').attr("disabled","disabled")//Set the input element to disabled
 $('input').attr( "disabled","")//Remove the disabled attribute of the input element
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