Home >Web Front-end >Front-end Q&A >How to make elements editable in jquery

How to make elements editable in jquery

青灯夜游
青灯夜游Original
2022-05-23 14:42:102078browse

Two methods: 1. Use prop() to set the value of the disabled attribute to false, the syntax is "element object.prop("disabled",false)". 2. Use removeAttr() to delete attributes, the syntax is "element object.removeAttr("disabled")".

How to make elements editable in jquery

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

In HTML, if an element (textarea, input, etc.) is set to the disabled attribute, it will be in an uneditable state.

So how to restore non-editable elements to editable state? Here is the jquery method.

1. Use prop()

You only need to set the disabled attribute value to false.

<!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").prop("disabled",false);
			});
		});
		</script>
	</head>
	<body>

		<input type="text" disabled="disabled" />
		<br><br>
		<button>实现可编辑</button>

	</body>
</html>

How to make elements editable in jquery

2. Use removeAttr()

Just use removeAttr() to delete the disabled attribute.

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

		<input type="text" disabled="disabled" />
		<br><br>
		<button>实现可编辑</button>

	</body>
</html>

How to make elements editable in jquery

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

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