AJAX三级联动省市选择,使用jquery+html+XML
来源:互联网 发布:linux查看系统重启时间 编辑:程序博客网 时间:2024/05/17 09:23
HTML代码
<html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>jquery结合ajax和xml实现省市县三级联动</title> <script src="/js/jquery-1.8.3.min.js" type="text/javascript"></script> <script src="/js/province_city_select/province_city.js" type="text/javascript"></script></head><body> <select id="province" name="province"> </select> <select id="city" name="city"> </select> <select id="area" name="area"> </select> <div> 地址是:<span id="pro_city"></span><input id="txtAdd" type="text" /> </div></body></html>
province_city.js内容
$(function () { var address = $("#pro_city"); var province = $("#province"); var city = $("#city"); var area = $("#area"); var preProvince = "<option value=\"\">选择省(市)</option>"; var preCity = "<option value=\"\">选择市(区)</option>"; var preArea = "<option value=\"\">选择区(县)</option>"; province.html(preProvince); city.html(preCity); area.html(preArea); $.ajax({ type: "GET", url: "/js/province_city_select/Info.xml", success: func_suc_getXmlProvice }); province.change(function () { if (province.val() != "") { city.html(preCity); $.ajax({ type: "GET", url: "/js/province_city_select/Info.xml", success: func_suc_getXmlCity }); city.change(); } }); city.change(function () { area.html(preArea); $.ajax({ type: "GET", url: "/js/province_city_select/Info.xml", success: func_suc_getXmlArea }); }); area.change(function () { var value = province.find("option:selected").text() + city.find("option:selected").text() + area.find("option:selected").text(); address.text(value); $("#txtProCity").val(value); }); function func_suc_getXmlProvice(xml) { var sheng = $(xml).find("prov"); sheng.each(function (i) { province.append("<option value=" + i + ">" + sheng.eq(i).attr("text") + "</option>"); }); } function func_suc_getXmlCity(xml) { var xml_sheng = $(xml).find("prov"); var pro_num = parseInt(province.val()); var xml_shi = xml_sheng.eq(pro_num).find("city"); xml_shi.each(function (j) { city.append("<option value=" + j + ">" + xml_shi.eq(j).attr("text") + "</option>"); }); } function func_suc_getXmlArea(xml) { var xml_sheng = $(xml).find("prov"); var pro_num = parseInt(province.val()); var xml_shi = xml_sheng.eq(pro_num).find("city"); var city_num = parseInt(city.val()); var xml_xianqu = xml_shi.eq(city_num).find("county"); xml_xianqu.each(function (k) { area.append("<option value=" + k + ">" + xml_xianqu.eq(k).attr("text") + "</option>"); }); }});
Info.xml内容是中国的省市列表,有点大,完整版到这里下载
http://download.csdn.net/detail/ful1021/6555541
或者留下邮箱发送
<?xml version="1.0" encoding="gb2312"?><district><prov id="110000" text="北京市"><city id="110100" text="市辖区"><county id="110101" text="东城区"></county><county id="110102" text="西城区"></county><county id="110103" text="崇文区"></county><county id="110104" text="宣武区"></county><county id="110105" text="朝阳区"></county><county id="110106" text="丰台区"></county><county id="110107" text="石景山区"></county><county id="110108" text="海淀区"></county><county id="110109" text="门头沟区"></county><county id="110111" text="房山区"></county><county id="110112" text="通州区"></county><county id="110113" text="顺义区"></county><county id="110114" text="昌平区"></county><county id="110115" text="大兴区"></county><county id="110116" text="怀柔区"></county><county id="110117" text="平谷区"></county></city><city id="110200" text="县"><county id="110228" text="密云县"></county><county id="110229" text="延庆县"></county></city></prov></district>
云天博客:www.yuntianseo.com 专注于网络营销推广
- AJAX三级联动省市选择,使用jquery+html+XML
- jQuery ajax实现省市县三级联动
- jquery+xml+ajax 省市多级联动
- ajax实现省市三级联动
- ajax省市县三级联动
- ajax三级联动省市选择器
- jquery+php+mysql实现Ajax省市县三级联动
- jquery ajax(2)-----获取省市县/区三级联动
- jQuery解析xml文件,使用get方法实现省市县三级联动下拉框
- 省市县三级联动xml
- jquery读取xml文件实现省市县三级联动
- jquery json 三级省市联动
- jquery插件省市三级联动
- jquery AJAX 省市联动
- 使用AJAX+php+mysql实现省市县三级联动
- 使用javascript解析xml实现省市县三级联动
- jquery ajax 三级联动
- jQuery Ajax三级联动
- U盘制作Mac系统启动盘图文教程
- 【C#】监视U盘的插入与拔出
- Hadoop2.0 YARN cloudra4.4.0安装配置
- mmap
- shell脚本中字符串比较经常遇到的一个问题
- AJAX三级联动省市选择,使用jquery+html+XML
- 字符设备驱动小计
- Sicily1211(矩阵相乘)
- C++与JAVA语言区别
- 如何优化移动网站,快速响应如本地应用
- Hadoop2.0 YARN cloudra4.4.0 WordCount实例
- 11.14C程序设计语言--指针类型
- Ubuntu 12.04安装Go语言运行环境,第一个程序Hello world
- 水