Home >Web Front-end >JS Tutorial >jquery implements secondary linkage of drop-down menu using json object to get value from DB to display linkage_javascript skills

jquery implements secondary linkage of drop-down menu using json object to get value from DB to display linkage_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:54:211296browse

Use struts2 and Ajax to realize the transmission of json objects, and then realize the secondary linkage of the menu

The following is the original code of my js file:

Copy code The code is as follows:

var mail={
//Initialization
init:{
//Initialization data
initdata:{
did:'',
ttitle:'',
sendpassword:'',
description:''
},
//Initialization event
initevent:{
DataEvent:function(){
$("#did").unbind("change");//Get the first-level menu and bind the event
$("#did").bind("change ",function(){
//alert($(this).val());
mail.init.initdata.did=$(this).val();
//alert( mail.init.initdata.did);
mail.init.initevent.getuser();
});
},
getuser:function(){
$.post("mailAction_showUsers?did=" mail.init.initdata.did,null,function(data){
var uidoption=$("#uid") ;// Get the secondary menu
uidoption.empty();//Empty the list
for(var i=0;i//Fill options into it, pass Loop
uidoption.append("" );
}
});

},
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 your password!");
return false;
}
else if(mail .init.initdata.ttitle==""){
alert("Please enter a topic! ");
return false ;
}
else if(mail.init.initdata.description==""){
alert("Please enter content!");
return false ;
}
else
return true;
});
}
}
}
}

$().ready(function (){
mail.init.initevent.DataEvent();
mail.init.initevent.submitCheck();

});

This is the background action:
Copy code The code is as follows:

private int did;
public String getDid(){
...
}
public void setDid(Strign did){
...
}
public String showUsers(){

users=(ArrayList)this.userService.getUsersByDid(did);
System.out.println(users.size() "...");
return SUCCESS;
}

Struts.xml configuration:
Copy code The code is as follows:



< ;result type="json">




Front-end jsp page:
Copy code The code is as follows:

Receiver




This is a screenshot of the operation after implementation:
jquery implements secondary linkage of drop-down menu using json object to get value from DB to display linkage_javascript skills
Written to those in need. . . Reference Reference
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn