Home  >  Article  >  Web Front-end  >  How to make the id element uneditable in jquery

How to make the id element uneditable in jquery

青灯夜游
青灯夜游Original
2022-06-10 16:31:291719browse

Jquery method to make the id element uneditable: 1. Get the specified element through the id attribute value, the syntax "$("#id value")" will return a jquery object containing the specified element; 2. Use Attr() sets the disabled attribute to the obtained element object to make the element uneditable. The syntax is "id element object.attr("disabled", "disabled");".

How to make the id element uneditable in jquery

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

jquery method to make the id element uneditable

1. Get the specified element through the id attribute value

$("#id值")

will return a jquery object containing the specified element

2. Make the obtained element object uneditable

Just use the attr() method to add the element Set the disabled attribute to make the element uneditable.

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<script src="./js/jquery-3.6.0.min.js"></script>
		<script type="text/javascript">
			$(document).ready(function() {
				$("#box").css("border","1px solid red");
				$("button").click(function() {
					$("#box").attr("disabled", "disabled");
					// $("textarea").attr("disabled","true");
				});
			});
		</script>
	</head>

	<body>
		<textarea></textarea><br><br>
		<textarea id="box">id="box"元素</textarea><br><br>
		<button>让id="box"元素不可编辑</button>
	</body>

</html>

How to make the id element uneditable in jquery

[Recommended learning: jQuery video tutorial, web front-end video

The above is the detailed content of How to make the id element uneditable in jquery. 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