自动完成【纯HTML+Javascript】
来源:互联网 发布:微信软件登陆 编辑:程序博客网 时间:2024/06/11 10:55
这是最原始是自动完成,可以根据需要改改成为你想要的【关键是<input 标签的 autolist 属性】
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<title>自定义自动完成-51windows.Net</title>
<head>
<meta name="keywords" content="51windows.Net">
<meta http-equiv=Content-Type content="text/html; charset=gb2312">
<style>...
.sdiv{...}{font-size:12px;overflow-y:auto;overflow-x:hidden;height:expression(this.parentElement.style.pixelHeight);z-index:101;}
.sdivover{...}{background:highlight;color:highlighttext;width:100%;padding-left:3px;cursor:default;overflow:hidden;hidden;line-height:120%;}
.sdivout {...}{background:#FFFFFF;color:#000000;width:100%;padding-left:3px;cursor:default;overflow:hidden;line-height:120%;}
input{...}{haiwa:expression(this.onkeyup=__ACP);hw:expression(this.ondblclick=__ACP);}
</style>
</head>
<body onclick="divclick()" onkeydown="KeyDown()">
<SCRIPT LANGUAGE="JavaScript">...
<!--
var __InputName;
var HighLine = 0
var MenuStrs = ""
var MenuLines = 0
var KeyOnMenu = false
var _AutoObj
var ShowLine = 10
var LineHeight = 15
var SelectValue = "";
var __InputName;
function DivOver(obj)...{
if (KeyOnMenu)...{
updateHtml(-1);
KeyOnMenu = false
}
obj.className="sdivover";
}
function divclick(obj)...{
document.getElementById("__AutocompleteDiv").style.display = "none";
if (obj)...{
selectedvalue = obj.innerText;
__InputName.value = selectedvalue;
}
HighLine = 0
_Autostr = ""
SelectValue = ""
}
function __ACP()...{
if (event.keyCode!=13)...{
event.cancelBubble=true
e = this;
var t=e.offsetTop;
var l=e.offsetLeft;
var w=e.offsetWidth;
var h=e.offsetHeight;
_AutoObj = this
divID = document.getElementById("__AutocompleteDiv");
__InputName = this;
updateHtml(HighLine);
if (MenuLines>0)...{
while(e=e.offsetParent)
...{
t+=e.offsetTop;
l+=e.offsetLeft;
}
divID = eval(divID);
divID.style.top = t+h;
divID.style.left = l;
divID.style.width = w;
divID.style.height = MenuLines * LineHeight>ShowLine*LineHeight?ShowLine*LineHeight:MenuLines * LineHeight;
divID.style.display = ""
}
else...{
divID.style.display = "none"
}
}
}
function InsertSort(arr) ...{ //插入排序->直接插入法排序@panliu888
var temp, j;
for(var i=1; i<arr.length; i++) ...{
if((arr[i]) < (arr[i-1])) ...{
temp = arr[i];
j = i-1;
do ...{
arr[j+1] = arr[j];
j--;
}
while (j>-1 && (temp) < (arr[j]));
arr[j+1] = temp;
}//endif
}
return arr;
}
function updateHtml(k)...{
listhtml = ""
var line = 0
htmlarr = InsertSort(_AutoObj.autolist.split("|"))
var liststrarr = htmlarr;
for(i=0;i<liststrarr.length;i++)...{
if((liststrarr[i].substr(0,_AutoObj.value.length)==_AutoObj.value)&&(liststrarr[i].length>_AutoObj.value.length))...{
line ++;
if (k==line)...{
SelectValue = liststrarr[i]
listhtml += '<div class="sdivover" onclick="divclick(this)" onmouseover=DivOver(this);HighLine='+line+';SelectValue="'+liststrarr[i].replace(/"/ig,"/"")+'"; onmouseout=this.className="sdivout";>'+liststrarr[i]+'</div>';
}
else
listhtml += '<div class="sdivout" onclick="divclick(this)" onmouseover=DivOver(this);HighLine='+line+';;SelectValue="'+liststrarr[i].replace(/"/ig,"/"")+'"; onmouseout=this.className="sdivout";>'+liststrarr[i]+'</div>';
}
}
MenuLines = line
document.getElementById("__AutocompleteDivlist").innerHTML = listhtml;
document.getElementById("__AutocompleteDivlist").scrollTop = (k-ShowLine)>0?(k-ShowLine)*LineHeight:0;
}
function KeyDown(){
switch ( event.keyCode ){
case 13 : if(SelectValue.length>0){_AutoObj.value =SelectValue;divclick();}break ;
case 38 : KeyMove(-1) ; break ;
case 40 : KeyMove(1) ; break ;
}
}
function KeyMove(n){
HighLine = HighLine+(n);
if (parseInt(HighLine)>parseInt(MenuLines)){HighLine = 1;}
if(parseInt(HighLine)<1){HighLine = MenuLines;}
KeyOnMenu = true;
updateHtml(HighLine)
}
//-->
</SCRIPT>
昵称:<input type="text" autolist="51windows|"|haiwa|blueidea|hw|google|jimao8|中国|中|海娃|李海华" size="40" name="q"><br>
网址:<input type="text" autolist="http://www.51windows.Net|http://www.blueidea.com|http://www.csdn.Net" size="40" name="q">
<div id="__AutocompleteDiv" style="position: absolute;border: 1 solid #000000;display:none;height:180px;background:#FFFFFF;" onclick="event.cancelBubble=true">
<div class="sdiv" id="__AutocompleteDivlist" onclick="event.cancelBubble=true">
</div>
</div>
</body>
</html>
<html>
<title>自定义自动完成-51windows.Net</title>
<head>
<meta name="keywords" content="51windows.Net">
<meta http-equiv=Content-Type content="text/html; charset=gb2312">
<style>...
.sdiv{...}{font-size:12px;overflow-y:auto;overflow-x:hidden;height:expression(this.parentElement.style.pixelHeight);z-index:101;}
.sdivover{...}{background:highlight;color:highlighttext;width:100%;padding-left:3px;cursor:default;overflow:hidden;hidden;line-height:120%;}
.sdivout {...}{background:#FFFFFF;color:#000000;width:100%;padding-left:3px;cursor:default;overflow:hidden;line-height:120%;}
input{...}{haiwa:expression(this.onkeyup=__ACP);hw:expression(this.ondblclick=__ACP);}
</style>
</head>
<body onclick="divclick()" onkeydown="KeyDown()">
<SCRIPT LANGUAGE="JavaScript">...
<!--
var __InputName;
var HighLine = 0
var MenuStrs = ""
var MenuLines = 0
var KeyOnMenu = false
var _AutoObj
var ShowLine = 10
var LineHeight = 15
var SelectValue = "";
var __InputName;
function DivOver(obj)...{
if (KeyOnMenu)...{
updateHtml(-1);
KeyOnMenu = false
}
obj.className="sdivover";
}
function divclick(obj)...{
document.getElementById("__AutocompleteDiv").style.display = "none";
if (obj)...{
selectedvalue = obj.innerText;
__InputName.value = selectedvalue;
}
HighLine = 0
_Autostr = ""
SelectValue = ""
}
function __ACP()...{
if (event.keyCode!=13)...{
event.cancelBubble=true
e = this;
var t=e.offsetTop;
var l=e.offsetLeft;
var w=e.offsetWidth;
var h=e.offsetHeight;
_AutoObj = this
divID = document.getElementById("__AutocompleteDiv");
__InputName = this;
updateHtml(HighLine);
if (MenuLines>0)...{
while(e=e.offsetParent)
...{
t+=e.offsetTop;
l+=e.offsetLeft;
}
divID = eval(divID);
divID.style.top = t+h;
divID.style.left = l;
divID.style.width = w;
divID.style.height = MenuLines * LineHeight>ShowLine*LineHeight?ShowLine*LineHeight:MenuLines * LineHeight;
divID.style.display = ""
}
else...{
divID.style.display = "none"
}
}
}
function InsertSort(arr) ...{ //插入排序->直接插入法排序@panliu888
var temp, j;
for(var i=1; i<arr.length; i++) ...{
if((arr[i]) < (arr[i-1])) ...{
temp = arr[i];
j = i-1;
do ...{
arr[j+1] = arr[j];
j--;
}
while (j>-1 && (temp) < (arr[j]));
arr[j+1] = temp;
}//endif
}
return arr;
}
function updateHtml(k)...{
listhtml = ""
var line = 0
htmlarr = InsertSort(_AutoObj.autolist.split("|"))
var liststrarr = htmlarr;
for(i=0;i<liststrarr.length;i++)...{
if((liststrarr[i].substr(0,_AutoObj.value.length)==_AutoObj.value)&&(liststrarr[i].length>_AutoObj.value.length))...{
line ++;
if (k==line)...{
SelectValue = liststrarr[i]
listhtml += '<div class="sdivover" onclick="divclick(this)" onmouseover=DivOver(this);HighLine='+line+';SelectValue="'+liststrarr[i].replace(/"/ig,"/"")+'"; onmouseout=this.className="sdivout";>'+liststrarr[i]+'</div>';
}
else
listhtml += '<div class="sdivout" onclick="divclick(this)" onmouseover=DivOver(this);HighLine='+line+';;SelectValue="'+liststrarr[i].replace(/"/ig,"/"")+'"; onmouseout=this.className="sdivout";>'+liststrarr[i]+'</div>';
}
}
MenuLines = line
document.getElementById("__AutocompleteDivlist").innerHTML = listhtml;
document.getElementById("__AutocompleteDivlist").scrollTop = (k-ShowLine)>0?(k-ShowLine)*LineHeight:0;
}
function KeyDown(){
switch ( event.keyCode ){
case 13 : if(SelectValue.length>0){_AutoObj.value =SelectValue;divclick();}break ;
case 38 : KeyMove(-1) ; break ;
case 40 : KeyMove(1) ; break ;
}
}
function KeyMove(n){
HighLine = HighLine+(n);
if (parseInt(HighLine)>parseInt(MenuLines)){HighLine = 1;}
if(parseInt(HighLine)<1){HighLine = MenuLines;}
KeyOnMenu = true;
updateHtml(HighLine)
}
//-->
</SCRIPT>
昵称:<input type="text" autolist="51windows|"|haiwa|blueidea|hw|google|jimao8|中国|中|海娃|李海华" size="40" name="q"><br>
网址:<input type="text" autolist="http://www.51windows.Net|http://www.blueidea.com|http://www.csdn.Net" size="40" name="q">
<div id="__AutocompleteDiv" style="position: absolute;border: 1 solid #000000;display:none;height:180px;background:#FFFFFF;" onclick="event.cancelBubble=true">
<div class="sdiv" id="__AutocompleteDivlist" onclick="event.cancelBubble=true">
</div>
</div>
</body>
</html>
- 自动完成【纯HTML+Javascript】
- javascript 自动完成下拉框
- 自动转换静态表格(纯html)
- 纯javascript的HTML在线编辑器
- 纯javascript,放百度自动补全
- HTML输入框 关闭自动完成【历史记录】
- 在html中禁用自动完成
- 0、Notepad++如何自动完成html
- HTML+CSS+JavaScript完成滚动栏效果
- 仿google自动完成的JAVASCRIPT
- 用javascript仿ie的自动完成
- 33个JavaScript自动完成脚本
- 33个JavaScript自动完成脚本
- 轻量级javascript自动完成autocomplete插件
- 纯javascript 自动补全,不涉及数据库
- HTML中禁止自动完成和禁用输入法
- HTML中禁止自动完成和禁用输入法
- HTML CSS Javascript完成浮动登录窗口和窗口移动
- 2006年毕业生薪资大起底
- TestRef
- JavaEE5 Learning-JSP
- GB编码转换为UTF8编码
- 2006-09-28 墨子的双眼皮
- 自动完成【纯HTML+Javascript】
- VB6求两个字符串最长公共子串的问题
- 與古禪師談、求長生不老術
- 今年保研,还真奇怪,保44,结果45报名考试,一人缺考.呵呵
- A macro to get all interior colorindex has been used in thisworkbook
- 产生一定范围内随机数的方法
- 和弦表
- 最近关注的几个开放源代码的几个.NET的CMS系统和论坛系统
- 读书笔记--软件工程 实践者的研究方法(一)