- 出發(fā)地:
- 到達(dá)地:
創(chuàng)新互聯(lián)是一家專業(yè)提供饒河企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)、成都h5網(wǎng)站建設(shè)、小程序制作等業(yè)務(wù)。10年已為饒河眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站設(shè)計(jì)公司優(yōu)惠進(jìn)行中。
- function linkage(){}
- $(function(){
- //linkage.init("state","country","city");
- });
- linkage.init = function(levelOne, levelTwo, levelThree){
- linkage.data = [];
- levelOne = "#" + levelOne;
- levelTwo = "#" + levelTwo;
- levelThree = "#" + levelThree;
- var html = "";
- var url = "linkage.action";//訪問地址
- //JQuery訪問數(shù)據(jù)
- $.getJSON(url, function(data){
- linkage.data = data;
- $(levelOne).html(linkage.getOptionHtmlByLevel(1));//洲區(qū)域信息
- $(levelTwo).html(linkage.getOptionHtmlById($(levelOne).val()));//國家信息
- $(levelThree).html(linkage.getOptionHtmlById($(levelTwo).val()));//城市信息
- // 為下拉levelOne框綁定onchange事件
- $(levelOne).change(function(){
- $(levelTwo).html(linkage.getOptionHtmlById($(levelOne).val()));//國家信息
- $(levelThree).html(linkage.getOptionHtmlById($(levelTwo).val()));//城市信息
- });
- // 為下拉levelTwo框綁定onchange事件
- $(levelTwo).change(function(){
- $(levelThree).html(linkage.getOptionHtmlById($(levelTwo).val()));//城市信息
- });
- });
- };
- /**
- * 獲得下拉框的選項(xiàng)html
- * @param data
- * @return html
- */
- linkage.getOptionHtml = function(data){
- var html = "";
- html = "";
- return html;
- };
- /**
- * 根據(jù)副ID查找數(shù)據(jù)
- * @param subId
- * @return html
- */
- linkage.getOptionHtmlById = function(subId){
- var html = "";
- for(i = 0 ; i < linkage.data.length ; i++){
- if(linkage.data[i].subId == subId){
- html += linkage.getOptionHtml(linkage.data[i]);
- }
- }
- return html;
- };
- /**
- * 根據(jù)區(qū)域級別查找數(shù)據(jù)
- * @param level
- * @return html
- */
- linkage.getOptionHtmlByLevel = function(level){
- var html = "";
- for(i = 0 ; i < linkage.data.length ; i++){
- if(linkage.data[i].locationLevel == level){
- html += linkage.getOptionHtml(linkage.data[i]);
- }
- }
- return html;
- };
- public void getAllLocationInfo(){
- List
locationList = this.linkageService.findAllLocation(); - HttpServletResponse response = (HttpServletResponse)ActionContext.getContext().get(ServletActionContext.HTTP_RESPONSE);
- HttpServletRequest request = (HttpServletRequest)ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
- try {
- request.setCharacterEncoding("utf-8");
- response.setCharacterEncoding("utf-8");
- JSONArray json = JSONArray.fromObject(locationList);
- response.getWriter().write(json.toString());
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
注意:此用到了JSON轉(zhuǎn)換包
jar包:json-lib-0.4.jar,commons-beanutils.jar