1. js代码:
//google suggest start
var taxonNameList = null;
var index = 0;
var size = 0;
var taxonNameArray ;
//set the panel on the top of others
$(document).ready(function(){
var left = $("#taxonQuery").offset().left;
var top = $("#taxonQuery").offset().top;
var panel = $("#taxonNameListPanel");
panel.css("left",left);
panel.css("top",top + 20);
panel.css("background","#fff");
});
function taxonNameSuggest(e){
//keyset
var e2 = window.event||e;
var keyStr = e2.keyCode;
if(keyStr!=38&&keyStr!=40&&keyStr!=13){
var key = $("#taxonQuery").val();
var length = key.length;
var panel = $("#taxonNameListPanel");
$.get("../taxonNameSuggest?suffix=" + key,function(data){
taxonNameList = data;
setTaxonNamePanel();
panel.show();
});
}else{
if(keyStr==38){//up
if(index!=size){
if(index==-1)index = index +1;
$("#taxonQuery").val(taxonNameArray[index]);
$("#item" + index).css("background","gray");
$("#item" + (index - 1)).css("background","");
index=index+1;
}
}else if(keyStr==40){//down
if(index!=-1){
if(index==size)index = index-1;
$("#taxonQuery").val(taxonNameArray[index]);
$("#item" + index).css("background","gray");
$("#item" + (index + 1)).css("background","");
index=index-1;
}
}else{//enter
hide();
$("#searchButton").focus();
}
}
}
function setTaxonNamePanel(){
taxonNameArray = taxonNameList.split(";");
var table = document.getElementById("taxonNameTable");
//delete all rows
size = taxonNameArray.length-1;
index = size - 1;
for(i=table.rows.length-1;i>=0;i--){
table.deleteRow(i);
}
for(i=0;i<taxonNameArray.length;i++){
if(taxonNameArray[i]==null||taxonNameArray[i]=="")break;
var newRow = table.insertRow(0);
newRow.onmouseover=mup;
newRow.onmouseout=mout;
var newCol = newRow.insertCell(0);
newCol.innerHTML = "<div onclick='setValue(this)' id='item" + i + "''>" + taxonNameArray[i] + "</div>";
}
}
function mup(){
$(this).css("background","gray");
}
function mout(){
$(this).css("background","");
}
function setValue(t){
$("#taxonQuery").val($(t).text());
hide();
}
function hide(){
$("#taxonNameListPanel").hide();
}
//end of google suggest
2. 页面代码:
<input id="taxonQuery" type="text" value="<%if(request.getParameter("taxonName")!=null) out.print(request.getParameter("taxonName")); %>" onkeyup="taxonNameSuggest(event)" />
<input id="searchButton" type="button" value="Search" onClick="taxonSearch();">
<div id="taxonNameListPanel" style="width: 155px; border: 1px solid #000; position: relative; left: 104px; top: 0px; display: none;">
<table width="100%" id="taxonNameTable" style="cursor: hand;">
</table>
<div style="float: right;clear:both;">
<a href="#" style="border: none; font-size: 12px;" onclick="hide(this)">close</a>
</div>
</div>
分享到:
相关推荐
它给出了谷歌搜索字符串给出的建议列表
自动完成 google suggestion autocomplete demo
安装pip install -r requirements.txt 跑步python service.py 常问问题 :speech_balloon: 常问问题问:您是否有论文或其他书面说明来介绍模型的详细信息?... 一方面,Google在Wikipedia数据上对BERT
谷歌建议搜索(googlesuggestion)ajax,json实现方式 里面有实现的说明,本人原创,如有错误 还请海涵.但是功能都已实现 欢迎下载!
ecshop仿照淘宝模板搜索下拉框,ajax实现google suggestion效果
纯ajax实现的仿效谷歌和百度的搜索提示功能,自己建立一个小数据库模拟一下,可以实现上下键的动态选取,鼠标单击触发搜索等
像百度一样搜索时联想出相关信息 显示在输入框下面
目前很多产品里都已经很好地应用了这一技术,比如Google的Gmall、Google Map、Google Suggestion以及微软的Virtual Earth和Start.com等,Kupu(一个开源的JavaScript应用程序)也是一个大量应用AJAX技术的典型案例...
该组件是Richfaces建议框组件的扩展。建议框是类似于Google Suggest的组件。 该组件在JSF输入文本框旁边包含一个按钮,并且单击该按钮的onclick会显示建议框。
集合了百度,谷歌,搜狗,360,腾讯等多家搜索截图预览:![img](img/2015-04-26_111924.jpg)![img](img/2015-04-26_111752.jpg)![img](img/2015-04-26_111951.jpg)![img](img/2015-04-26_111902.jpg)
允许用户使用Google登录 他们登录时,向他们发送欢迎电子邮件 让用户添加建议 当他们的建议获得5票赞成时,请向他们发送电子邮件表示祝贺 整个应用程序是scotch.io的伙计们创建程序的由我按照上简单逐步教程创建。 ...
readme: 本文件记录了suggestion.js文件的功能使用说明: 代码如下: /* * 功能:该js文件中的代码实现了[输入自动搜索提示]功能,如百度、google搜索框中输入一些字符会以下拉列表形式给出一些提示,提高了用户体验;...
Android Market / Google Play 搜索建议的包装器。 样本输出 ruby examples/simple_suggest.rb Found 6 suggestions! Suggestion 0 : Lookout Security & Antivirus suggestion type was APPLICATION Icon url ...
Suggestion Scraper and Google Suggest 69 Building keyword lists with common qualifiers 70 Analyzing customers' search behavior 71 Building keyword lists with location names 72 Learning how ...
This practical guide shows you how to make your Java web applications more responsive and dynamic by incorporating new Ajaxian features, including suggestion lists, drag-and-drop, and more. Java ...
This practical guide shows you how to make your Java web applications more responsive and dynamic by incorporating new Ajaxian features, including suggestion lists, drag-and-drop, and more. Java ...
This practical guide shows you how to make your Java web applications more responsive and dynamic by incorporating new Ajaxian features, including suggestion lists, drag-and-drop, and more. Java ...
翻译或添加词汇 我的词汇 - 功能建议和路线图 https://trello.com/b/hei5wfny/my-vocabulary-feature-suggestion-and-roadmap. changelog: V67:与Google Drive同步 v66:删除歧视区敏感 V64:添加音频语音(beta...
ChromeCacheView v1.25 ... Description ChromeCacheView is a small utility that...If you have any problem, suggestion, comment, or you found a bug in my utility, you can send a message to nirsofer@yahoo.com