JavaScript的移除];禁用"属性HTML输入 [英] javascript remove "disabled" attribute to html input

查看:136
本文介绍了JavaScript的移除];禁用"属性HTML输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用javascript去掉禁用属性的HTML输入?

How can I remove "disabled" attribute to an html input using javascript?

<input id=edit disabled>

在的onclick我希望我的输入标签不包括已禁用属性。

at onclick I wanted my input tag not consist of "disabled" attribute.

推荐答案

设置元素的禁用属性设置为false:

Set the element's disabled property to false:

document.getElementById('my-input-id').disabled = false;

如果你正在使用jQuery,等效是:

If you're using jQuery, the equivalent would be:

$('#my-input-id').prop('disabled', false);

有关的几个输入字段,则可以通过类,而不是访问它们:

For several input fields, you may access them by class instead:

var inputs = document.getElementsByClassName('my-input-class');
for(var i = 0; i < inputs.length; i++) {
    inputs[i].disabled = false;
}

其中,文件可以用的形式取代,例如,只查找表单中的元素。你也可以使用的getElementsByTagName('输入')来获取所有输入元素。在你的迭代,你则必须检查输入[I] .TYPE =='文本'

Where document could be replaced with a form, for instance, to find only the elements inside that form. You could also use getElementsByTagName('input') to get all input elements. In your for iteration, you'd then have to check that inputs[i].type == 'text'.

这篇关于JavaScript的移除];禁用&QUOT;属性HTML输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆