Disable/enable an input with jQuery?

后端 未结 18 2645
礼貌的吻别
礼貌的吻别 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:59

        // Disable #x
        $( "#x" ).prop( "disabled", true );
        // Enable #x
        $( "#x" ).prop( "disabled", false );
    

    Sometimes you need to disable/enable the form element like input or textarea. Jquery helps you to easily make this with setting disabled attribute to "disabled". For e.g.:

      //To disable 
      $('.someElement').attr('disabled', 'disabled');
    

    To enable disabled element you need to remove "disabled" attribute from this element or empty it's string. For e.g:

    //To enable 
    $('.someElement').removeAttr('disabled');
    
    // OR you can set attr to "" 
    $('.someElement').attr('disabled', '');
    

    refer :http://garmoncheg.blogspot.fr/2011/07/how-to-disableenable-element-with.html

提交回复
热议问题