removeAttr() 不删除“已禁用";IE中的属性 [英] removeAttr() not removing "disabled" attribute in IE
本文介绍了removeAttr() 不删除“已禁用";IE中的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var disableSelection = function(){
$("#elementId").attr("disabled","disabled");
};
var enableSelection = function(){
$("#elementId").removeAttr("disabled");
};
我有以下要求:
- 禁用 SELECT 元素以限制用户选择选项
- 禁用的 SELECT 元素已经选择了一些 OPTION 元素
- 在提交事件时启用禁用的 SELECT 元素以保存所选值
添加属性禁用"对 IE 效果很好.然而,当我尝试使用 jQuery revomeAttr() 方法删除属性时,而不是删除属性:
Adding attribute "disabled" works well for IE. Yet, when I try to remove attribute by using jQuery revomeAttr() method then instead of removing attribute:
- 方法将禁用"属性添加到先前启用的 SELECT 元素
- 方法不会删除禁用"属性
推荐答案
使用 .prop
而不是 .attr
来影响元素的禁用状态:
Use .prop
instead of .attr
to affect an element's disabled state:
var disableSelection = function(){
$("#elementId").prop("disabled", true);
};
var enableSelection = function(){
$("#elementId").prop("disabled", false);
};
有关详细信息,请参阅.prop() 与 .attr().
For more information, see .prop() vs .attr().
这篇关于removeAttr() 不删除“已禁用";IE中的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文