$(document).ready(function () { sliderShow(); document.onkeydown = function (event) { var e = event || window.event || arguments.callee.caller.arguments[0]; if (e && e.keyCode == 13 && $('.keydowninput').val() != '请选择目的地') { // enter 键 createPlaceSpan(); } }; $('.keydowninput').bind('click.inputfocus', function () { $(this).val(''); $(this).attr('fc', 'on'); }); $('.list-city li').click(function () { if ($('.keydowninput').attr('fc') == 'on') { var _txt = $(this).text(); if (!$(this).hasClass('city-select')) { $(this).addClass('city-select'); var ifo = $(this).attr('cityname'); makePlaceSpan(_txt, ifo); } } }); $('.mdd-select input').blur(function (e) { var inputObj = $(this); var mddselect = $(this).parent().find('.mddselect'); window.setTimeout(function () { var str = mddselect.attr('value'); if (str != undefined && typeof str == 'string') { if (str.length == 0) { var strMark = inputObj.attr('mark'); switch (strMark) { case 'mdd': inputObj.val("目的地不能为空"); break; } inputObj.parents('.mdd-select').addClass('error-tips'); } } }, 250); }) }); function createPlaceSpan() { var _txt = $('.keydowninput').val(); makePlaceSpan(_txt); } function makePlaceSpan(txt, ifo) { var cityselecttext = $('.city-select').text() if (txt != undefined && txt != '') { var _textspan = document.createElement('span'); _textspan.innerHTML = txt + '×'; _textspan.className = "tag-span"; if (ifo) { _textspan.setAttribute('ct', ifo); $('.list-city').attr('list-city', ifo).addClass('.city-select'); } $(_textspan).insertBefore($('.mdd-select label')); $('.keydowninput').val(''); } $('.mdd-select').find('.mddselect').val(cityselecttext); } function closePlaceSpan(o) { var ss = $(o).parent().attr('ct'); $('.city-select[cityname="' + ss + '"]').removeClass('city-select'); $(o).parent().remove(); var cityselecttext = $('.city-select').text(); $('.mdd-select').find('.mddselect').val(cityselecttext); if ($('.tag-span').length == 0) { $('.keydowninput').val('请选择目的地'); } } function sliderShow() { var tipPop = $('.tips-pop'); var popli = tipPop.find('li'); var popnum = tipPop.length for (i = 0; i < popnum; i++) { popli.eq(i).show().delay(3000).fadeOut(); } }