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

首頁 > 編程 > Java > 正文

AJAX省市區三級聯動下拉菜單(java版)

2019-11-26 14:40:57
字體:
來源:轉載
供稿:網友

此小程序的功能主要是采用異步請求方式從數據庫中調取省市區信息顯示到下拉列表:

代碼如下:

建立數據庫中的代碼和一些配置文件信息就省略了,主要有JavaScript中的代碼為:

$(document).ready(function(){$.get("getProvince.do", function(result){$("#showp").html(result);});})var xmlhttp;function mysend(str){$(document).ready(function(){$("#show2").html("");})var show = document.getElementByIdx_x_x_x_x_x_x_x_x_x("show");show.innerHTML = "";var province = document.getElementByIdx_x_x_x_x_x_x_x_x_x("province").value;if(province!=0){if(window.XMLHttpRequest){xmlhttp = new XMLHttpRequest();}else{xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4 && xmlhttp.status==200){show.innerHTML = xmlhttp.responseText;}}var ss = encodeURIComponent(str);xmlhttp.open("GET","getCity.do?provinceid="+ss,true);xmlhttp.send(null);}}function myarea(str){if(window.XMLHttpRequest){xmlhttp = new XMLHttpRequest();}else{xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4 && xmlhttp.status==200){var show2 = document.getElementByIdx_x_x_x_x_x_x_x_x_x("show2");show2.innerHTML = xmlhttp.responseText;}}var ss = encodeURIComponent(str);xmlhttp.open("GET","getArea.do?cityid="+ss,true);xmlhttp.send(null);}

html頁面中的代碼為:

所在地

action中的代碼為:

package mobi.zhangsheng.jiejia.action;import java.io.IOException;import java.io.PrintWriter;import java.util.List;import javax.annotation.Resource;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts2.ServletActionContext;import org.springframework.stereotype.Controller;import mobi.zhangsheng.jiejia.domain.Areas;import mobi.zhangsheng.jiejia.service.AgentsService;import mobi.zhangsheng.jiejia.service.AreasService;@Controllerpublic class ProvinceAction {private int provinceid;private int cityid;@Resourceprivate AreasService as;@Resourceprivate AgentsService ags;public int getProvinceid() {return provinceid;}public void setProvinceid(int provinceid) {this.provinceid = provinceid;}public int getCityid() {return cityid;}public void setCityid(int cityid) {this.cityid = cityid;}public void getProvince(){List provinceList = as.getAreasPrvinceList();HttpServletResponse resp= ServletActionContext.getResponse();HttpServletRequest request = ServletActionContext.getRequest();//resp.setContentType("xml");resp.setContentType("text/html");resp.setCharacterEncoding("utf-8");try {PrintWriter out = resp.getWriter();out.print("");//out.print("shanghai");} catch (IOException e) {e.printStackTrace();}}public void getCity(){List cityList = as.getAreasCityList(provinceid);HttpServletResponse resp= ServletActionContext.getResponse();//resp.setContentType("xml");resp.setContentType("text/html");resp.setCharacterEncoding("utf-8");try {PrintWriter out = resp.getWriter();out.print("");//out.print("shanghai");} catch (IOException e) {e.printStackTrace();}}public void getArea(){List areaList = as.getAreasCityList(cityid);if(areaList.size()==0){}else{HttpServletResponse resp= ServletActionContext.getResponse();resp.setContentType("text/html");resp.setCharacterEncoding("utf-8");try {PrintWriter out = resp.getWriter();out.print("");} catch (IOException e) {e.printStackTrace();}}}}

主要的功能代碼都在上面了,如有不懂的請聯系QQ:1037139984,祝大家都有好的發展,共同學習,共同成長。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 巢湖市| 郸城县| 大同县| 华池县| 女性| 循化| 陵川县| 四川省| 台前县| 鄂尔多斯市| 红原县| 监利县| 阿拉善右旗| 行唐县| 崇仁县| 班戈县| 丰镇市| 吉安市| 藁城市| 赤峰市| 通化市| 双城市| 西乌珠穆沁旗| 衡南县| 镇安县| 迭部县| 台中县| 彩票| 宜丰县| 三穗县| 嫩江县| 玉树县| 涟源市| 西安市| 菏泽市| 墨玉县| 达拉特旗| 景德镇市| 东平县| 祁门县| 灵丘县|