最新文章專題視頻專題問(wèn)答1問(wèn)答10問(wèn)答100問(wèn)答1000問(wèn)答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問(wèn)答文章1 問(wèn)答文章501 問(wèn)答文章1001 問(wèn)答文章1501 問(wèn)答文章2001 問(wèn)答文章2501 問(wèn)答文章3001 問(wèn)答文章3501 問(wèn)答文章4001 問(wèn)答文章4501 問(wèn)答文章5001 問(wèn)答文章5501 問(wèn)答文章6001 問(wèn)答文章6501 問(wèn)答文章7001 問(wèn)答文章7501 問(wèn)答文章8001 問(wèn)答文章8501 問(wèn)答文章9001 問(wèn)答文章9501
當(dāng)前位置: 首頁(yè) - 科技 - 知識(shí)百科 - 正文

解決Jquery下拉框數(shù)據(jù)動(dòng)態(tài)獲取的問(wèn)題

來(lái)源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 22:21:11
文檔

解決Jquery下拉框數(shù)據(jù)動(dòng)態(tài)獲取的問(wèn)題

解決Jquery下拉框數(shù)據(jù)動(dòng)態(tài)獲取的問(wèn)題:廢話不多說(shuō),直接上源碼: select.jsp <%@ page language=java import=java.util.* pageEncoding=UTF-8%> <% String path = request.getContextPath(); String basePath = request.ge
推薦度:
導(dǎo)讀解決Jquery下拉框數(shù)據(jù)動(dòng)態(tài)獲取的問(wèn)題:廢話不多說(shuō),直接上源碼: select.jsp <%@ page language=java import=java.util.* pageEncoding=UTF-8%> <% String path = request.getContextPath(); String basePath = request.ge

廢話不多說(shuō),直接上源碼:

select.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
 <base href="<%=basePath%>" rel="external nofollow" >
 
 <title>My JSP 'select.jsp' starting page</title>
 
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0"> 
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css" rel="external nofollow" >
	-->
	<script type="text/javascript" src="js/jquery-2.1.1.min.js" charset="utf-8"></script>
	<script type="text/javascript">
	
	function get_app_type() {
	
	$.ajax({
	type: "post",
	url: "AppTypeShow.action", //獲取json數(shù)據(jù)
	dataType: "json",
	success: function(data) {
	var d = eval("(" + data + ")");
	for(var i = 0; i < d.length; i++) {
	var id = d[i].id;
	var name = d[i].name;
	var opt = "<option value='" + id + "'>" + name + "</option>";
	$("#appType").append(opt);
	}
	},
	error: function() {
	alert("系統(tǒng)異常,請(qǐng)稍后再試!")
	}
	});
	
	}
	
	function get_app_class() {
	
	$.ajax({
	type: "post",
	url: "AppClassShow.action",
	dataType: "json",
	success: function(data) {
	var d = eval("(" + data + ")");
	for(var i = 0; i < d.length; i++) {
	var id = d[i].id;
	var name = d[i].name;
	var opt = "<option value='" + id + "'>" + name + "</option>";
	$("#appClass").append(opt);
	}
	},
	error: function() {
	alert("系統(tǒng)異常,請(qǐng)稍后再試!")
	}
	});
	
	}
	
	$(document).ready(function() {
	
	get_app_type();
	get_app_class();
	
	});
	</script>
 </head>
 
 <body>
 <table>
 	<tr>
	<td align="right">APP類型:</td>
	<td align="left">
	<select name="appType" id="appType" 
	style="margin-left: 16px; height: 30px; width: 110px; text-align: left; size: 3; color: #505050;">
 	<option value="-1">---請(qǐng)選擇---</option>
 	</select>
	</td>
	</tr>
	<tr height="25px"><td> </td></tr>
	<tr>
	<td align="right">APP種類:</td>
	<td align="left">
	<select name="appClass" id="appClass" 
	style="margin-left: 16px; height: 30px; width: 110px; text-align: left; size: 3; color: #505050;">
 	<option value="-1">---請(qǐng)選擇---</option>
 	</select>
	</td>
	</tr>
 </table>
 </body>
</html>

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
	<constant name="struts.i18n.encoding" value="UTF-8"></constant>
	<package name="simpleton" extends="struts-default,json-default">
	
	<action name="*JsonAction" method="{1}"
	class="jquery.chisj.action.JsonAction">
	<result name="fail">error.jsp</result>
	<result type="json">
	<param name="root">result</param>
	</result>
	
	</action>
	
	<action name="AppTypeShow"
	class="jquery.chisj.action.NtAppAction"
	method="appTypeShow">
	<result name="fail">error.jsp</result>
	<result type="json">
	<param name="root">result</param>
	</result>
	</action>
	
	<action name="AppClassShow"
	class="jquery.chisj.action.NtAppAction"
	method="appClassShow">
	<result name="fail">error.jsp</result>
	<result type="json">
	<param name="root">result</param>
	</result>	
	</action>
	
	</package>
</struts> 

NtAppAction.java

/**
 * 
 */
package jquery.chisj.action;
import java.util.ArrayList;
import java.util.List;
import jquery.chisj.entity.APPClass;
import jquery.chisj.entity.APPType;
import com.opensymphony.xwork2.ActionSupport;
import net.sf.json.JSONArray;
/**
 * @ClassName: NtAppAction
 * @Description: TODO
 * @Author: chisj chisj@foxmail.com
 * @Date 2016年1月20日 下午4:53:50
 *
 */
public class NtAppAction extends ActionSupport {
	private String result;
	
	public String appTypeShow() {
	System.out.println("---app type show---");
	List<APPType> appTypeList = new ArrayList<APPType>();
	try {
	APPType appType_1 = new APPType();
	APPType appType_2 = new APPType();
	appType_1.setId(Short.valueOf("1"));
	appType_1.setName("Android");
	appType_2.setId(Short.valueOf("2"));
	appType_2.setName("iOS");
	appTypeList.add(appType_1);
	appTypeList.add(appType_2);
	JSONArray jsonArray = JSONArray.fromObject(appTypeList);
	result = String.valueOf(jsonArray);
	} catch (Exception e) {
	e.printStackTrace();
	}
	
	return SUCCESS;
	}
	
	public String appClassShow() {
	System.out.println("---app class show---");
	List<APPClass> appClassList = new ArrayList<APPClass>();
	try {
	APPClass appClass_1 = new APPClass();
	APPClass appClass_2 = new APPClass();
	appClass_1.setId(Short.valueOf("1"));
	appClass_1.setName("種類1");
	appClass_2.setId(Short.valueOf("2"));
	appClass_2.setName("種類2");
	appClassList.add(appClass_1);
	appClassList.add(appClass_2);
	JSONArray jsonArray = JSONArray.fromObject(appClassList);
	result = String.valueOf(jsonArray);
	} catch (Exception e) {
	e.printStackTrace();
	}
	
	return SUCCESS;
	}
	
	public String getResult() {
	return result;
	}
	
	public void setResult(String result) {
	this.result = result;
	}
	
}

以上這篇解決Jquery下拉框數(shù)據(jù)動(dòng)態(tài)獲取的問(wèn)題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

解決Jquery下拉框數(shù)據(jù)動(dòng)態(tài)獲取的問(wèn)題

解決Jquery下拉框數(shù)據(jù)動(dòng)態(tài)獲取的問(wèn)題:廢話不多說(shuō),直接上源碼: select.jsp <%@ page language=java import=java.util.* pageEncoding=UTF-8%> <% String path = request.getContextPath(); String basePath = request.ge
推薦度:
  • 熱門焦點(diǎn)

最新推薦

猜你喜歡

熱門推薦

專題
Top