<div class="codetitle"> <span><a style="CURSOR: pointer" data="25768" class="copybut" id="copybut25768" onclick="doCopy('code25768')"><u>复代码</u></a></span> 代码如下:</div> <div class="codebody" id="code25768"> <br><html xmlns="http://www.w3.org /1999/xhtml"> <br><head runat="server"> <br><title>jquery xml解析</title> <br><script src="jquery.min.js" type="text/javascript"></script> <br><script type="text/javascript"> <br>$(document).ready(function(){ <br>$.ajax({url:"City.xml", <br>success:function(xml){ <br>$(xml).find( "province").each(function(){ <br>var t = $(this).attr("name");//this-> <br>$("#DropProvince").append("< ;option>" t "</option>"); <br>}); <br>} <br>}); <br>$("#DropProvince").change(function(){ <br> $("#sCity>option").remove(); <br>var pname = $("#DropProvince").val() <br>$.ajax({url:"City.xml", <br>success:function(xml){ <br>$(xml).find("province[name='" pname "']>city").each(function(){ <br>$("#sCity" ).append("<option>" $(this).text() "</option>") <br>} <br>}); 🎜>}); <br></script> <br></head> <br><본문> <br><form id="form1"> <br><div> <br><select id="DropProvince" style="width:60px;"> <br><option>请选择</option> <br></select> <br><select id="sCity" style="width:60px;"> <br></select> <br></div> <br></form> <br></body> <br></html> <br><br><br><br>city.xml文件 </div> <br><strong><br></strong><div class="codetitle">复主代码<span><a style="CURSOR: pointer" data="17482" class="copybut" id="copybut17482" onclick="doCopy('code17482')"><u> 代码如下:</u></a></span><?xml version="1.0" 인코딩="utf-8" ?> </div><지방> <div class="codebody" id="code17482"><지방명="湖북"> <br><city>무汉</city> <br><city>黄stone</city> <br><city>宜昌</city> <br><city>天门</city> <br></지방> <br><지방 이름="湖南"> <br><city>邵阳</city> <br><city>长沙</city> <br><city>岳阳</city> <br></지방> <br><지방명="广东"> <br><city>广州</city> <br><city>深圳</city> <br></지방> <br></provinces><br><br> <br>其实主要是注意怎样在html界上解析xml文件,格式就是 <br> </div> <br><br><div class="codetitle">复代码<span><a style="CURSOR: pointer" data="95456" class="copybut" id="copybut95456" onclick="doCopy('code95456')"><u> 代码如下:</u></a> </span><script type="text/javascript"> </div>$(document).ready(function () { <div class="codebody" id="code95456">$.ajax({ <br>url: "City.xml", <br>success: function (xml) { <br>$(xml) .find("province").each(function () { <br>var t = $(this).attr("name"); <br>$("#DropProvince").append("<option> " t "</option>"); <br>}); <br>} <br>}); <br>$("#DropProvince").change(function () { <br>$(" #sCity>option").remove(); <br>var pname = $("#DropProvince").val(); <br>$.ajax({ <br>url: "City.xml", <br>성공: 함수(xml) { <br>$(xml).find("province[name='" pname "']>city").each(function(){ <br>$("#sCity" ).append("<option>" $(this).text() "</option>") <br>} <br>}); 🎜>}); <br></script> <br><br> <br>就是사용$.ajax()调用xml文件的内容。然后$.each()进行循环操작,基本思想就是这样的,成功之后去执行success这个回调函数。这里的xml文件是이용은 来存储数据的, 数据库中读取文件입니다.</div>