removeAttr() not removing “disabled” attribute in IE

前端 未结 3 883
后悔当初
后悔当初 2020-12-03 07:17
var disableSelection = function(){
    $(\"#elementId\").attr(\"disabled\",\"disabled\");    
};

var enableSelection = function(){
    $(\"#elementId\").removeAttr(         


        
相关标签:
3条回答
  • 2020-12-03 07:37

    You can use removeProp('disabled') instead. It worked for me while removeAttr('disabled') didn't.

    0 讨论(0)
  • 2020-12-03 07:48

    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);
    };
    

    For more information, see .prop() vs .attr().

    0 讨论(0)
  • 2020-12-03 07:58

    Jquery Docs says, about .removeProp():

    Note: Do not use this method to remove native properties such as checked, >disabled, or selected. This will remove the property completely and, once >removed, cannot be added again to element. Use .prop() to set these properties >to false instead.

    Additional Notes:

    In Internet Explorer prior to version 9, using .prop() to set a DOM element >property to anything other than a simple primitive value (number, string, or >boolean) can cause memory leaks if the property is not removed (using >.removeProp()) before the DOM element is removed from the document. To safely >set values on DOM objects without memory leaks, use .data().

    0 讨论(0)
提交回复
热议问题