jquery 读取xml数据示例

  1. <html>
  2. <head>
  3. <title>jquery xml解析</title>
  4. <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
  5. <script type="text/javascript">
  6. $(document).ready(
  7. function() {
  8. $.ajax( {
  9. url : "xx.xml",
  10. success : function(xml) {
  11. $(xml).find("province").each(function() {
  12. var t = $(this).attr("name");//this->
  13. $("#DropProvince").append(
  14. "<option>" + t + "</option>");
  15. });
  16. }
  17. });
  18. $("#DropProvince").change(
  19. function() {
  20. $("#sCity>option").remove();
  21. var pname = $("#DropProvince").val();
  22. $.ajax( {
  23. url : "xx.xml",
  24. success : function(xml) {
  25. $(xml).find(
  26. "province[name='" + pname
  27. + "']>city").each(
  28. function() {
  29. $("#sCity").append(
  30. "<option>"
  31. + $(this)
  32. .text()
  33. + "</option>");
  34. });
  35. }
  36. });
  37. });
  38. });
  39. </script>
  40. </head>
  41. <body>
  42. <form >
  43. <div>
  44. <select >
  45. <option>请选择</option>
  46. </select>
  47. <select >
  48. </select>
  49. </div>
  50. </form>
  51. </body>
  52. </html>