jQuery 解析xml文件
今天给大家分享的是由图老师小编精心为您推荐的jQuery 解析xml文件,喜欢的朋友可以分享一下,也算是给小编一份支持,大家都不容易啊!
html xmlns="http://www.w3.org/1999/xhtml"
head runat="server"
titlejquery xml解析/title
script src="jquery.min.js" type="text/javascript"/script
script type="text/javascript"
$(document).ready(function(){
$.ajax({url:"City.xml",
success:function(xml){
$(xml).find("province").each(function(){
var t = $(this).attr("name");//this-
$("#DropProvince").append("option"+t+"/option");
});
}
});
$("#DropProvince").change(function(){
$("#sCityoption").remove();
var pname = $("#DropProvince").val();
$.ajax({url:"City.xml",
success:function(xml){
$(xml).find("province[name='"+pname+"']city").each(function(){
$("#sCity").append("option"+$(this).text()+"/option");
});
}
});
});
});
/script
/head
body
form id="form1"
div
select id="DropProvince" style="width:60px;"
option请选择/option
/select
select id="sCity" style="width:60px;"
/select
/div
/form
/body
/html
city.xml文件
代码如下:
?xml version="1.0" encoding="utf-8" ?
provinces
province name="湖北"
city武汉/city
city黄石/city
city宜昌/city
city天门/city
/province
province name="湖南"
city邵阳/city
city长沙/city
city岳阳/city
/province
province name="广东"
city广州/city
city深圳/city
/province
/provinces