首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET Framework >

jquery 省市二级联动 怎么得到子节点值集合

2012-10-17 
jquery 省市二级联动 如何得到子节点值集合xml结构如下:provincetitle北京/titleitemcity东城/

jquery 省市二级联动 如何得到子节点值集合
xml结构如下:
  <province>
  <title>北京</title>
  <item>
  <city>东城</city>
  <city>西城</city>
  <city>崇文</city>
  <city>宣武</city>
  <city>朝阳</city>
  <city>丰台</city>
  <city>石景山</city>
  <city>海淀</city>
  <city>门头沟</city>
  <city>房山</city>
  <city>通州</city>
  <city>顺义</city>
  <city>昌平</city>
  <city>大兴</city>
  <city>平谷</city>
  <city>怀柔</city>
  <city>密云</city>
  <city>延庆</city>
  </item>
</province>
<province>
  <title>上海</title>
  <item>
  <city>黄浦</city>
  <city>卢湾</city>
  <city>徐汇</city>
  <city>长宁</city>
  <city>静安</city>
  <city>普陀</city>
  <city>闸北</city>
  <city>虹口</city>
  <city>杨浦</city>
  <city>闵行</city>
  <city>宝山</city>
  <city>嘉定</city>
  <city>浦东</city>
  <city>金山</city>
  <city>松江</city>
  <city>青浦</city>
  <city>南汇</city>
  <city>奉贤</city>
  <city>崇明</city>
  </item>
</province> <province>
  <title>北京</title>
  <item>
  <city>东城</city>
  <city>西城</city>
  <city>崇文</city>
  <city>宣武</city>
  <city>朝阳</city>
  <city>丰台</city>
  <city>石景山</city>
  <city>海淀</city>
  <city>门头沟</city>
  <city>房山</city>
  <city>通州</city>
  <city>顺义</city>
  <city>昌平</city>
  <city>大兴</city>
  <city>平谷</city>
  <city>怀柔</city>
  <city>密云</city>
  <city>延庆</city>
  </item>
</province>
<province>
  <title>上海</title>
  <item>
  <city>黄浦</city>
  <city>卢湾</city>
  <city>徐汇</city>
  <city>长宁</city>
  <city>静安</city>
  <city>普陀</city>
  <city>闸北</city>
  <city>虹口</city>
  <city>杨浦</city>
  <city>闵行</city>
  <city>宝山</city>
  <city>嘉定</city>
  <city>浦东</city>
  <city>金山</city>
  <city>松江</city>
  <city>青浦</city>
  <city>南汇</city>
  <city>奉贤</city>
  <city>崇明</city>
  </item>
</province>



选择省得到市,现在能得到省,确得不到相应的市,
//得到所有市
$(document).ready(function () {
  $.ajax({ url: "serverDoc.xml",
  success: function (xml) {
  $(xml).find("title").each(function () {
  var t = $(this).text(); //this->
  $("#DropProvince").append("<option>" + t + "</option>");
  });
  }
  });
//得到所有市,有问题。。。
  $("#DropProvince").change(function () {
  $("#sCity>option").remove();
  var pname = $("#DropProvince").val();
  $.ajax({ url: "serverDoc.xml",
  success: function (xml) {
  alert($("#DropProvince").val().find("item city").text());
  $(xml).find("province[val=" + pname + "] city").each(function () {
  $("#sCity").append("<option>" + $(this).text() + "</option>");
  });
  }
  });
  });
  });


 <select id="DropProvince" style="width:60px;">
  <option>请选择</option>
  </select>
  <select id="sCity" style="width:60px;">
  </select>

[解决办法]
崔永祥的省、市、地区联动选择,用起来不错,自己看
http://www.popub.net/script/PCAS.html
[解决办法]
网上很多的,找个自己感觉可以的就行

热点排行