Disable/enable an input with jQuery?

后端 未结 18 2677
礼貌的吻别
礼貌的吻别 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 07:50

    I used @gnarf answer and added it as function

       $.fn.disabled = function (isDisabled) {
         if (isDisabled) {
           this.attr('disabled', 'disabled');
         } else {
           this.removeAttr('disabled');
         }
       };
    

    Then use like this

    $('#myElement').disable(true);
    

提交回复
热议问题