Three ways for jquery to change the Boolean state of disabled

Source: Internet
Author: User

  Change the Boolean state of disabled, the following for you to introduce three kinds of relatively good methods, you can refer to the following

First: Change the Boolean state of the disabled, the specific code and interpretation as follows:    code as follows:    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  text2.attr ("disabled", true) by setting the Boolean property of disabled to; }else{ // Remove the Disabled property   text2.attr ("disabled", false); } }) by placing the third text input box disabled property to False;    The second: Remove the disabled attribute, the specific code and explain the following:    code as follows:  code as follows: $ ("Button:eq (1)"). Click (function () {  var text2=$ (" Input:text:eq (1) ");  if (text2.attr (" disabled ") ==false) { //Set the second text input box to disabled by setting the value of disabled  Text2.attr ("Disabled", "disabled"); }else{ //Removes the Disable property of the second text input box by removing   text2.removeattr (" Disabled "); } });    A third: Change the value of the disabled, the specific code and explain the following:    code as follows:  code 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  text1.attr ("Disabled", "disabled"); }else{ //By setting the value of disabled. The Disabled property in the first text input box is cleared out by overriding the   text1.attr ("Disabled", ""); } });    Complete sample code is as follows (tested through):   Code as follows:  code as follows: <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >  <html >  <head> <script src= "The Path of jquery is introduced" ></script>  <script type= "Text/javascript" ><!--  $ (document). Ready (function () {  $ ("button:eq (0)"). Click (function () {  var Text1 = $ ("Input : Text:eq (0) ");  if (text1.attr (" disabled ") =" ") { //text1.attr (" disabled ") ==false // Sets the first text input box to disabled  text1.attr ("Disabled", "Disabled"); } else by setting the value of disabled { // Clears the disabled property in the first text input box by overriding the   text1.attr ("Disabled", ""); } });  $ ("Button:eq (1)"). Click (function () {  var text2 = $ ("Input:text:eq (1)");  if (tExt2.attr ("disabled") = = False) { //Set the second text input box to disabled  text2.attr ("Disabled", "disabled" by setting the value of disabled) "); } else { //Remove the Disable property of the second text input box by removing   text2.removeattr (" disabled "); } });  $ ("Button:eq (2)"). Click (function () {  var text2 = $ ("Input:text:eq (2)");  if (text2.attr ("disabled") = = False ) { //sets the third text input box disabled property to true  text2.attr ("disabled", True); } by setting the Boolean property of the disabled {   Remove the Disabled property   text2.attr ("disabled", false); } });  by disabled the third text input box property to False ; //--></script>  </head>  <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= "a"/>  />  <button>disabledState</button>  <iNput type= "text" value= "input something into me!" size= ""/>  </body>  </html>    & nbsp
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.