Home  >  Article  >  Web Front-end  >  How to make the text box uneditable in jquery

How to make the text box uneditable in jquery

青灯夜游
青灯夜游Original
2022-03-01 16:50:304226browse

In jquery, you can use the attr() method to set the disabled attribute to make the text box uneditable. The disabled attribute can specify that the text area is disabled (not editable); the syntax is "$("textarea").attr ("disabled","disabled");".

How to make the text box uneditable in jquery

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

In jquery, you can use the attr() method to set the disabled attribute to make the text box uneditable.

The disabled property is a Boolean property. The disabled attribute specifies that the text area should be disabled. A disabled text area is neither usable nor the text selectable (cannot be copied).

Just use the attr() method to set the disabled attribute to the textarea element of the text box.

Grammar:

$("textarea").attr("disabled","disabled");
$("textarea").attr("disabled","true");

Example:

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<script src="js/jquery-1.10.2.min.js"></script>
		<script type="text/javascript">
			$(document).ready(function() {
				$("button").click(function() {
					$("textarea").attr("disabled", "disabled");
					// $("textarea").attr("disabled","true");
				});
			});
		</script>
	</head>

	<body>
		<textarea></textarea><br><br>
		<button>让textarea不可编辑</button>
	</body>

</html>

How to make the text box uneditable in jquery

##[Recommended learning:

jQuery video tutorial, Web front-end introductory tutorial

The above is the detailed content of How to make the text box 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