日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

搜索栏联想词提示

發布時間:2025/3/12 编程问答 11 豆豆
生活随笔 收集整理的這篇文章主要介紹了 搜索栏联想词提示 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在我們需要游覽一些網站的時候,我們經常需要使用搜索引擎來進行搜索,無論是百度谷歌還是搜狐等,我們都需要在搜索欄中輸入相關的搜索詞,當我們點擊進行輸入的時候,下面會給出許許多多的提示詞,程序自動聯想你可能輸入的內容,所以往往我們只輸入了一個詞就看到了我們想要的題目直接點擊進行搜索就行了。

那麼我們如何來實現如上所說的聯想詞提示的搜索效果的呢???

首先我們來看一下效果

如上圖所示效果非常完美,那麼程序到底如何呢?

程序展示

html

<!DOCTYPE html> <html><head><meta charset="utf-8" /><title>相似查詢</title><link rel="stylesheet" type="text/css" href="css/style.css" /></head><body><script src="/demos/googlegg.js"></script><div id="out"><div id="ser_box"><input type="search" id="ipt" /><span><input id="su" value="搜索一下" class="bg s_btn" type="submit"></span></div><div id="bot_box"><ul id="oul"></ul></div></div><script src="js/style.js" type="text/javascript" charset="utf-8"></script></body> </html>

style.css

* {margin: 0;padding: 0; }#out {width: 500px;height: 140px;margin: 300px auto; }#ser_box {width: 500px;height: 32px;border: 1px solid blue;text-align: center; }#ipt {width: 480px;height: 26px;margin-top: 2px;border: 0;outline: 0;font-family: "微軟雅黑";font-size: 16px; }#bot_box {width: 500px;border: 1px solid #4C9ED9;border-top: none;display: none; }#bot_box ul li {list-style: none;line-height: 25px;padding-left: 10px; }#bot_box ul li:hover {background: #BCBCBC; }.s_btn {position: relative;left: 300px;top: -31px;width: 100px;height: 36px;color: #fff;font-size: 15px;letter-spacing: 1px;background: #3385ff;border-bottom: 1px solid #2d78f4;outline: medium; }.sel {background: #BCBCBC; }

style.js

function $(id) {return document.getElementById(id); }var ipt = $("ipt"); var ser = $("ser_box"); var bot = $("bot_box"); var oul = $("oul");ipt.oninput = function() {var ss = ipt.value;var url = "http://suggestion.baidu.com/su?cb=queryList&wd=" + ss;addScript(url); }ipt.onfocus = function() {var ss = ipt.value;var url = "http://suggestion.baidu.com/su?cb=queryList&wd=" + ss;addScript(url);}function queryList(data) {ss = document.getElementsByTagName("script")[0];document.body.removeChild(ss)var arr = data.s;oul.innerHTML = "";if (arr.length == 0) {bot.style.display = "none";} else {bot.style.display = "block";}for (var i = 0; i < arr.length; i++) {li = document.createElement("li");li.innerHTML = arr[i];li.onclick = function() {oul.innerHTML = "";ipt.value = this.innerHTML;bot.style.display = "none";}oul.appendChild(li);} }function addScript(url) {var s = document.createElement("script");s.src = url;s.type = "text/javascript";document.body.appendChild(s); }/*取li*/lis = document.getElementsByTagName("li");/*按鍵*/ var i = 0;document.onkeydown = function(ev) {if (bot.style.display == "block") {if (ev.keyCode == 40) {for (var j = 0; j < lis.length; j++) {if (lis[j].className == "sel") {lis[j].className = "";}}if (i < lis.length) {lis[i].className = "sel";i++;if (i == lis.length) {i = 0;}}}if (ev.keyCode == 38) {m = 0for (; m < lis.length; m++) {if (lis[m].className == "sel") {lis[m].className = "";break;}}i = m;if (m > 0) {lis[m - 1].className = "sel";} else {lis[lis.length - 1].className = "sel";}}if (ev.keyCode == 13) {for (var n = 0; n < lis.length; n++) {if (lis[n].className == "sel") {ipt.value = lis[n].innerHTML;}}bot.style.display = "none";}} else {i = 0;m = 0;} }

了解更多關注我喲!!!

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的搜索栏联想词提示的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。