当前位置:Gxlcms > JavaScript > 用jquery生成二级菜单的实例代码_jquery

用jquery生成二级菜单的实例代码_jquery

时间:2021-07-01 10:21:17 帮助过:3人阅读

javascript

页面中的函数

代码如下:

function querySub(id,sid/*选中的项*/){
$.post('${path}/page/article/querySubChannelArticle.action',
{'channelId':id},function(data){
$('select[name="article.subChannel.subId"] option[value!=""]').remove();
var jsonObj = data;
for ( var i = 0; i < jsonObj.length; i++) {
var $option = $('

页面代码:
代码如下:


一级栏目

listValue="channelName"
key="article.subChannel.channel.channelId"
onchange="querySub(this.value)">




二级栏目





服务器端

代码如下:

public String querySubChannelArticle(){
HttpServletResponse response=getResponse();
HttpServletRequest request=getRequest();
response.setContentType("application/json; charset=UTF-8");
PrintWriter out =null;
try {
out = response.getWriter();

List> list = new LinkedList>();
if(channelId!=null && !channelId.equals("")){
Channel tmp = new Channel();
tmp.setChannelId(Integer.parseInt(channelId));
subChannelList = subChannelDAO.listSubChannel(tmp);

for(Object oo:subChannelList){
Map obj = new HashMap();
SubChannel c = (SubChannel)oo;
obj.put("subId", c.getSubId());
obj.put("subName", c.getSubName());
list.add(obj);
}
}
String outStr = JsonUtil.toJSONStr(list);
out.println(outStr);
}catch(Exception e){
e.printStackTrace();
}
out.flush();
out.close();
return null;
}

其实蛮简洁的

人气教程排行