Home > Web Front-end > JS Tutorial > How to add disable attribute to elements in jquery

How to add disable attribute to elements in jquery

青灯夜游
Release: 2021-11-19 12:20:23
Original
5681 people have browsed it

In jquery, you can use the attr() method to add the disable attribute to an element, with the syntax "$(selector).attr("disabled",true);" or "$(selector).attr(" disabled","disabled");".

How to add disable attribute to elements in jquery

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

The disabled attribute specifies that the element should be disabled. Disabled elements are neither available nor clickable.

jquery method to add disable attribute to element

attr() method can set the attribute value of the selected element.

There are two ways to add the disable attribute to an element using the attr() method

$(selector).attr("disabled",true);
$(selector).attr("disabled","disabled");
Copy after login

Example:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<script src="js/jquery-1.10.2.min.js"></script>
		<script>
			$(document).ready(function(){
				$("button").click(function(){
					// $("input").attr("disabled",true);
					$("input").attr("disabled","disabled");
				});
			});
		</script>
	</head>
	<body>

		<input type="text" />
		<br><br>
		<button>增加disable属性</button>

	</body>
</html>
Copy after login

How to add disable attribute to elements in jquery

Related video tutorial recommendations: jQuery Tutorial(Video)

The above is the detailed content of How to add disable attribute to elements in jquery. 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