- <html>
- <head>
- <title>jquery xml解析</title>
- <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
- <script type="text/javascript">
- $(document).ready(
- function() {
- $.ajax( {
- url : "xx.xml",
- success : function(xml) {
- $(xml).find("province").each(function() {
- var t = $(this).attr("name");//this->
- $("#DropProvince").append(
- "<option>" + t + "</option>");
- });
- }
- });
- $("#DropProvince").change(
- function() {
- $("#sCity>option").remove();
- var pname = $("#DropProvince").val();
- $.ajax( {
- url : "xx.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=" 60px;">
- <option>请选择</option>
- </select>
- <select id="sCity" style=" 60px;">
- </select>
- </div>
- </form>
- </body>
- </html>