JQuery Script Load Timing

前端 未结 3 1717
猫巷女王i
猫巷女王i 2020-12-28 10:55

If I have a button that sets off a jquery script is there a way to make sure the button is inactive until the script completes?

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-28 11:12

    This is one area where I like to extend jQuery:

    $.fn.disable = function() {
        return this.each(function() {
            if (typeof this.disabled != "undefined") this.disabled = true;
        });
    }
    
    $.fn.enable = function() {
        return this.each(function() {
            if (typeof this.disabled != "undefined") this.disabled = false;
        });
    }
    

    and then you can do:

    $("#button").disable();
    $("#button").enable();
    

    I find myself disabling/enabling controls a lot.

提交回复
热议问题