国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

用jquery生成二級菜單的實例代碼

2024-05-06 15:48:15
字體:
供稿:網(wǎng)友
這篇文章介紹了用jquery生成二級菜單的代碼,需要的朋友可以參考一下

javascript

頁面中的函數(shù)

復制代碼 代碼如下:


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 = $('<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(<s:property value='article.subChannel.channel.channelId'/>,<s:property value='article.subChannel.subId'/>);
});


頁面代碼:

復制代碼 代碼如下:


<tr>
<th>一級欄目</th>
<td valign="middle">
<s:select list="channelList" listKey="channelId"
listValue="channelName"
key="article.subChannel.channel.channelId"
onchange="querySub(this.value)"></s:select>
</td>
</tr>
<tr>
<th>二級欄目</th>
<td valign="middle">
<s:select list="{}" headerKey="" headerValue="-請選擇-"></s:select>
<!--<s:property value="article.subChannel.subName"/>
--></td>
</tr>


服務器

復制代碼 代碼如下:


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

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

for(Object oo:subChannelList){
Map<String,Object> obj = new HashMap<String,Object>();
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;
}


其實蠻簡潔的

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 赣州市| 遂溪县| 东辽县| 阳高县| 恩施市| 安陆市| 临沭县| 松桃| 东台市| 石景山区| 绵竹市| 镶黄旗| 雅安市| 清河县| 虹口区| 肇庆市| 平邑县| 崇左市| 墨脱县| 高尔夫| 陵水| 门源| 岐山县| 西吉县| 汉川市| 房产| 乐至县| 昌图县| 亚东县| 金门县| 白河县| 青浦区| 喜德县| 大足县| 隆德县| 南充市| 株洲市| 永登县| 余干县| 北票市| 娄底市|