ITeye博客

struts2+ajax做的一个级联下拉列表

bh三少 · 2010-09-20 14:47 · 开发笔记 · Web前端 · HTML · CSS · Ajax · Struts · json · Markdown

struts2+ajax做的一个级联下拉列表 struts端代码: /** * 級聯顯示社群的資訊類別 * @return */ public String showNewsType() { newsTypeList = associationNewsTypeService.showNewsTypeListByAssnId(associationId); return SUCCESS; } struts配置文件代码: ajax代码: /** *級聯下拉列表顯示 */ function showNewsType(newsTypeId) { var parent = document.getElementById("synAssociationSelect"); var associationId = parent.options[parent.selectedIndex].value; if(associationId == 0) { $("#newsTypeSelectTd").css("display","none"); } else { var params = {"associationId":associationId}; $.ajax({ type : "post", url : "/government/showNewsType", async : false, data : params, dataType : "json", success : function(json) { var newsTypeSel = document.getElementById("newsTypeSelect"); newsTypeSel.length = 0; if(json.newsTypeList.length == 0) { newsTypeSel.options.add(new Option("該社群沒有資訊分類", 0)); } for(var i = 0; i < json.newsTypeList.length; i++) { if(json.newsTypeList[i].typeId == newsTypeId) { newsTypeSel.options.add(new Option(json.newsTypeList[i].typeName, json.newsTypeList[i].typeId, 'seleted')); } else { newsTypeSel.options.add(new Option(json.newsTypeList[i].typeName, json.newsTypeList[i].typeId)); } } } }); $("#newsTypeSelectTd").css("display","block"); } } html代码: 同步社群: #if($userAssociationList.size() > 0) --請選擇-- #foreach($userAssociation in $userAssociationList) $!{userAssociation.associationName} #end #else --您還沒有加入社群-- #end

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。