欢迎光临
我们一直在努力

jquery如何实现元素可编辑

本篇内容主要讲解“jquery如何实现元素可编辑”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“jquery如何实现元素可编辑”吧!

两种方法:1、用prop()将disabled属性的值设置为false,语法“元素对象.prop("disabled",false)”。2、用removeAttr()删除属性,语法“元素对象.removeAttr("disabled")”。

本教程操作环境:windows7系统、jquery1.10.2版本、Dell G3电脑。

在HTML中,如果元素(textarea、input等)设置了disabled属性,就会处于不可编辑状态。

那么怎么将不可编辑的元素恢复可编辑状态呢,下面介绍一下jquery方法。

1、使用prop()

只需要将disabled属性值设置为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>

2、使用removeAttr()

只需要使用removeAttr()删除disabled属性即可。

<!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>

到此,相信大家对“jquery如何实现元素可编辑”有了更深的了解,不妨来实际操作一番吧!这里是云搜网网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。