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

查看:31
本文介绍了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.

推荐答案

将元素的 disabled 属性设置为 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;
}

其中 document 可以替换为一个表单,例如,仅查找该表单中的元素.您还可以使用 getElementsByTagName('input') 来获取所有输入元素.在您的 for 迭代中,您必须检查 inputs[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天全站免登陆