jquery.listitem.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /* ============================================================
  2. * jquery.listitem.js 下拉列表选择
  3. * ============================================================ */
  4. !function($) {
  5. // 个人简历年份 相关
  6. var birthdayDate = new Date();
  7. var byear = birthdayDate.getFullYear();
  8. byear = byear - 16;
  9. var byearMin = byear - 49;
  10. var htmlYear = '', htmlYear1 = '', htmlYear2 = '';
  11. for (var i = byear; i >= byearMin; i--) {
  12. if (i > (byear-20)) {
  13. htmlYear += [
  14. '<li>',
  15. '<a class="J_listitme" href="javascript:;" data-code="' + i + '">' + i + '</a>',
  16. '</li>'
  17. ].join('');
  18. } else if (i > (byear-40)) {
  19. htmlYear1 += [
  20. '<li>',
  21. '<a class="J_listitme" href="javascript:;" data-code="' + i + '">' + i + '</a>',
  22. '</li>'
  23. ].join('');
  24. } else {
  25. htmlYear2 += [
  26. '<li>',
  27. '<a class="J_listitme" href="javascript:;" data-code="' + i + '">' + i + '</a>',
  28. '</li>'
  29. ].join('');
  30. }
  31. }
  32. $('.J_birthdy').each(function(index, el) {
  33. var $thisBirthdys = $(this).find('.J_birthday_box');
  34. $thisBirthdys.eq(0).html(htmlYear);
  35. $thisBirthdys.eq(1).html(htmlYear1);
  36. $thisBirthdys.eq(2).html(htmlYear2);
  37. $(this).closest('.J_listitme_parent').find('.J_birthday_prev').hide();
  38. })
  39. // 点击翻页
  40. $('.J_birthday_next').on('click', function(event) {
  41. var $thisParent = $(this).closest('.J_listitme_parent');
  42. var $thisBox = $thisParent.find('.J_birthday_box');
  43. var sub = 0; // 获取选中tab的下标
  44. $thisBox.each(function(index, el) {
  45. if ($(this).hasClass('active')) {
  46. sub = index;
  47. }
  48. })
  49. $thisBox.eq(sub+1).addClass("active").siblings(".J_birthday_box").removeClass("active");
  50. if (sub == 1) {
  51. $thisParent.find('.J_birthday_next').hide();
  52. }
  53. $thisParent.find('.J_birthday_prev').show();
  54. event.stopPropagation();
  55. })
  56. $('.J_birthday_prev').on('click', function(event) {
  57. var $thisParent = $(this).closest('.J_listitme_parent');
  58. var $thisBox = $thisParent.find('.J_birthday_box');
  59. var sub = 0; // 获取选中tab的下标
  60. $thisBox.each(function(index, el) {
  61. if ($(this).hasClass('active')) {
  62. sub = index;
  63. }
  64. });
  65. $thisBox.eq(sub-1).addClass("active").siblings(".J_birthday_box").removeClass("active");
  66. if (sub == 1) {
  67. $thisParent.find('.J_birthday_prev').hide();
  68. }
  69. $thisParent.find('.J_birthday_next').show();
  70. event.stopPropagation();
  71. })
  72. // 教育经历等相关年份
  73. var experienceDate = new Date();
  74. var eyear = experienceDate.getFullYear();
  75. var eyearMin = eyear - 59;
  76. var htmlYearexp = '', htmlYear1exp = '', htmlYear2exp = '';
  77. for (var i = eyear; i >= eyearMin; i--) {
  78. if (i > (eyear-20)) {
  79. htmlYearexp += [
  80. '<li>',
  81. '<a class="J_listitme" href="javascript:;" data-code="' + i + '">' + i + '</a>',
  82. '</li>'
  83. ].join('');
  84. } else if (i > (eyear-40)) {
  85. htmlYear1exp += [
  86. '<li>',
  87. '<a class="J_listitme" href="javascript:;" data-code="' + i + '">' + i + '</a>',
  88. '</li>'
  89. ].join('');
  90. } else {
  91. htmlYear2exp += [
  92. '<li>',
  93. '<a class="J_listitme" href="javascript:;" data-code="' + i + '">' + i + '</a>',
  94. '</li>'
  95. ].join('');
  96. }
  97. }
  98. $('.J_birthdy_exp').each(function(index, el) {
  99. var $thisExps = $(this).find('.J_birthday_box_exp');
  100. $thisExps.eq(0).html(htmlYearexp);
  101. $thisExps.eq(1).html(htmlYear1exp);
  102. $thisExps.eq(2).html(htmlYear2exp);
  103. $(this).closest('.J_listitme_parent').find('.J_birthday_prev_exp').hide();
  104. })
  105. // 点击翻页
  106. $('.J_birthday_next_exp').on('click', function(event) {
  107. var $thisParent = $(this).closest('.J_listitme_parent');
  108. var $thisBox = $thisParent.find('.J_birthday_box_exp');
  109. var sub = 0; // 获取选中tab的下标
  110. $thisBox.each(function(index, el) {
  111. if ($(this).hasClass('active')) {
  112. sub = index;
  113. }
  114. });
  115. $thisBox.eq(sub+1).addClass("active").siblings(".J_birthday_box_exp").removeClass("active");
  116. if (sub == 1) {
  117. $thisParent.find('.J_birthday_next_exp').hide();
  118. }
  119. $thisParent.find('.J_birthday_prev_exp').show();
  120. event.stopPropagation();
  121. })
  122. $('.J_birthday_prev_exp').on('click', function(event) {
  123. var $thisParent = $(this).closest('.J_listitme_parent');
  124. var $thisBox = $thisParent.find('.J_birthday_box_exp');
  125. var sub = 0; // 获取选中tab的下标
  126. $thisBox.each(function(index, el) {
  127. if ($(this).hasClass('active')) {
  128. sub = index;
  129. }
  130. })
  131. $thisBox.eq(sub-1).addClass("active").siblings(".J_birthday_box_exp").removeClass("active");
  132. if (sub == 1) {
  133. $thisParent.find('.J_birthday_prev_exp').hide();
  134. }
  135. $thisParent.find('.J_birthday_next_exp').show();
  136. event.stopPropagation();
  137. })
  138. // 个人简历月份 相关
  139. var htmlMonth = '';
  140. for (var i = 1; i <= 12; i++) {
  141. htmlMonth += [
  142. '<li>',
  143. '<a class="J_listitme" href="javascript:;" data-code="' + i + '">' + i + '月</a>',
  144. '</li>'
  145. ].join('');
  146. }
  147. $('.J_month').each(function(index, el) {
  148. $(this).find('.J_month_box').html(htmlMonth);
  149. })
  150. //var $obj = $('.J_listitme'); //by lww modify
  151. $(document).on('click','.J_listitme', function(e) {
  152. var $thisParent = $(this).closest('.J_listitme_parent');
  153. var thisText = $(this).text();
  154. var thisCode = $(this).data('code');
  155. $thisParent.find('.J_listitme_text').text(thisText);
  156. $thisParent.find('.J_listitme_code').val(thisCode); // 隐藏input赋值
  157. hideMenus();
  158. e.stopPropagation();
  159. })
  160. // 下拉多选
  161. var $objM = $('.J_listitme_m');
  162. $objM.off().on('click', function() {
  163. var $thisParent = $(this).closest('.J_listitme_parent');
  164. var thisText = $(this).data('title');
  165. var thisCode = $(this).data('code');
  166. function syncListM() {
  167. var checkedArray = $thisParent.find('.J_listitme_m:checked');
  168. var codeArray = new Array();
  169. var titleArray = new Array();
  170. $.each(checkedArray, function(index, val) {
  171. codeArray[index] = $(this).data('code');
  172. titleArray[index] = $(this).data('title');
  173. });
  174. $thisParent.find('.J_listitme_text').text(titleArray.length ? titleArray.join('+') : $thisParent.find('.J_listitme_text').data('title'));
  175. $thisParent.find('.J_listitme_text').attr('title', titleArray.length ? titleArray.join('+') : $thisParent.find('.J_listitme_text').data('title'));
  176. $thisParent.find('.J_listitme_code').val(codeArray.join(','));
  177. }
  178. if ($(this).is(':checked')) {
  179. // 已选中
  180. if (!eval(thisCode)) {
  181. // 不限
  182. $thisParent.find('.J_listitme_m').each(function(index, el) {
  183. if (index) {
  184. $(this).prop('checked', !0);
  185. $(this).prop('disabled', !0);
  186. }
  187. });
  188. $thisParent.find('.J_listitme_text').text(thisText);
  189. $thisParent.find('.J_listitme_text').attr('title', thisText);
  190. $thisParent.find('.J_listitme_code').val(thisCode);
  191. hideMenus();
  192. } else {
  193. var othersArray = $thisParent.find('.J_listitme_m');
  194. var thisIndex = $thisParent.find('.J_listitme_m').index($(this));
  195. var checkedNum = $thisParent.find('.J_listitme_m:checked').length;
  196. if (checkedNum <= 1) {
  197. $.each(othersArray, function (index, value) {
  198. if (index > thisIndex) {
  199. $(this).prop('checked', !0);
  200. }
  201. })
  202. }
  203. syncListM();
  204. }
  205. } else {
  206. // 未选中
  207. if (!eval(thisCode)) {
  208. // 不限
  209. $thisParent.find('.J_listitme_m').each(function(index, el) {
  210. if (index) {
  211. $(this).prop('checked', 0);
  212. $(this).prop('disabled', 0);
  213. }
  214. });
  215. }
  216. syncListM();
  217. }
  218. });
  219. function hideMenus() {
  220. $('.J_tooltip').each(function() {
  221. $(this).removeClass('open');
  222. })
  223. $('.J_dropdown').each(function() {
  224. $(this).removeClass('open');
  225. })
  226. }
  227. // 单选按钮点击
  228. var $radiobj = $('.J_radioitme');
  229. $(document).on('click','.J_radioitme', function(event) {
  230. $(this).addClass("checked").siblings(".J_radioitme").removeClass("checked");
  231. var $thisParent = $(this).closest('.J_radioitme_parent');
  232. var thisCode = $(this).data('code');
  233. $thisParent.find('.J_radioitme_code').val(thisCode); // 隐藏input赋值
  234. })
  235. }(window.jQuery);