Enable/Disable a dropdownbox in jquery

后端 未结 10 1447
情深已故
情深已故 2020-12-01 03:34

I am new to jQuery and I want to enable and disable a dropdown list using a checkbox. This is my html:


                        
    
提交评论

  • 2020-12-01 03:47
    $(document).ready(function() {
     $('#chkdwn2').click(function() {
       if ($('#chkdwn2').prop('checked')) {
          $('#dropdown').prop('disabled', true);
       } else {
          $('#dropdown').prop('disabled', false);  
       }
     });
    });
    

    making use of .prop in the if statement.

    0 讨论(0)
  • 2020-12-01 03:50

    To enable/disable -

    $("#chkdwn2").change(function() { 
        if (this.checked) $("#dropdown").prop("disabled",true);
        else $("#dropdown").prop("disabled",false);
    }) 
    

    Demo - http://jsfiddle.net/tTX6E/

    0 讨论(0)
  • 2020-12-01 03:54

    I am using JQuery > 1.8 and this works for me...

    $('#dropDownId').attr('disabled', true);
    
    0 讨论(0)
  • 2020-12-01 03:56
    $("#chkdwn2").change(function(){
           $("#dropdown").slideToggle();
    });
    

    JsFiddle

    0 讨论(0)
  • 2020-12-01 03:59
    $("#chkdwn2").change(function() { 
        if (this.checked) $("#dropdown").prop("disabled",'disabled');
    }) 
    
    0 讨论(0)
  • 提交回复
    热议问题