日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java 省市区三级联动_AJAX省市区三级联动下拉菜单(java版)

發(fā)布時(shí)間:2023/12/9 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 省市区三级联动_AJAX省市区三级联动下拉菜单(java版) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

此小程序的功能主要是采用異步請(qǐng)求方式從數(shù)據(jù)庫(kù)中調(diào)取省市區(qū)信息顯示到下拉列表:

代碼如下:

建立數(shù)據(jù)庫(kù)中的代碼和一些配置文件信息就省略了,主要有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;

@Controller

public class ProvinceAction {

private int provinceid;

private int cityid;

@Resource

private AreasService as;

@Resource

private 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();

}

}

}

}

主要的功能代碼都在上面了,如有不懂的請(qǐng)聯(lián)系QQ:1037139984,祝大家都有好的發(fā)展,共同學(xué)習(xí),共同成長(zhǎng)。

總結(jié)

以上是生活随笔為你收集整理的java 省市区三级联动_AJAX省市区三级联动下拉菜单(java版)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。