dedecms織夢(mèng)使用ajax實(shí)現(xiàn)搜索下拉提示功能
這個(gè)功能主要實(shí)現(xiàn)的是用戶在搜索的時(shí)候輸入關(guān)鍵字,然后會(huì)出現(xiàn)下拉菜單,下拉菜單中出現(xiàn)的是站內(nèi)所有包含這個(gè)關(guān)鍵字的文章的標(biāo)題共用戶選擇,相對(duì)DedeCMS原生的搜索這個(gè)功能實(shí)用一點(diǎn),既增加了用戶體驗(yàn),也可以讓用戶快速的找......
以下是【金聰采編】分享的內(nèi)容全文:
以下是【金聰采編】分享的內(nèi)容全文:
打開(kāi)你的網(wǎng)站首頁(yè)模板,在</head>之前加入
<script language="javascript" type="text/javascript" src="{dede:global.cfg_templets_skin/}/js/jquery-1.7.1.min.js"></script><script type="text/javascript"> function lookup(inputString) { if(inputString.length == 0) { // Hide the suggestion box. $('#suggestions').hide(); } else { $.post("/plus/search_list.php", {queryString: ""+inputString+""}, function(data){ if(data.length >0) { $('#suggestions').show(); $('#autoSuggestionsList').html(data); } }); } } // lookup function fill(thisValue) { $('#inputString').val(thisValue); setTimeout("$('#suggestions').hide();", 200); } </script> |
jquery-1.7.1.min.js這個(gè)jquery庫(kù)需要你自己下載,這里就不多說(shuō)了。本人用的是這個(gè)版本的。
這段代碼中的search_list.php就是本文下載的文件,下載后放入/plus目錄下。
打開(kāi)head.htm,找到搜索部分的from表單代碼修改為
<form name="formsearch" action="{dede:global.cfg_cmsurl/}/plus/search.php" id="formkeyword"> <label for="header-subscribe-email" class="text"></label><input type="hidden" name="kwtype" value="0"/><input type="text" name="q" size="24" value="在這里搜索..." onfocus="if(this.value=='在這里搜索...'){this.value='';}" onblur="if(this.value==''){this.value='在這里搜索...';}" id="inputString" onkeyup="lookup(this.value);" onblur="fill();" class="f-text"><input type="submit" class="commit" value="搜索"/> <div class="suggestionsBox" id="suggestions" style="display: none;"> <div class="suggestionList"> <ul id="autoSuggestionsList"> </ul> </div> </div></form> |
這部分可以根據(jù)你自己的代碼的實(shí)際情況具體修改,主要是輸入關(guān)鍵字的input和下邊加的DIV層。
打開(kāi)你自己的樣式表css文件,在最后加入
.suggestionsBox { position: relative; left: 0px; width: 250px; background: white; border: 1px solid #dcdcdc; color: #323232; z-index: 999;}.suggestionList { margin: 0px; padding: 0px;}.suggestionList li { margin: 0px 0px 3px 0px; position: relative; padding: 3px; cursor: pointer; list-style: none; padding-left: 5px; height: 20px; overflow: hidden}.suggestionList li:hover { background-color: #659CD8;}.jr { position: absolute; top: 9px; right: -5px} |
到這添加的代碼就完了,然后下載search_list.rar,下載后解壓得search_list.php到放入/plus目錄下。在這個(gè)文件里有詳細(xì)注解??筛鶕?jù)實(shí)際情況調(diào)整。所有結(jié)果都是由這個(gè)文件來(lái)返回的。最后去前臺(tái)試試您的效果把。

侵權(quán)舉報(bào)/版權(quán)申訴



![[轉(zhuǎn)載]DedeCMS全站調(diào)用購(gòu)物車數(shù)量顯示縮略圖](/d/file/c193b326fdf45961b69825fb4e8c9a4c.png)