citySetMe_V.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. function SelCity(obj, e) {
  2. $("#hcity").remove();
  3. $("#hproper").remove();
  4. $("#harea").remove();
  5. var ths = obj;
  6. 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>';
  7. Iput.show({
  8. id: ths,
  9. event: e,
  10. content: dal,
  11. width: "470"
  12. });
  13. $("#cColse").click(function() {
  14. Iput.colse()
  15. });
  16. var tb_province = [];
  17. var b = province;
  18. for (var i = 0,
  19. len = b.length; i < len; i++) {
  20. tb_province.push('<a data-id="' + b[i]['id'] + '" data-name="' + b[i]['name'] + '" title="' + b[i]['name'] + '">' + b[i]['name'] + '</a>')
  21. }
  22. $("#_citys0").append(tb_province.join(""));
  23. $("#_citys0 a").click(function() {
  24. var g = getCity($(this));
  25. $("#_citys1 a").remove();
  26. $("#_citys1").append(g);
  27. $("._citys1").hide();
  28. $("._citys1:eq(1)").show();
  29. $("#_citys0 a,#_citys1 a,#_citys2 a").removeClass("AreaS");
  30. $(this).addClass("AreaS");
  31. var lev = $(this).data("name");
  32. // ths.value = $(this).data("name");
  33. var pre = $(this).data("name");
  34. if( $(this).data("name")=="北京市"||$(this).data("name")=="天津市"||$(this).data("name")=="重庆市"||$(this).data("name")=="上海市"||$(this).data("name")=="台湾省"||$(this).data("name")=="香港特别行政区"||$(this).data("name")=="澳门特别行政区"){
  35. }
  36. $("#area").val("");
  37. if (document.getElementById("hcity") == null) {
  38. var hcitys = $('<input>', {
  39. type: 'hidden',
  40. name: "hcity",
  41. "data-id": $(this).data("id"),
  42. id: "hcity",
  43. val: lev
  44. });
  45. $(ths).after(hcitys)
  46. } else {
  47. $("#hcity").val(lev);
  48. $("#hcity").attr("data-id", $(this).data("id"))
  49. }
  50. $("#_citys1 a").click(function() {
  51. $("#_citys1 a,#_citys2 a").removeClass("AreaS");
  52. $(this).addClass("AreaS");
  53. var lev = $(this).data("name");
  54. if (document.getElementById("hproper") == null) {
  55. var hcitys = $('<input>', {
  56. type: 'hidden',
  57. name: "hproper",
  58. "data-id": $(this).data("id"),
  59. id: "hproper",
  60. val: lev
  61. });
  62. $(ths).after(hcitys)
  63. } else {
  64. $("#hproper").attr("data-id", $(this).data("id"));
  65. $("#hproper").val(lev)
  66. }
  67. var bc = $("#hcity").val();
  68. if( pre=="北京市"||pre=="天津市"||pre=="重庆市"||pre=="上海市"||pre=="台湾省"||pre=="香港特别行政区"||pre=="澳门特别行政区"){
  69. $("#area").val($(this).data("name"));
  70. }else{
  71. }
  72. var ar = getArea($(this));
  73. $("#_citys2 a").remove();
  74. if (ar == '') Iput.colse();
  75. $("#_citys2").append(ar);
  76. $("._citys1").hide();
  77. $("._citys1:eq(2)").show();
  78. $("#_citys2 a").click(function() {
  79. $("#_citys2 a").removeClass("AreaS");
  80. $(this).addClass("AreaS");
  81. var lev = $(this).data("name");
  82. if (document.getElementById("harea") == null) {
  83. var hcitys = $('<input>', {
  84. type: 'hidden',
  85. name: "harea",
  86. "data-id": $(this).data("id"),
  87. id: "harea",
  88. val: lev
  89. });
  90. $(ths).after(hcitys)
  91. } else {
  92. $("#harea").val(lev);
  93. $("#harea").attr("data-id", $(this).data("id"))
  94. }
  95. var bc = $("#hcity").val();
  96. var bp = $("#hproper").val();
  97. $("#area").val($(this).data("name"));
  98. Iput.colse()
  99. var value="";
  100. if($("#hcity").val()!=undefined){
  101. value=$("#hcity").val();
  102. }
  103. if($("#hproper").val()!=undefined){
  104. value=value+$("#hproper").val();
  105. }
  106. if($("#harea").val()!=undefined){
  107. value=value+$("#harea").val();
  108. }
  109. ths.value = value;
  110. })
  111. var value="";
  112. if($("#hcity").val()!=undefined){
  113. value=$("#hcity").val();
  114. }
  115. if($("#hproper").val()!=undefined){
  116. value=value+$("#hproper").val();
  117. }
  118. if($("#harea").val()!=undefined){
  119. value=value+$("#harea").val();
  120. }
  121. ths.value = value;
  122. })
  123. var value="";
  124. if($("#hcity").val()!=undefined){
  125. value=$("#hcity").val();
  126. }
  127. if($("#hproper").val()!=undefined){
  128. value=value+$("#hproper").val();
  129. }
  130. if($("#harea").val()!=undefined){
  131. value=value+$("#harea").val();
  132. }
  133. ths.value = value;
  134. })
  135. }
  136. function getCity(obj) {
  137. var c = obj.data('id');
  138. var e = province;
  139. var f = [];
  140. var g = '';
  141. for (var i = 0; i < e.length; i++) {
  142. if (e[i]['id'] == parseInt(c)) {
  143. f = e[i]['son'];
  144. break
  145. }
  146. }
  147. for (var j = 0; j < f.length; j++) {
  148. g += '<a data-id="' + f[j]['id'] + '" data-name="' + f[j]['name'] + '" title="' + f[j]['name'] + '">' + f[j]['name'] + '</a>'
  149. }
  150. $("#_citysheng").html('请选择城市');
  151. return g
  152. }
  153. function getArea(obj) {
  154. var c = obj.data('id');
  155. var e = province;
  156. var f = [];
  157. var g = '';
  158. for (var i = 0; i < e.length; i++) {
  159. for (var j = 0; j < e[i]['son'].length; j++) {
  160. if (e[i]['son'][j]['id'] == parseInt(c) && e[i]['son'][j]['sec']) {
  161. f = e[i]['son'][j]['sec'];
  162. break
  163. }
  164. }
  165. }
  166. if (f.length) {
  167. for (var k = 0; k < f.length; k++) {
  168. g += '<a data-id="' + f[k]['id'] + '" data-name="' + f[k]['name'] + '" title="' + f[k]['name'] + '">' + f[k]['name'] + '</a>'
  169. }
  170. }
  171. $("#_citysheng").html('请选择区县');
  172. return g
  173. }