How to make elements editable in jquery

青灯夜游
Release: 2022-05-23 14:42:10
Original
2051 people have browsed it

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

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

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!

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