用jquery生成二級菜單的實例代碼
更新時間:2013年06月24日 11:04:51 作者:
這篇文章介紹了用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 id='_channel' 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 name='article.subChannel.subId' 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;
}
其實蠻簡潔的
相關文章
jQuery幫助之CSS尺寸(五)outerHeight、outerWidth
在前面我們分別通過innerHeight()和innerWidth()來獲得第一個匹配元素內部區(qū)域的高度和寬度,我們在應用中往往除了需要內部的尺寸,同樣還需要知道外部的高度和寬度.2009-11-11Jquery加載時從后臺讀取數(shù)據(jù)綁定到dropdownList實例
從后臺讀取數(shù)據(jù)綁定到dropdownList,option選項value動態(tài)賦值,具體實現(xiàn)如下,感興趣的朋友可以參考下哈2013-06-06jQuery簡單實現(xiàn)仿京東商城的左側菜單效果代碼
這篇文章主要介紹了jQuery簡單實現(xiàn)仿京東商城的左側菜單效果代碼,通過簡單的jQuery鼠標事件及元素動態(tài)變換實現(xiàn)樣式動態(tài)切換功能,非常簡單實用,需要的朋友可以參考下2015-09-09jQuery EasyUI API 中文文檔 - NumberSpinner數(shù)值微調器使用介紹
jQuery EasyUI API 中文文檔 - NumberSpinner數(shù)值微調器使用,需要的朋友可以參考下。2011-10-10