Home  >  Article  >  Web Front-end  >  Three ways to change the boolean state of disabled in jquery_jquery

Three ways to change the boolean state of disabled in jquery_jquery

WBOY
WBOYOriginal
2016-05-16 17:09:231133browse

The first one: change the boolean status of disabled, the specific code and explanation are as follows:

The code is as follows:

Copy code The code is as follows:

$("button:eq(2)").click(function(){
var text2=$("input:text:eq(2 )");
if(text2.attr("disabled")==false){
//Set the disabled attribute of the third text input box to true by setting the boolean attribute of disabled
text2. attr("disabled",true);
}else{
//Remove the disabled attribute by setting the disabled attribute of the third text input box to false
text2.attr("disabled",false ; >


Copy code


The code is as follows:

$("button:eq(1)").click(function() { var text2=$("input:text:eq(1)"); if(text2.attr("disabled")==false){ //By setting the value of disabled Set the second text input box to disabled text2.attr("disabled","disabled"); }else{ //Disable the second text input box by removing it Attribute deletion
text2.removeAttr("disabled");
}
});


The third method: change the value of disabled, the specific code and explanation are as follows:

The code is as follows:




Copy code


The code is as follows:

$("button: eq(0)").click(function(){ var text1=$("input:text:eq(0)"); if(text1.attr("disabled")=="" ){ // Or text1.attr("disabled")==false //Set the first text input box to disabled by setting the value of disabled text1.attr("disabled", "disabled"); }else{
//Clear the disabled attribute in the first text input box by overwriting
text1.attr("disabled","");
}
});


The complete sample code is as follows (tested and passed):
The code is as follows:




Copy Code

The code is as follows:

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