您好,登錄后才能下訂單哦!
- <script type="text/javascript">
- $(function(){
- linkage.init('state','country','city');
- linkage.init('state1','country1','city1');
- });
- </script>
- </head>
- <body >
- 出發(fā)地:
- <select id="state"></select>
- <select id="country"></select>
- <select id="city"></select>
- <br>
- 到達(dá)地:
- <select id="state1"></select>
- <select id="country1"></select>
- <select id="city1"></select>
- </body>
- 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 = "<option value="+data.id+">" + data.locationName + "</option>";
- 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<LocationBean> 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
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。