jquery实现三级联动 SSH结合jquery实现三级联动效果
李佳和2435 人气:0想了解SSH结合jquery实现三级联动效果的相关内容吗,李佳和2435在本文为您仔细讲解jquery实现三级联动的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:SSH,jquery,三级联动,下面大家一起来学习吧。
jsp页面部分:
<li id="floors"> <span class="title" id="floorShow">选择楼栋:</span> <select name="build" id="build" style="width: 282px;height: 40px;" onchange="floor2()"> </select> </li> <li id="builds"> <span class="title" id="floorShow">选择住房:</span> <select name="builds" id="floot2" style="width: 282px;height: 40px;"> </select> </li>
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 = "<option value='0'>请选择</option>"; for(var i=0;i<len;i++){ htm += "<option value='"+data[i].id+"'>"+data[i].info+"</option>"; } $("#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 = "<option value='0'>请选择</option>"; for(var i=0;i<len;i++){ htm += "<option value='"+data[i].id+"'>"+data[i].info+"</option>"; } $("#floot2").append(htm); } }) } }
struts2配置部分:
<package name="user" namespace="/" extends="json-default"> <action name="floor" class="addressInfoAction" method="floor"> <result type="json"> <param name="root">floor</param> </result> </action> <action name="floor2" class="addressInfoAction" method="floor2"> <result type="json"> <param name="root">floor2</param> </result> </action> </package>
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的其他的夹包的版本一致。
加载全部内容