citySetMe.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. var pre = $(this).data("name");
  31. if( $(this).data("name")=="北京市"||$(this).data("name")=="天津市"||$(this).data("name")=="重庆市"||$(this).data("name")=="上海市"||$(this).data("name")=="台湾省"||$(this).data("name")=="香港特别行政区"||$(this).data("name")=="澳门特别行政区"){
  32. ths.value = $(this).data("name");
  33. }
  34. $("#area").val("");
  35. if (document.getElementById("hcity") == null) {
  36. var hcitys = $('<input>', {
  37. type: 'hidden',
  38. name: "hcity",
  39. "data-id": $(this).data("id"),
  40. id: "hcity",
  41. val: lev
  42. });
  43. $(ths).after(hcitys)
  44. } else {
  45. $("#hcity").val(lev);
  46. $("#hcity").attr("data-id", $(this).data("id"))
  47. }
  48. $("#_citys1 a").click(function() {
  49. $("#_citys1 a,#_citys2 a").removeClass("AreaS");
  50. $(this).addClass("AreaS");
  51. var lev = $(this).data("name");
  52. if (document.getElementById("hproper") == null) {
  53. var hcitys = $('<input>', {
  54. type: 'hidden',
  55. name: "hproper",
  56. "data-id": $(this).data("id"),
  57. id: "hproper",
  58. val: lev
  59. });
  60. $(ths).after(hcitys)
  61. } else {
  62. $("#hproper").attr("data-id", $(this).data("id"));
  63. $("#hproper").val(lev)
  64. }
  65. var bc = $("#hcity").val();
  66. if( pre=="北京市"||pre=="天津市"||pre=="重庆市"||pre=="上海市"||pre=="台湾省"||pre=="香港特别行政区"||pre=="澳门特别行政区"){
  67. $("#area").val($(this).data("name"));
  68. }else{
  69. ths.value = $(this).data("name");
  70. }
  71. var ar = getArea($(this));
  72. $("#_citys2 a").remove();
  73. if (ar == '') Iput.colse();
  74. $("#_citys2").append(ar);
  75. $("._citys1").hide();
  76. $("._citys1:eq(2)").show();
  77. $("#_citys2 a").click(function() {
  78. $("#_citys2 a").removeClass("AreaS");
  79. $(this).addClass("AreaS");
  80. var lev = $(this).data("name");
  81. if (document.getElementById("harea") == null) {
  82. var hcitys = $('<input>', {
  83. type: 'hidden',
  84. name: "harea",
  85. "data-id": $(this).data("id"),
  86. id: "harea",
  87. val: lev
  88. });
  89. $(ths).after(hcitys)
  90. } else {
  91. $("#harea").val(lev);
  92. $("#harea").attr("data-id", $(this).data("id"))
  93. }
  94. var bc = $("#hcity").val();
  95. var bp = $("#hproper").val();
  96. $("#area").val($(this).data("name"));
  97. Iput.colse()
  98. })
  99. })
  100. })
  101. }
  102. function getCity(obj) {
  103. var c = obj.data('id');
  104. var e = province;
  105. var f = [];
  106. var g = '';
  107. for (var i = 0; i < e.length; i++) {
  108. if (e[i]['id'] == parseInt(c)) {
  109. f = e[i]['son'];
  110. break
  111. }
  112. }
  113. for (var j = 0; j < f.length; j++) {
  114. g += '<a data-id="' + f[j]['id'] + '" data-name="' + f[j]['name'] + '" title="' + f[j]['name'] + '">' + f[j]['name'] + '</a>'
  115. }
  116. $("#_citysheng").html('请选择城市');
  117. return g
  118. }
  119. function getArea(obj) {
  120. var c = obj.data('id');
  121. var e = province;
  122. var f = [];
  123. var g = '';
  124. for (var i = 0; i < e.length; i++) {
  125. for (var j = 0; j < e[i]['son'].length; j++) {
  126. if (e[i]['son'][j]['id'] == parseInt(c) && e[i]['son'][j]['sec']) {
  127. f = e[i]['son'][j]['sec'];
  128. break
  129. }
  130. }
  131. }
  132. if (f.length) {
  133. for (var k = 0; k < f.length; k++) {
  134. g += '<a data-id="' + f[k]['id'] + '" data-name="' + f[k]['name'] + '" title="' + f[k]['name'] + '">' + f[k]['name'] + '</a>'
  135. }
  136. }
  137. $("#_citysheng").html('请选择区县');
  138. return g
  139. }