Home > Web Front-end > Front-end Q&A > How to make the text box uneditable in jquery

How to make the text box uneditable in jquery

青灯夜游
Release: 2022-03-01 16:50:30
Original
4256 people have browsed it

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");
Copy after login

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

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!

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