Three ways to change the Boolean state of disabled in jquery _jquery

Source: Internet
Author: User

First: Change the Boolean state of the disabled, the specific code and interpretation as follows:

The code is as follows:

Copy Code code as follows:

$ ("Button:eq (2)"). Click (function () {
var text2=$ ("Input:text:eq (2)");
if (text2.attr ("disabled") ==false) {
Set the third text input box disabled property to True by setting the Boolean property of disabled
Text2.attr ("Disabled", true);
}else{
Remove the disabled property by placing the third text input box disabled property to False
Text2.attr ("Disabled", false);
}
});

The second: Remove the disabled attribute, the specific code and explain as follows:

The code is as follows:
Copy Code code as follows:

$ ("Button:eq (1)"). Click (function () {
var text2=$ ("Input:text:eq (1)");
if (text2.attr ("disabled") ==false) {
Sets the second text input box to disabled by setting the value of the disabled
Text2.attr ("Disabled", "disabled");
}else{
Remove the Disable property of the second text input box by removing it
Text2.removeattr ("Disabled");
}
});

The third: Change the value of the disabled, the specific code and explanation as follows:

The code is as follows:
Copy Code code as follows:

$ ("Button:eq (0)"). Click (function () {
var text1=$ ("Input:text:eq (0)");
if (text1.attr ("disabled") = = "") {
or text1.attr ("disabled") ==false
Sets the first text input box to disabled by setting the value of the disabled
Text1.attr ("Disabled", "disabled");
}else{
Clears the disabled property in the first text input box by overriding
Text1.attr ("Disabled", "");
}
});

The complete sample code is as follows (tested through):
The code is as follows:
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<script type= "Text/javascript" ><!--
$ (document). Ready (function () {
$ ("Button:eq (0)"). Click (function () {
var Text1 = $ ("input:text:eq (0)");
if (text1.attr ("disabled") = = "") {
or text1.attr ("disabled") ==false
Sets the first text input box to disabled by setting the value of the disabled
Text1.attr ("Disabled", "disabled");
} else {
Clears the disabled property in the first text input box by overriding
Text1.attr ("Disabled", "");
}
});
$ ("Button:eq (1)"). Click (function () {
var Text2 = $ ("Input:text:eq (1)");
if (text2.attr ("disabled") = = False) {
Sets the second text input box to disabled by setting the value of the disabled
Text2.attr ("Disabled", "disabled");
} else {
Remove the Disable property of the second text input box by removing it
Text2.removeattr ("Disabled");
}
});
$ ("Button:eq (2)"). Click (function () {
var Text2 = $ ("Input:text:eq (2)");
if (text2.attr ("disabled") = = False) {
Set the third text input box disabled property to True by setting the Boolean property of disabled
Text2.attr ("Disabled", true);
} else {
Remove the disabled property by placing the third text input box disabled property to False
Text2.attr ("Disabled", false);
}
});
});
--></script>
<body>
<button>disabledNull</button>
<input type= "text" value= "input something into me!" size= "/>"
<br/>
<button>disabledRemove</button>
<input type= "text" value= "input something into me!" size= "/>"
<br/>
<button>disabledState</button>
<input type= "text" value= "input something into me!" size= "/>"
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.