關鍵詞匹配搜尋仿百度

來源:互聯網
上載者:User

<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>關鍵詞匹配搜尋仿百度</title><meta name="description" content=" 內容介紹不超過100個中文"><meta name="keywords" content=" 內容相關關鍵詞3-5個"><style>body, ul, li { margin: 0; padding: 0;}body{ font-size:12px; font-family:sumsun,arial;background:#FFFFFF;}.gover_search{ position:relative; z-index:99; height:63px; padding:15px 0 0 20px; border:1px solid #b8cfe6; border-bottom:0; background:url(../images/gover_search_bg.gif) repeat-x 0 0;}.gover_search_form{height:36px;}.gover_search .search_t{ float:left; width:112px; line-height:26px; color:#666;}.gover_search .input_search_key{ float:left; width:462px; height:18px; padding:3px; margin-right:5px; border:1px solid #ccc; line-height:18px; background:#fff;}.gover_search .search_btn{ float:left; width:68px; height:26px; overflow:hidden; border:1px solid #ccc; text-align:center; color:#ff3300; letter-spacing:5px; background:url(../images/gover_search_bg.gif) no-repeat 0 -79px; cursor:pointer; font-weight:bold;}.gover_search .search_suggest{ position:absolute; z-index:999; left:132px; top:41px; width:468px; border:1px solid #ccc;border-top:none; display:none;color:#004080; }.gover_search .search_suggest li{height:24px; overflow:hidden; padding-left:3px; line-height:24px; background:#fff; cursor:default;}.gover_search .search_suggest li.hover{background:#ddd;}.num_right{float:right;text-align:right;line-height:24px;padding-right:10px}</style></head><body><div class="gover_search">    <div class="gover_search_form clearfix">            <span class="search_t">關鍵詞匹配搜尋</span>            <input type="text" class="input_search_key" id="gover_search_key" placeholder="請輸入關鍵詞直接搜尋" />            <button type="submit" class="search_btn">搜尋</button>            <div class="search_suggest" id="gov_search_suggest">                <ul>                </ul>            </div>        </div>    </div><script type="text/javascript" src="http://jt.875.cn/js/jquery.js"></script><script type="text/javascript">//實現搜尋輸入框的輸入提示js類function oSearchSuggest(searchFuc){var input = $('#gover_search_key');var suggestWrap = $('#gov_search_suggest');var key = "";var init = function(){input.bind('keyup',sendKeyWord);input.bind('blur',function(){setTimeout(hideSuggest,100);})}var hideSuggest = function(){suggestWrap.hide();}//發送請求,根據關鍵字到後台查詢var sendKeyWord = function(event){//鍵盤選擇下拉項if(suggestWrap.css('display')=='block'&&event.keyCode == 38||event.keyCode == 40){var current = suggestWrap.find('li.hover');if(event.keyCode == 38){if(current.length>0){var prevLi = current.removeClass('hover').prev();if(prevLi.length>0){prevLi.addClass('hover');input.val(prevLi.html());}}else{var last = suggestWrap.find('li:last');last.addClass('hover');input.val(last.html());}}else if(event.keyCode == 40){if(current.length>0){var nextLi = current.removeClass('hover').next();if(nextLi.length>0){nextLi.addClass('hover');input.val(nextLi.html());}}else{var first = suggestWrap.find('li:first');first.addClass('hover');input.val(first.html());}}//輸入字元}else{ var valText = $.trim(input.val());if(valText ==''||valText==key){return;}searchFuc(valText);key = valText;}}//請求返回後,執行資料展示this.dataDisplay = function(data){if(data.length<=0){            suggestWrap.hide();return;}//往搜尋方塊下拉建議顯示欄中添加條目並顯示var li;var tmpFrag = document.createDocumentFragment();suggestWrap.find('ul').html('');for(var i=0; i<data.length; i++){li = document.createElement('LI');li.innerHTML = data[i];tmpFrag.appendChild(li);}suggestWrap.find('ul').append(tmpFrag);suggestWrap.show();//為下拉選項綁定滑鼠事件suggestWrap.find('li').hover(function(){suggestWrap.find('li').removeClass('hover');$(this).addClass('hover');},function(){$(this).removeClass('hover');}).bind('click',function(){    $(this).find("span").remove();input.val(this.innerHTML);suggestWrap.hide();});}init();};//執行個體化輸入提示的JS,參數為進行查詢操作時要調用的函數名var searchSuggest =  new oSearchSuggest(sendKeyWordToBack);//這是一個模似函數,實現向後台發送ajax查詢請求,並返回一個查詢結果資料,傳遞給前台的JS,再由前台JS來展示資料。本函數由程式員進行修改實現查詢的請求//參數為一個字串,是搜尋輸入框中當前的內容function sendKeyWordToBack(keyword){   /*  var obj = {    "keyword" : keyword }; $.ajax({   type: "POST",   url: "${ctx}/front/suqiu2/search/prompt-keyword.action",   async:false,   data: obj,   dataType: "json",   success: function(data){ //var json = eval("("+data+")"); var key=data.split(","); var aData = []; for(var i=0;i<key.length;i++){//以下為根據輸入返回搜尋結果的類比效果代碼,實際資料由後台返回if(key[i]!=""){  aData.push(key[i]);} }//將返回的資料傳遞給實現搜尋輸入框的輸入提示js類 searchSuggest.dataDisplay(aData);   } });  */ //以下為根據輸入返回搜尋結果的類比效果代碼,實際資料由後台返回var aData = [];aData.push('<span class="num_right">約100個</span>'+keyword+'返回資料1');aData.push('<span class="num_right">約200個</span>'+keyword+'返回資料2');aData.push('<span class="num_right">約100個</span>'+keyword+'返回資料3');aData.push('<span class="num_right">約50000個</span>'+keyword+'返回資料4');aData.push('<span class="num_right">約1044個</span>'+keyword+'2012是真的');aData.push('<span class="num_right">約100個</span>'+keyword+'2012是假的');aData.push('<span class="num_right">約100個</span>'+keyword+'2012是真的');aData.push('<span class="num_right">約100個</span>'+keyword+'2012是假的');//將返回的資料傳遞給實現搜尋輸入框的輸入提示js類searchSuggest.dataDisplay(aData);}</script></body></html>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.