javascript删除“已停用”来自html输入的属性 [英] javascript remove "disabled" attribute from html input

查看:132
本文介绍了javascript删除“已停用”来自html输入的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用javascript从HTML输入中删除禁用属性?

How can I remove the "disabled" attribute from an HTML input using javascript?

<input id="edit" disabled>

onClick我希望我的输入标签不包含禁用属性。

at onClick I want my input tag to 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('input')来获取所有输入元素。在你的 for 迭代中,你必须检查输入[i] .type =='text'

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删除“已停用”来自html输入的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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