This article mainly introduces the implementation of the jquery drop-down menu two-level linkage using JSON objects from DB value display linkage, need friends can refer to the following
Use STRUTS2 and Ajax to implement JSON object transmission, and then implement menu two-level linkage Below is my JS file original code: code as follows: VAR mail={ //initialization init:{ //initialization of data initdata:{ did: ', ttitle: ', sendpassword: ', description: ' }, //initialization event initevent:{ dataevent:function () { $ ("#did"). Unbind ("change"); Get a level menu, bind event $ ("#did"). Bind (' Change ', function () { //alert ($ (this). Val ()); mail.init.initdata.did=$ (This). Val (); //alert (Mail.init.initdata.did); mail.init.initevent.getuser (); }); }, <span Style = "COLOR: #ff0000;" >getuser:function () { $.post ("mailaction_showusers?did=" +mail.init.initdata.did,null,function (data) { var uidoption=$ ("#uid")//Get level Two menu uidoption.empty ()//Empty list for (Var i=0;i<data.users.length;i+ +) { //Add option to the inside, through the loop uidoption.append ("<option value=" +data.users[i].uid+ ">" +data.users[i). Username+ "</option>"); } });</span> },&nbsP Submitcheck:function () { $ ("#send"). Unbind ("click"); $ ("#send"). Bind ("click", Function () { mail.init.initdata.description=$ ("input[type= ' textarea ']"). Text (); mail.init.initdata.sendpassword=$ (" Input[name= ' Sendpassword '). Val (); mail.init.initdata.ttitle=$ ("Input[name= ' Ttitle ')"). Val (); if (mail.init.initdata.sendpassword== "") { alert ("Please enter password!"); Return false; } else if (mail.init.initdata.ttitle== "") { alert ("Please enter a theme!") "); return false; } else if (mail.init.initdata.description==" ") { alert (" Enter the content! "). "); return false; } else return true; }); } -} } } $ (). R Eady (function () { mail.init.initevent.DataEvent (); Mail.init.initevent.submitCheck (); }); This is the backstage action: code as follows: Private int did; public String getdid () { ... } Public void Setdid (Strign did) { ... } PUBlic String showusers () { users= (arraylist<user>) This.userService.getUsersByDid (did); System.out.println (users.size () + "..."); return success; } struts.xml configuration: code is as follows: <package name= "Users" namespace= "/" extends= "Json-default" > <action name= "Mailaction_showusers" Method= "Showusers" class= "mailaction" > <result type= "JSON" ></result> </action> </package> foreground JSP page: code as follows: <td width= "65px" > Receiver </td> <td> <s:select list= "departmentlist" listkey= "did" listvalue= "Dname" id= "did" Name= "did" ></s:select > <s:select list= "users" listkey= "UID" listvalue= "username" id= "UID" name= "UID" ></s:select> </td>