Home >Web Front-end >Front-end Q&A >How to remove readonly attribute in jquery

How to remove readonly attribute in jquery

青灯夜游
青灯夜游Original
2022-03-03 14:39:475032browse

In jquery, you can use the removeAttr() method to remove the readonly attribute of an element. This method can remove the specified attribute from the selected element. The syntax is "$(selector).removeAttr("readonly") ".

How to remove readonly attribute in jquery

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

The readonly attribute specifies that the input field is read-only. Read-only fields cannot be modified. However, users can still tab to the field and select or copy its text.

The readonly attribute prevents users from modifying the value until certain conditions are met (such as a checkbox being selected).

jquery removes readonly (read-only) effect

In jquery, you can use the removeAttr() method to remove the readonly attribute of an element

removeAttr() method is used to remove attributes from selected elements.

<!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").removeAttr("readonly");
				});
			});
		</script>
	</head>

	<body>
		<textarea readonly="readonly">测试文本</textarea><br><br>
		<button>移除readonly(只读)效果</button>
	</body>

</html>

How to remove readonly attribute in jquery

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

The above is the detailed content of How to remove readonly attribute 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