Home > Web Front-end > JS Tutorial > body text

How jQuery determines whether an input is disabled

coldplay.xixi
Release: 2020-11-30 11:35:10
Original
3034 people have browsed it

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>
Copy after login

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",“”);        //可编辑
Copy after login

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");     //可编辑
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!