javascript jQuery:removeAttr("disabled") 不适用于 Firefox
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4138950/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery: removeAttr("disabled") not working on Firefox
提问by randombits
I have some code that looks like the following coming back from an XHR response:
我有一些代码看起来像从 XHR 响应返回的以下内容:
jQuery(':text:not(:hidden)').removeAttr("disabled");
This is a result of input fields being disabled after form submit. The XHR response returns this tidbit of jQuery and re-enables controls. Works great on every browser, even "partially" on FF 3.6.1 OSX. What I mean by partially is that some text fields have the disabled attribute removed, others do not. These text fields are verified not hidden.
这是表单提交后输入字段被禁用的结果。XHR 响应返回 jQuery 的这个花絮并重新启用控件。适用于所有浏览器,甚至“部分”适用于 FF 3.6.1 OSX。我的意思是部分文本字段删除了 disabled 属性,而其他文本字段没有。这些文本字段已验证未隐藏。
回答by lonesomeday
Have a go using this instead:
试试用这个:
jQuery('input:text:visible').each(function(){
this.disabled = false;
});
This uses the disabledproperty of the element directly, rather than messing around with jQuery wrappers.
这disabled直接使用元素的属性,而不是使用 jQuery 包装器。
回答by Bryan A
Did you try something like:
你有没有尝试过:
jQuery('input[type=text]:visible').removeAttr("disabled");
回答by Daniel
Instead try:
而是尝试:
jQuery(':text:not(:hidden)').attr("disabled",'');

