var submitSearch = function() { var params = { 'keyword' : $.trim($('input[name="top_search_"]').val()) }; window.location = $appPath + '/search2/index.do?rows=5&' + $.param(params); }; function searchSenior(){ $('.search-win').slideToggle("show"); } $(function() { $('.header_querySenior').click(function() { $('.search-win').slideToggle("show"); }); $('.search-win .list-group > .list-group-item').click(function() { $(this).toggleClass('selected-item unselected-item'); var value = $(this).text(); var text = $.trim($('input[name="top_search_"]').val()); // 选中 if (text.indexOf(value) < 0 && $(this).hasClass("selected-item")) { text += " " + value; $('input[name="top_search_"]').val(text); } // 取消 if (text.indexOf(value) >= 0 && $(this).hasClass("unselected-item")) { text = text.replace(value, ""); $('input[name="top_search_"]').val(text); } }); // 单击”取消选择“按钮取消所有已选的项 $('.search-win #cancel-selected').click(function() { $('.search-win .list-group > .selected-item').toggleClass('selected-item unselected-item'); }); $('.search-win #clear-selected').click(function() { $('.search-win .list-group > .selected-item').toggleClass('selected-item unselected-item'); $('input[name="top_search_"]').val(""); }); $('.search_top_button').click(submitSearch); $('.search_top_input').on('keydown', function(event) { event = event ? event : (window.event ? window.event : null); if (event.keyCode == 13) { submitSearch(); } }); $('.search-win').show(0,function(){ $('.search-win .list-group').height(function(idx, h) { if (h > 80) { // 为折叠按钮添加click事件处理函数 $(this).children('.collapse-all').show(); $(this).children('.collapse-all').data('max-height', h).click(function() { if ($(this).data('opened')) { // 收起 $(this).data('opened', false); $(this).find('span').text('展开'); $(this).find('img').attr('src', $appStaticsPath + '/images/data/collapsed.png'); $(this).closest('dd').animate({ height : "80px" }, 'normal'); } else { // 展开 $(this).data('opened', true); $(this).find('span').text('收起'); $(this).find('img').attr('src', $appStaticsPath + '/images/data/expanded.png'); $(this).closest('dd').animate({ height : $(this).data('max-height') }, 'normal'); } }); } return Math.min(h, 80); }).closest('.search-win').hide().css('visibility', 'visible'); }); });