Jquery changes the Boolean state of disabled in three ways
- 2020-03-30 00:51:58
- OfStack
The first is to change the Boolean state of disabled. The specific code and explanation are as follows:
The code is as follows:
$("button:eq(2)").click(function(){
var text2=$("input:text:eq(2)");
if(text2.attr("disabled")==false){
//Set the disabled property of the third text input box to true by setting the Boolean property of disabled
text2.attr("disabled",true);
}else{
//The disabled property is removed by setting the third text input field, the disabled property, to false
text2.attr("disabled",false);
}
});
The second: remove the disabled property. The specific code and explanation are as follows:
The code is as follows:
$("button:eq(1)").click(function(){
var text2=$("input:text:eq(1)");
if(text2.attr("disabled")==false){
//Set the value of disabled to disabled for the second text input box
text2.attr("disabled","disabled");
}else{
//Remove the disable property from the second text field by removing it
text2.removeAttr("disabled");
}
});
The third is to change the value of disabled. The specific code and explanation are as follows:
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 value of disabled to disabled for the first text input box
text1.attr("disabled","disabled");
}else{
//Clear the disabled property from the first text field by overriding it
text1.attr("disabled","");
}
});
The complete sample code is as follows (the test passed) :
The code is as follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head> <script src="jquery I'm just going to introduce the path "></script>
<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
//Set the value of disabled to disabled for the first text input box
text1.attr("disabled", "disabled");
} else {
//Clear the disabled property from the first text field by overriding it
text1.attr("disabled", "");
}
});
$("button:eq(1)").click(function () {
var text2 = $("input:text:eq(1)");
if (text2.attr("disabled") == false) {
//Set the value of disabled to disabled for the second text input box
text2.attr("disabled", "disabled");
} else {
//Remove the disable property from the second text field by removing it
text2.removeAttr("disabled");
}
});
$("button:eq(2)").click(function () {
var text2 = $("input:text:eq(2)");
if (text2.attr("disabled") == false) {
//Set the disabled property of the third text input box to true by setting the Boolean property of disabled
text2.attr("disabled", true);
} else {
//The disabled property is removed by setting the third text input field, the disabled property, to false
text2.attr("disabled", false);
}
});
});
// --></script>
</head>
<body>
<button>disabledNull</button>
<input type="text" value="input something into me!" size="40"/>
<br/>
<button>disabledRemove</button>
<input type="text" value="input something into me!" size="40"/>
<br/>
<button>disabledState</button>
<input type="text" value="input something into me!" size="40"/>
</body>
</html>