二级联动


function getdormid() {
        alert(11);
        var id=$("#id").val();
        $.get("${path}/dorm?method=JSONDormList",{id:id},function(data){
            var str="";
            $.each(data, function(i, obj) {
                alert(obj.remaining_number);
                if(obj.remaining_number!=0){
                    str += "<option value="+obj.id+">" + obj.code + "</option>";
                }
            });
            $("#dorm").html(str);
        }, "json");
        
    }
    <tr>
            <td>宿舍编号:</td><td>
            <select name="id" id="id" onchange="getdormid()">
                <option value="0">男</option> 
                <option value="1">女</option> 
            </select>
            <select name="dorm" id="dorm" >
                <option></option> 
            </select>
        </tr>
// 查询宿舍集合
    private void getJSONDormList(HttpServletRequest request, HttpServletResponse response) {
        //调用方法
        String id= request.getParameter("id");
        List<Dorms> dormList=studentService.getJSONDormList(id);
        System.out.println(dormList.size()+"成都");
        Object jsonList = JSON.toJSON(dormList);
        PrintWriter out;
        try {
            out = response.getWriter();
            out.print(jsonList);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

 

posted @ 2019-03-05 20:23  lilixia  阅读(251)  评论(0编辑  收藏  举报