removeAttr(name)
删除匹配集合中每个元素的属性‘name’
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
$("button").click(function () {
$(this).next().removeAttr("disabled")
.focus()
.val("editable now");
});
});
</script>
</head>
<body>
<button>Enable</button>
<input type="text" disabled="disabled" value="can't edit this" />
</body>
</html>
$(this).next().removeAttr("disabled")
删除input元素中disabled属性。以下为删除属性
<input type="text" disabled="disabled" value="can't edit this" />
本文介绍如何使用jQuery的removeAttr方法来删除HTML元素的disabled属性,从而实现使原本被禁用的输入框变为可用状态。通过一个简单的示例,演示了当按钮被点击时,紧随其后的输入框将取消disabled状态并更新其值。
2万+

被折叠的 条评论
为什么被折叠?



