<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>模拟google搜索提示</title>
<STYLE type="text/css">
.div_list{
border:1px solid #336600;
width:100px;
position:absolute;
display:none;
background-color:#FFFFFF;
color:#009966;
}
ul{
list-style:none;
margin-left:0px;
}
td{width:100%;}
.li_sel{
width:100%;
background-color:#99FFCC;
cursor:pointer;
}
body{
margin-left:10px;
margin-top:10px;
}
</STYLE>
</head>
<body>
请输入姓名
<INPUT type="text" name="txtName" id="txtName" value=""
onkeyup="HandleKeyUp(this,document.getElementById('divlist'),event)"
onkeydown="HandleKeyDown(document.getElementById('divlist'),event)"
autocomplete="off"
/>
<input type="button" value="提交" onclick="ShowRecord(document.getElementById('txtName').value"/>
<DIV class="div_list" id="divlist" selectindex="-1">dd</DIV>
<SCRIPT language="javaScript">
var xmlhttp;
function SetListPos(oDiv) {//设置列表位置使其在文本况下方
var oInput=document.getElementById("txtName");
if(document.all){
oDiv.style.left=oInput.offsetLeft+10+'px';
oDiv.style.top=oInput.offsetTop+oInput.offsetHeight+10+"px";
oDiv.style.width=oInput.offsetWidth-2+'px';
}
else{
oDiv.style.left=oInput.offsetLeft+'px';
oDiv.style.top=oInput.offsetTop+oInput.offsetHeight+"px";
oDiv.style.width=oInput.offsetWidth-2+'px';
}
}
function FillList(oDiv,strList){
arrList=window.eval(strList);
oDiv.selectindex=-1;//设置选中项目为空
if(arrList.length>0){
var strhtml="<table border=0 style='width:100%'>";
for(var i=0;i<arrList.length;i++){
strhtml+="<tr><td onmouseover=\"this.className='li_sel'\" ";
strhtml+="onmouseout=\"this.className=''\" ";
strhtml+="onclick='Td_click(this,document.getElementById(\"txtName\"),document.getElementById(\"divlist\"))'>"
strhtml+=arrList[i].name+"</td></tr>";
}
strhtml+="</table>";
oDiv.innerHTML=strhtml;
ShowList(document.getElementById('divlist'),'block');
}
else{
ShowList(oDiv,'none');
oDiv.innerHTML="";
}
}
function ShowList(oDiv,strDisplay){
oDiv.style.display=strDisplay;
}
function CreateXmlHttp(){
if(document.all)
return new ActiveXObject("Microsoft.XMLHTTP");
else
return new XMLHttpRequest();
}
function HandleStateChange(){
if(4==xmlhttp.readyState){
var oDiv=document.getElementById("divlist");
if(200==xmlhttp.status){
var strResponse=xmlhttp.responseText;
FillList(oDiv,strResponse);
}
else{
alert("请求发生错误!"+xmlhttp.responseText)
ShowList(oDiv,'[]');
}
}
}
function HandleInputChange(strInput){
if(strInput!=""){
xmlhttp=CreateXmlHttp();
xmlhttp.open("post","google.aspx",true);
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xmlhttp.onreadystatechange=HandleStateChange;
xmlhttp.send("word=" + escape(strInput));
}
else{
var oDiv=document.getElementById('divlist');
ShowList(oDiv,'none');
oDiv.innerHTML="";
}
}
function Td_click(oTd,oInput,oDiv){
oInput.value=oTd.innerHTML;
ShowList(oDiv,'none');
}
function ChangeListSelect(oDiv,strOperation){
var nItemCount=oDiv.getElementsByTagName('tr').length;
var nSelIndex=parseInt(oDiv.selectindex);
//恢复以前选中的项目
if(nSelIndex!=-1)
oDiv.getElementsByTagName('td')[nSelIndex].className='';
//改变选中项目
var i=strOperation=="push"?1:-1;
if(nSelIndex+i<-1)
oDiv.selectindex=nItemCount-1;
if(nSelIndex+i>=-1 && nSelIndex+i<nItemCount)
oDiv.selectindex=nSelIndex+i;
if(nSelIndex+i>=nItemCount)
oDiv.selectindex=-1
//显示现在选中的项目
nSelIndex=parseInt(oDiv.selectindex);
if(nSelIndex!=-1)
oDiv.getElementsByTagName('td')[nSelIndex].className='li_sel';
}
function HandleKeyUp(oInput,oDiv,e){
var evt=window.event||e;
var keycode=evt.keyCode||evt.witch;
switch(keycode){
case 9://处理tab键(失败,无法触发)
oDiv.style.display='none';
break;
case 13://处理回车键
var nIndex=oDiv.selectindex;
if( nIndex){
oInput.value=oDiv.getElementsByTagName('td')[nIndex].innerHTML;
oDiv.style.display='none';
}
break;
case 38://处理方向键上箭头
ChangeListSelect(oDiv,"pop") ;
break;
case 40://处理方向键下肩头
ChangeListSelect(oDiv,"push") ;
break;
default://处理正常的字符输入
HandleInputChange(oInput.value)
}
}
function HandleKeyDown(oDiv,e){
var evt=window.event||e;
var keycode=evt.keyCode||evt.witch;
if(keycode==9){//处理tab键
oDiv.style.display='none';
}
}
function ShowRecord(strName){
}
SetListPos(document.getElementById('divlist'));
</SCRIPT>
</body>
</html>
一个适合新手的google suggest效果
需积分: 9 152 浏览量
2007-11-05
09:22:38
上传
评论
收藏 7KB RAR 举报
xingqiliudehuanghun
- 粉丝: 104
- 资源: 11
最新资源
- 三维装箱问题(Three-Dimensional Bin Packing Problem,3D-BPP)是一个经典的组合优化问题
- 以下是一些关于Linux线程同步的基本概念和方法.txt
- 以下是一个简化的示例,它使用pygame库来模拟烟花动画的框架.txt
- Linux线程同步机制深度解析与实用指南.zip
- PTA题库C语言解题策略与实战.rar
- SVPWM控制技术的simulink建模与仿真【包括simulink模型,参考文献,操作步骤】
- AI高清修复图片画质易语言易语言源码易语言填表
- 映射窗口.ec易语言易语言模块CPU占用0%游戏监控窗口监控
- 易语言 361窗口模块高效、便捷、自封装、自用
- 易语言 窗口排列 模块 ,简单、高效、体积小
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈