Enable/Disable a dropdownbox in jquery

2019-01-08 16:15发布

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

<select id="dropdown" style="width:200px">
    <option value="feedback" name="aft_qst">After Quest</option>
    <option value="feedback" name="aft_exm">After Exam</option>
</select>
<input type="checkbox" id="chkdwn2" value="feedback" />

What jQuery code do I need to do this? Also searching for a good jQuery documentation/study material.

9条回答
我想做一个坏孩纸
2楼-- · 2019-01-08 16:51

try this

 <script type="text/javascript">
        $(document).ready(function () {
            $("#chkdwn2").click(function () {
                if (this.checked)
                    $('#dropdown').attr('disabled', 'disabled');
                else
                    $('#dropdown').removeAttr('disabled');
            });
        });
    </script>
查看更多
时光不老,我们不散
3楼-- · 2019-01-08 16:55

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

$('#dropDownId').attr('disabled', true);
查看更多
祖国的老花朵
4楼-- · 2019-01-08 16:55
$("#chkdwn2").change(function() { 
    if (this.checked) $("#dropdown").prop("disabled",'disabled');
}) 
查看更多
登录 后发表回答