jquery生成二级菜单的实例代码
本文导语: 1,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;...
1,javascript 页面中的函数
$.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 = $('');
$option.attr('value',jsonObj[i].subId);
if(jsonObj[i].subId === sid){
$option.attr('selected',true);
}
$option.text(jsonObj[i].subName);
$('select[name="article.subChannel.subId"]').append($option);
}
});
}
$(function(){
querySub(,);
});
页面代码:
一级栏目
二级栏目
服务器端
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;
}
- jquery 树形二级菜单实例代码
- jquery 二级导航菜单 示例
- jquery二级联动的实现代码一例
- jquery二级菜单动画效果的实现代码
- jquery+div+css二级菜单的实现代码