Disable/enable an input with jQuery?

后端 未结 18 2737
礼貌的吻别
礼貌的吻别 2020-11-21 07:47
$input.disabled = true;

or

$input.disabled = \"disabled\";

Which is the standard way? And, conversely, how do yo

18条回答
  •  忘掉有多难
    2020-11-21 08:06

    You can put this somewhere global in your code:

    $.prototype.enable = function () {
        $.each(this, function (index, el) {
            $(el).removeAttr('disabled');
        });
    }
    
    $.prototype.disable = function () {
        $.each(this, function (index, el) {
            $(el).attr('disabled', 'disabled');
        });
    }
    

    And then you can write stuff like:

    $(".myInputs").enable();
    $("#otherInput").disable();
    

提交回复
热议问题