jQuery dropdown select event

前端 未结 1 1119
梦毁少年i
梦毁少年i 2021-01-27 17:21

Is there a specific event for when a user selects an item in a dropdown box? I am creating a fairly large form that uses multiple dropdown boxes. On load all but the first are d

相关标签:
1条回答
  • 2021-01-27 18:20

    Try Below code:

    <select id="drop1">
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
    </select>
    <select id="drop2"></select>
    

    Jquery

    $(document).ready(function(){
    $("#drop2").attr("disabled", true);
    $("#drop1").change(function(){
        $("#drop2").attr("disabled", false);
        //Put your ajax code here and bind like below code
        $("#drop2").append(new Option("option text", "value"));
        $("#drop2").append(new Option("xxx","1"));        
    });
    });
    

    Demo: http://jsfiddle.net/J5kmz/

    0 讨论(0)
提交回复
热议问题