Dieser Artikel teilt den spezifischen Code für JQuery mit, um eine dreistufige Verknüpfung für Ihre Referenz zu realisieren. Der spezifische Inhalt ist wie folgt
JSP -Seitenteil:
<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 Teil:
Funktion floor () {document.getElementById ("Build"). Optionen.Length = 0; document.getElementById ("floot2"). Optionen.length = 0; var parentId = document.getElementById ("Dorf"). Wert; if (parentID == 0) {} else {$ .ajax ({type: "post", url: "floor.action", data: {"parentId": parentId}, dataType: "json", Erfolg: Funktion (Daten) {Konsole.log (Daten); var len = data. i = 0; i <len; i ++) {htm+= "<option value = '"+data [i] .id+"'>"+data [i] .info+"</option>"; var Build = document.getElementById ("Build"). Wert; if (build == 0) {} else {$ .ajax ({Typ: "post", url: "floor2.Action", Daten: {"parentId": build}, DataType: "JSON", Erfolg: Funktion (Daten) {var len = data.length; htm+= "<Option Value = '"+Daten [i] .ID+"'>"+Daten [i] .Info+"</option>";Struts2 -Konfigurationsteil:
<package name = "user" namespace = "/" extends = "json-Default"> <action name = "floor" methode = "floor"> <result type = "json"> <param name = "root"> floor </param> </result> </action> <actionname = "floor 2" methode
Aktionsabschnitt:
public String floor () {System.out.println ("Hier ist ajax call"); // floor = addressInfoService.getfloor (adressInfo.getParentid ()); System.out.println (adressInfo.getParentid ()); floor = addressInfoService.getFloor (adressInfo.getParentid ()); Erfolgserfolg; } public String floor2 () {System.out.println ("Hier ist der zweite Anruf von Ajax"); System.out.println (adressInfo.getParentid ()); floor2 = addressInfoService.getBuild (addressInfo.getParentid ()); Erfolgserfolg; }Vergessen Sie schließlich nicht, Struts2-Json-Plugin-2.3.15.1.Jar zu importieren. Die Version dieses Pakets sollte auch mit anderen Paketversionen von Struts2 übereinstimmen.
Das obige ist der gesamte Inhalt dieses Artikels. Ich hoffe, es wird für das Lernen aller hilfreich sein und ich hoffe, jeder wird Wulin.com mehr unterstützen.