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

首頁 > 編程 > JavaScript > 正文

利用了jquery的ajax實現(xiàn)二級聯(lián)互動菜單

2019-11-20 21:32:19
字體:
來源:轉載
供稿:網友
菜單資源保存在數(shù)據(jù)庫中。利用了jquery的ajax實現(xiàn)。用到的包有:json-lib-2.2.3-jdk15.jar ezmorph-1.0.6.jar json.js jquery.js

jsp頁面的代碼:
復制代碼 代碼如下:

<%@ page contentType="text/html; charset=gbk"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/json.js"></script>
<% String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";
out.println(basePath);
%>

<script type="text/javascript">
jQuery(function($){
//alert("ok");
});
function onchangeShow(oneId){
$.ajax({
url : "<%=basePath%>cateJson.whbs",
data : {parentId : oneId}, // 參數(shù)
type : "post",
cache : false,
dataType : "json", //返回json數(shù)據(jù)
error: function(){
alert('error');
},
success:onchangecallback
});
}
function onchangecallback(data){
document.all['twoId'].options.length = 0; //清空原有的option
var str="";
for(var i=0;i<data.length;i++){
str+="<option value='"+data[i].recordId+"'>"+data[i].title+"</option>"
}
$("#twoId").html(str);
}
</script>
<html>
<body>
<div align="center">
請選擇部門類型
<s:select list="rfones" listKey="recordId" listValue="title" name="oneId" theme="simple" id="oneId" value="oneID" onchange="onchangeShow(this.value)"></s:select>

請選擇文件類型
<s:select list="rftwos" listKey="recordId" listValue="title" name="twoId" theme="simple" id="twoId" value="twoID"></s:select>
</div>
</body>
</html>

struts中action的代碼
復制代碼 代碼如下:

/**
* des:取得二級聯(lián)動菜單
* autho:exceljava
* date:Nov 20, 2009
* @return
* @throws IOException
*/
public String getJsonCategory() throws IOException{
rfjsons=archiveService.getCategoryByParentID(parentId);//這里從數(shù)據(jù)庫取得數(shù)據(jù)
net.sf.json.JSONArray jsonObj=net.sf.json.JSONArray.fromObject(rfjsons);//組裝成json數(shù)據(jù)
sendMessage(jsonObj.toString());//向視圖push json數(shù)據(jù)
return null;
}
/**
* des:封裝發(fā)送json格式的數(shù)據(jù)回js
* autho:exceljava
* date:Nov 20, 2009
* @param content
* @throws IOException
*/
public void sendMessage(String content) throws IOException{
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("UTF-8");
response.getWriter().write(content);

}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 会同县| 容城县| 安远县| 青田县| 临漳县| 玉门市| 汝阳县| 英吉沙县| 阜南县| 灵川县| 红河县| 泰州市| 齐河县| 伊川县| 历史| 甘洛县| 米林县| 余江县| 子洲县| 莱西市| 北安市| 云阳县| 新龙县| 三原县| 宁武县| 图片| 固原市| 布拖县| 孟州市| 偃师市| 虹口区| 连山| 达孜县| 阜阳市| 梅河口市| 万宁市| 汉沽区| 吐鲁番市| 阿荣旗| 横峰县| 灵武市|