Home  >  Article  >  Web Front-end  >  How jQuery determines whether an input is disabled

How jQuery determines whether an input is disabled

coldplay.xixi
coldplay.xixiOriginal
2020-11-17 10:16:222983browse

How jQuery determines whether the input is disabled: 1. Use the function [is(":disabled")] to determine; 2. Use the function [prop("disabled")] to determine; 3. Use the function [attr ("disabled")】judgment.

How jQuery determines whether an input is disabled

The operating environment of this tutorial: windows10 system, jquery2.2.4, this article is applicable to all brands of computers.

Recommendation: "jquery video tutorial"

JQuery method to determine whether input is disabled:

Judge whether input is disabled Disabled, available methods are:

● is(":disabled")

● prop("disabled")

● attr("disabled")

<script src="jquery.min.js"></script>
 <br/><input type="text" id="first" disabled>first
 <br/><input type="text" id="second" disabled <br/><input type="text" id="third">third
 <script>
     var v1, v2, v3;
     v1 = $("#first").is(":disabled");  // true / false
     v2 = $("#first").prop("disabled"); // true / false
     v3 = $("#first").attr("disabled"); // disabled / undefined
     console.log(v1);
     console.log(v2);
     console.log(v3);
     v1 = $("#second").is(":disabled");  // true / false
     v2 = $("#second").prop("disabled"); // true / false
     v3 = $("#second").attr("disabled"); // disabled / undefined
     console.log(v1);
     console.log(v2);
     console.log(v3);
     v1 = $("#third").is(":disabled");  // true / false
     v2 = $("#third").prop("disabled"); // true / false
     v3 = $("#third").attr("disabled"); // disabled / undefined
     console.log(v1);
     console.log(v2);
     console.log(v3);
 </script>

Page results:

How jQuery determines whether an input is disabled

Console output:

How jQuery determines whether an input is disabled

Use prop to set disable and undisable:

$("#first").prop("disabled",true);      //禁用
$("#first").prop("disabled",false);     //可编辑
$("#first").prop("disabled",“disabled”);//禁用
$("#first").prop("disabled",“”);        //可编辑

Use attribute settings to disable and undisable:

$("#first").attr("disabled",true);      //禁用
$("#first").attr("disabled",false);     //可编辑
$("#first").attr("disabled","disabled");//禁用
$("#first").attr("disabled","");        //禁用
$("#first").removeAttr("disabled");     //可编辑

Related free learning recommendations: JavaScript (video)

The above is the detailed content of How jQuery determines whether an input is disabled. For more information, please follow other related articles on the PHP Chinese website!

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