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

How to set jquery elements to be unusable

coldplay.xixi
Release: 2021-01-13 17:11:20
Original
1598 people have browsed it

Methods to set jquery elements that cannot be used: Use the [.prop()] method to adjust the properties of the element. After setting the button to disabled, the button will turn gray and cannot be clicked. The code is [$(" button").prop("disabled", true);].

How to set jquery elements to be unusable

The operating environment of this tutorial: windows7 system, jquery3.2.1 version, Dell G3 computer.

Methods that cannot be used to set jquery elements:

We can use jQuery to change non-CSS attributes of HTML elements. For example, you can disable buttons.

When you set the button to disabled, the button will turn gray and cannot be clicked.

jQuery has a .prop() method that allows you to adjust the properties of elements.

The following code shows how to disable all buttons:

$("button").prop("disabled", true);
Copy after login

Example: Let the target1 button be disabled

<script>
$(document).ready(function() {
$("#target1").css("color", "red");
$("#target1").prop("disabled", true);
});
</script>
<!-- Only change code above this line. -->
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<h4>#left-well</h4>
<div class="well" id="left-well">
<button class="btn btn-default target" id="target1">#target1</button>
<button class="btn btn-default target" id="target2">#target2</button>
<button class="btn btn-default target" id="target3">#target3</button>
</div>
</div>
<div class="col-xs-6">
<h4>#right-well</h4>
<div class="well" id="right-well">
<button class="btn btn-default target" id="target4">#target4</button>
<button class="btn btn-default target" id="target5">#target5</button>
<button class="btn btn-default target" id="target6">#target6</button>
</div>
</div>
</div>
</div>
Copy after login

Related free learning recommendations: javascript( video)

The above is the detailed content of How to set jquery elements to be unusable. 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!