select下拉联动

来源:互联网 发布:星际战甲画质优化 编辑:程序博客网 时间:2024/05/21 04:25
<!--一级select--><select name="s1" id="s1" class="form-control">    <option value="">--全部--</option>       <c:forEach items="${list }" var="item">    <option value="${item.id }">${item.desc }</option></c:forEach></select><!--二级select--><select class="form-control" name="s2" id="s2">     <option>--全部--</option></select><!--js--><!--根据s1选择的值动态更新s2里面的数据-->$("#s1").change(function() {        var id = $("#s1").val();        $.ajax({        type : 'post',        url : '',        data : {            'id':id        },        dataType : 'json',        success : function(data) {            if(data.flag){                var html = '<option value="">--全部--</option>';                $.each(data.obj, function(index, content) {                    html += '<option value="'+content.id+'">';                    html +=''+content.desc+'</option>';                });                <!--s2 select中追加数据-->                $("#s2").html(html);            }               }    });});