123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- /* ============================================================
- * jquery.listitem.js 下拉列表选择
- * ============================================================ */
- !function($) {
- // 个人简历年份 相关
- var birthdayDate = new Date();
- var byear = birthdayDate.getFullYear();
- byear = byear - 16;
- var byearMin = byear - 49;
- var htmlYear = '', htmlYear1 = '', htmlYear2 = '';
- for (var i = byear; i >= byearMin; i--) {
- if (i > (byear-20)) {
- htmlYear += [
- '<li>',
- '<a class="J_listitme" href="javascript:;" data-code="' + i + '">' + i + '</a>',
- '</li>'
- ].join('');
- } else if (i > (byear-40)) {
- htmlYear1 += [
- '<li>',
- '<a class="J_listitme" href="javascript:;" data-code="' + i + '">' + i + '</a>',
- '</li>'
- ].join('');
- } else {
- htmlYear2 += [
- '<li>',
- '<a class="J_listitme" href="javascript:;" data-code="' + i + '">' + i + '</a>',
- '</li>'
- ].join('');
- }
- }
- $('.J_birthdy').each(function(index, el) {
- var $thisBirthdys = $(this).find('.J_birthday_box');
- $thisBirthdys.eq(0).html(htmlYear);
- $thisBirthdys.eq(1).html(htmlYear1);
- $thisBirthdys.eq(2).html(htmlYear2);
- $(this).closest('.J_listitme_parent').find('.J_birthday_prev').hide();
- })
- // 点击翻页
- $('.J_birthday_next').on('click', function(event) {
- var $thisParent = $(this).closest('.J_listitme_parent');
- var $thisBox = $thisParent.find('.J_birthday_box');
- var sub = 0; // 获取选中tab的下标
- $thisBox.each(function(index, el) {
- if ($(this).hasClass('active')) {
- sub = index;
- }
- })
- $thisBox.eq(sub+1).addClass("active").siblings(".J_birthday_box").removeClass("active");
- if (sub == 1) {
- $thisParent.find('.J_birthday_next').hide();
- }
- $thisParent.find('.J_birthday_prev').show();
- event.stopPropagation();
- })
- $('.J_birthday_prev').on('click', function(event) {
- var $thisParent = $(this).closest('.J_listitme_parent');
- var $thisBox = $thisParent.find('.J_birthday_box');
- var sub = 0; // 获取选中tab的下标
- $thisBox.each(function(index, el) {
- if ($(this).hasClass('active')) {
- sub = index;
- }
- });
- $thisBox.eq(sub-1).addClass("active").siblings(".J_birthday_box").removeClass("active");
- if (sub == 1) {
- $thisParent.find('.J_birthday_prev').hide();
- }
- $thisParent.find('.J_birthday_next').show();
- event.stopPropagation();
- })
- // 教育经历等相关年份
- var experienceDate = new Date();
- var eyear = experienceDate.getFullYear();
- var eyearMin = eyear - 59;
- var htmlYearexp = '', htmlYear1exp = '', htmlYear2exp = '';
- for (var i = eyear; i >= eyearMin; i--) {
- if (i > (eyear-20)) {
- htmlYearexp += [
- '<li>',
- '<a class="J_listitme" href="javascript:;" data-code="' + i + '">' + i + '</a>',
- '</li>'
- ].join('');
- } else if (i > (eyear-40)) {
- htmlYear1exp += [
- '<li>',
- '<a class="J_listitme" href="javascript:;" data-code="' + i + '">' + i + '</a>',
- '</li>'
- ].join('');
- } else {
- htmlYear2exp += [
- '<li>',
- '<a class="J_listitme" href="javascript:;" data-code="' + i + '">' + i + '</a>',
- '</li>'
- ].join('');
- }
- }
- $('.J_birthdy_exp').each(function(index, el) {
- var $thisExps = $(this).find('.J_birthday_box_exp');
- $thisExps.eq(0).html(htmlYearexp);
- $thisExps.eq(1).html(htmlYear1exp);
- $thisExps.eq(2).html(htmlYear2exp);
- $(this).closest('.J_listitme_parent').find('.J_birthday_prev_exp').hide();
- })
- // 点击翻页
- $('.J_birthday_next_exp').on('click', function(event) {
- var $thisParent = $(this).closest('.J_listitme_parent');
- var $thisBox = $thisParent.find('.J_birthday_box_exp');
- var sub = 0; // 获取选中tab的下标
- $thisBox.each(function(index, el) {
- if ($(this).hasClass('active')) {
- sub = index;
- }
- });
- $thisBox.eq(sub+1).addClass("active").siblings(".J_birthday_box_exp").removeClass("active");
- if (sub == 1) {
- $thisParent.find('.J_birthday_next_exp').hide();
- }
- $thisParent.find('.J_birthday_prev_exp').show();
- event.stopPropagation();
- })
- $('.J_birthday_prev_exp').on('click', function(event) {
- var $thisParent = $(this).closest('.J_listitme_parent');
- var $thisBox = $thisParent.find('.J_birthday_box_exp');
- var sub = 0; // 获取选中tab的下标
- $thisBox.each(function(index, el) {
- if ($(this).hasClass('active')) {
- sub = index;
- }
- })
- $thisBox.eq(sub-1).addClass("active").siblings(".J_birthday_box_exp").removeClass("active");
- if (sub == 1) {
- $thisParent.find('.J_birthday_prev_exp').hide();
- }
- $thisParent.find('.J_birthday_next_exp').show();
- event.stopPropagation();
- })
- // 个人简历月份 相关
- var htmlMonth = '';
- for (var i = 1; i <= 12; i++) {
- htmlMonth += [
- '<li>',
- '<a class="J_listitme" href="javascript:;" data-code="' + i + '">' + i + '月</a>',
- '</li>'
- ].join('');
- }
- $('.J_month').each(function(index, el) {
- $(this).find('.J_month_box').html(htmlMonth);
- })
- //var $obj = $('.J_listitme'); //by lww modify
- $(document).on('click','.J_listitme', function(e) {
- var $thisParent = $(this).closest('.J_listitme_parent');
- var thisText = $(this).text();
- var thisCode = $(this).data('code');
- $thisParent.find('.J_listitme_text').text(thisText);
- $thisParent.find('.J_listitme_code').val(thisCode); // 隐藏input赋值
- hideMenus();
- e.stopPropagation();
- })
- // 下拉多选
- var $objM = $('.J_listitme_m');
- $objM.off().on('click', function() {
- var $thisParent = $(this).closest('.J_listitme_parent');
- var thisText = $(this).data('title');
- var thisCode = $(this).data('code');
- function syncListM() {
- var checkedArray = $thisParent.find('.J_listitme_m:checked');
- var codeArray = new Array();
- var titleArray = new Array();
- $.each(checkedArray, function(index, val) {
- codeArray[index] = $(this).data('code');
- titleArray[index] = $(this).data('title');
- });
- $thisParent.find('.J_listitme_text').text(titleArray.length ? titleArray.join('+') : $thisParent.find('.J_listitme_text').data('title'));
- $thisParent.find('.J_listitme_text').attr('title', titleArray.length ? titleArray.join('+') : $thisParent.find('.J_listitme_text').data('title'));
- $thisParent.find('.J_listitme_code').val(codeArray.join(','));
- }
- if ($(this).is(':checked')) {
- // 已选中
- if (!eval(thisCode)) {
- // 不限
- $thisParent.find('.J_listitme_m').each(function(index, el) {
- if (index) {
- $(this).prop('checked', !0);
- $(this).prop('disabled', !0);
- }
- });
- $thisParent.find('.J_listitme_text').text(thisText);
- $thisParent.find('.J_listitme_text').attr('title', thisText);
- $thisParent.find('.J_listitme_code').val(thisCode);
- hideMenus();
- } else {
- var othersArray = $thisParent.find('.J_listitme_m');
- var thisIndex = $thisParent.find('.J_listitme_m').index($(this));
- var checkedNum = $thisParent.find('.J_listitme_m:checked').length;
- if (checkedNum <= 1) {
- $.each(othersArray, function (index, value) {
- if (index > thisIndex) {
- $(this).prop('checked', !0);
- }
- })
- }
- syncListM();
- }
- } else {
- // 未选中
- if (!eval(thisCode)) {
- // 不限
- $thisParent.find('.J_listitme_m').each(function(index, el) {
- if (index) {
- $(this).prop('checked', 0);
- $(this).prop('disabled', 0);
- }
- });
- }
- syncListM();
- }
- });
- function hideMenus() {
- $('.J_tooltip').each(function() {
- $(this).removeClass('open');
- })
- $('.J_dropdown').each(function() {
- $(this).removeClass('open');
- })
- }
- // 单选按钮点击
- var $radiobj = $('.J_radioitme');
- $(document).on('click','.J_radioitme', function(event) {
- $(this).addClass("checked").siblings(".J_radioitme").removeClass("checked");
- var $thisParent = $(this).closest('.J_radioitme_parent');
- var thisCode = $(this).data('code');
- $thisParent.find('.J_radioitme_code').val(thisCode); // 隐藏input赋值
- })
- }(window.jQuery);
|