citySet.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. function SelCity(obj, e) {
  2. var ths = obj;
  3. var dal = '<div class="_citys"><span title="关闭" id="cColse" >×</span><div id="_citysheng" class="_citys0">请选择省份</div><div id="_citys0" class="_citys1"></div><div style="display:none" id="_citys1" class="_citys1"></div><div style="display:none" id="_citys2" class="_citys1"></div></div>';
  4. Iput.show({
  5. id: ths,
  6. event: e,
  7. content: dal,
  8. width: "470"
  9. });
  10. $("#cColse").click(function() {
  11. Iput.colse()
  12. });
  13. var tb_province = [];
  14. var b = province;
  15. for (var i = 0,
  16. len = b.length; i < len; i++) {
  17. tb_province.push('<a data-id="' + b[i]['id'] + '" data-name="' + b[i]['name'] + '" title="' + b[i]['name'] + '">' + b[i]['name'] + '</a>')
  18. }
  19. $("#_citys0").append(tb_province.join(""));
  20. $("#_citys0 a").click(function() {
  21. var g = getCity($(this));
  22. $("#_citys1 a").remove();
  23. $("#_citys1").append(g);
  24. $("._citys1").hide();
  25. $("._citys1:eq(1)").show();
  26. $("#_citys0 a,#_citys1 a,#_citys2 a").removeClass("AreaS");
  27. $(this).addClass("AreaS");
  28. var lev = $(this).data("name");
  29. ths.value = $(this).data("name");
  30. if (document.getElementById("hcity") == null) {
  31. var hcitys = $('<input>', {
  32. type: 'hidden',
  33. name: "hcity",
  34. "data-id": $(this).data("id"),
  35. id: "hcity",
  36. val: lev
  37. });
  38. $(ths).after(hcitys)
  39. } else {
  40. $("#hcity").val(lev);
  41. $("#hcity").attr("data-id", $(this).data("id"))
  42. }
  43. $("#_citys1 a").click(function() {
  44. $("#_citys1 a,#_citys2 a").removeClass("AreaS");
  45. $(this).addClass("AreaS");
  46. var lev = $(this).data("name");
  47. if (document.getElementById("hproper") == null) {
  48. var hcitys = $('<input>', {
  49. type: 'hidden',
  50. name: "hproper",
  51. "data-id": $(this).data("id"),
  52. id: "hproper",
  53. val: lev
  54. });
  55. $(ths).after(hcitys)
  56. } else {
  57. $("#hproper").attr("data-id", $(this).data("id"));
  58. $("#hproper").val(lev)
  59. }
  60. var bc = $("#hcity").val();
  61. ths.value = bc + "/" + $(this).data("name");
  62. var ar = getArea($(this));
  63. $("#_citys2 a").remove();
  64. if (ar == '') Iput.colse();
  65. $("#_citys2").append(ar);
  66. $("._citys1").hide();
  67. $("._citys1:eq(2)").show();
  68. $("#_citys2 a").click(function() {
  69. $("#_citys2 a").removeClass("AreaS");
  70. $(this).addClass("AreaS");
  71. var lev = $(this).data("name");
  72. if (document.getElementById("harea") == null) {
  73. var hcitys = $('<input>', {
  74. type: 'hidden',
  75. name: "harea",
  76. "data-id": $(this).data("id"),
  77. id: "harea",
  78. val: lev
  79. });
  80. $(ths).after(hcitys)
  81. } else {
  82. $("#harea").val(lev);
  83. $("#harea").attr("data-id", $(this).data("id"))
  84. }
  85. var bc = $("#hcity").val();
  86. var bp = $("#hproper").val();
  87. ths.value = bc + "/" + bp + "/" + $(this).data("name");
  88. Iput.colse()
  89. })
  90. })
  91. })
  92. }
  93. function getCity(obj) {
  94. var c = obj.data('id');
  95. var e = province;
  96. var f = [];
  97. var g = '';
  98. for (var i = 0; i < e.length; i++) {
  99. if (e[i]['id'] == parseInt(c)) {
  100. f = e[i]['son'];
  101. break
  102. }
  103. }
  104. for (var j = 0; j < f.length; j++) {
  105. g += '<a data-id="' + f[j]['id'] + '" data-name="' + f[j]['name'] + '" title="' + f[j]['name'] + '">' + f[j]['name'] + '</a>'
  106. }
  107. $("#_citysheng").html('请选择城市');
  108. return g
  109. }
  110. function getArea(obj) {
  111. var c = obj.data('id');
  112. var e = province;
  113. var f = [];
  114. var g = '';
  115. for (var i = 0; i < e.length; i++) {
  116. for (var j = 0; j < e[i]['son'].length; j++) {
  117. if (e[i]['son'][j]['id'] == parseInt(c) && e[i]['son'][j]['sec']) {
  118. f = e[i]['son'][j]['sec'];
  119. break
  120. }
  121. }
  122. }
  123. if (f.length) {
  124. for (var k = 0; k < f.length; k++) {
  125. g += '<a data-id="' + f[k]['id'] + '" data-name="' + f[k]['name'] + '" title="' + f[k]['name'] + '">' + f[k]['name'] + '</a>'
  126. }
  127. }
  128. $("#_citysheng").html('请选择区县');
  129. return g
  130. }