本文实例为大家分享了jquery实现三级联动的具体代码,供大家参考,具体内容如下
jsp页面部分:
js部分:
function floor(){ document.getElementById("build").options.length =0; document.getElementById("floot2").options.length =0; var parentId = document.getElementById("village").value; if(parentId == 0){ }else{ $.ajax({ type : "post", url : "floor.action", data : {"parentId":parentId}, dataType : "json", success :function(data){ console.log(data); var len = data.length; var htm = ""; for(var i=0;i"+data[i].info+""; } $("#build").append(htm); } }) } } function floor2(){ document.getElementById("floot2").options.length =0; var build = document.getElementById("build").value; if(build == 0){ }else{ $.ajax({ type : "post", url : "floor2.action", data : {"parentId":build}, dataType : "json", success : function(data){ var len = data.length; var htm = ""; for(var i=0;i "+data[i].info+""; } $("#floot2").append(htm); } }) } }
struts2配置部分:
floor floor2
action部分:
public String floor(){ System.out.println("这里是ajax调用"); //floor = addressInfoService.getFloor(addressInfo.getParentId()); System.out.println(addressInfo.getParentId()); floor = addressInfoService.getFloor(addressInfo.getParentId()); return SUCCESS; } public String floor2(){ System.out.println("这里是ajax的第二次调用"); System.out.println(addressInfo.getParentId()); floor2 = addressInfoService.getBuild(addressInfo.getParentId()); return SUCCESS; }
最后,一定不要忘记导入struts2-json-plugin-2.3.15.1.jar 这个夹包的版本也要和struts2的其他的夹包的版本一致。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。