English 中文(简体)
j En
原标题:Enable/Disable a dropdownbox in jquery

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.

最佳回答

在这里,我希望很容易理解:

http://jsfiddle.net/tft4t/

$(document).ready(function() {
 $("#chkdwn2").click(function() {
   if ($(this).is(":checked")) {
      $("#dropdown").prop("disabled", true);
   } else {
      $("#dropdown").prop("disabled", false);  
   }
 });
});
问题回答

我正在使用JQuery >1.8,为我工作。

$( #dropDownId ).attr( disabled , true);

Try -

$( #chkdwn2 ).change(function(){
    if($(this).is( :checked ))
        $( #dropdown ).removeAttr( disabled );
    else
        $( #dropdown ).attr("disabled","disabled");
})
$("#chkdwn2").change(function(){
       $("#dropdown").slideToggle();
});

rel=“nofollow”>JsFiddle

To enable/disable -

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

Demo -

try this

 <script type="text/javascript">
        $(document).ready(function () {
            $("#chkdwn2").click(function () {
                if (this.checked)
                    $( #dropdown ).attr( disabled ,  disabled );
                else
                    $( #dropdown ).removeAttr( disabled );
            });
        });
    </script>

www.un.org/Depts/DGACM/index_spanish.htm a. 更好的解决办法:

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

使用<代码>。

如果你从价值为15的下降1中挑选出选择方案,那是可消除的下降。

$("#dropdown1").change(function(){
            if ( $(this).val()!= "15" ) {
                $("#dropdown2").attr("disabled",true);
                $("#dropdown13").attr("disabled",true);

            }

您的遴选人应或是选人、助手(#)或班级(+)。

www.un.org/Depts/DGACM/index_spanish.htm 如果你想要放弃:

$("#your-selector").prop("disabled", true);

www.un.org/Depts/DGACM/index_spanish.htm 如果你想要做到:

$("#your-selector").prop("disabled", false); 




相关问题
PHP Combo Box AJAX Refresh

I have a PHP page that currently has 4 years of team positions in columns on the page. The client wants to select the players in positions and have first, second and thrid choices. Currently the page ...

jquery + ajax + json + fill dropdown list not working

I m pretty sure i am almost there....but i cannot figure out how to iterate through json objects and fill a dropdown list. Here is the js code: My JSON data returned:{"name":"County1","name":"County1"...

Gridviews and DropdownLists

Is it possible to change the data source of a dropdown list in a gridview from another dropdown list selected index changed method in the same gridview? for example I have a dropdown that needs to ...

Adding a new value to the drop down list box

I have a drop down list box which has one of the values to be others. I want to move these value to the last. Please help me with this. The code i am using is as follows ddlAssetsCountryOthersone....

Show hide div using codebehind

I have a DropDownList for which I am trying to show a div OnSelectedIndexChanged but it says OBJECT REQUIRED. I am binding the DataList in that div: aspx: <asp:DropDownList runat="server" ID="...

Why might dropdownlist.SelectedIndex = value fail?

I have a dropdown list that I am binding to a datatable. Here is the code I am using to do it: ddlBuildAddr.DataSource = buildings ddlBuildAddr.DataTextField = "buildingName" ddlBuildAddr....

热门标签