二级联动
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(); } }
作为一个真正的程序员,首先应该尊重编程,热爱你所写下的程序,他是你的伙伴,而不是工具。