This example shares the specific code for jquery to realize three-level linkage for your reference. The specific content is as follows
jsp page part:
<li id="floors"> <span id="floorShow">Select a building: </span> <select name="build" id="build" onchange="floor2()"> </select> </li> <li id="builds"> <span id="floorShow">Select a house: </span> <select name="builds" id="floot2"> </select></li>
js part:
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'>Please select </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'>Please select </option>"; for(var i=0;i<len;i++){ htm += "<option value='"+data[i].id+"'>"+data[i].info+"</option>"; } $("#floot2").append(htm); } }) } }Struts2 configuration part:
<package name="user" namespace="/" extends="json-default"> <action name="floor" method="floor"> <result type="json"> <param name="root">floor</param> </result> </action> <action name="floor2" method="floor2"> <result type="json"> <param name="root">floor2</param> </result> </package>
Action section:
public String floor(){ System.out.println("Here is ajax call"); //floor = addressInfoService.getFloor(addressInfo.getParentId()); System.out.println(addressInfo.getParentId()); floor = addressInfoService.getFloor(addressInfo.getParentId()); return SUCCESS; } public String floor2(){ System.out.println("Here is the second call of ajax"); System.out.println(addressInfo.getParentId()); floor2 = addressInfoService.getBuild(addressInfo.getParentId()); return SUCCESS; }Finally, don't forget to import struts2-json-plugin-2.3.15.1.jar. The version of this package should also be consistent with other package versions of struts2.
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.