sjett
锋 芒 内 敛 ,无 欲 则 刚 。
导航
博客园
首页
新随笔
联系
订阅
管理
<
2007年11月
>
日
一
二
三
四
五
六
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
统计
随笔 - 13
文章 - 4
评论 - 38
引用 - 0
公告
随风幻想...
lee.sjett@Gmail.com
昵称:
随 想
园龄:
7年5个月
粉丝:
0
关注:
0
搜索
常用链接
我的随笔
我的评论
我的参与
最新评论
我的标签
我的标签
IIS
(1)
随笔分类
AJAX_WebScripts(13)
(rss)
asp.net(6)
(rss)
winform
(rss)
设计模式-OO思维(2)
(rss)
生活随笔(2)
(rss)
网络与通信
(rss)
随笔档案
2011年7月 (1)
2008年5月 (1)
2007年11月 (2)
2007年6月 (10)
2006年7月 (2)
2006年6月 (2)
2006年5月 (2)
2005年3月 (2)
2004年12月 (1)
文章档案
2005年5月 (2)
2004年12月 (2)
常去的地方
alphatom.com
codeproject
csharp-corner
csharp-source.net
资源收集
车东
车东
文章收集1
(rss)
收集
积分与排名
积分 - 11843
排名 - 7768
最新评论
阅读排行榜
评论排行榜
推荐排行榜
[原创]搜索智能提示AutoComplate.js
//
-----------Create by sjett 2007-11-19----------------
var
_outTime
=
3000
;
//
setTimeOut(function,outTime);
var
inputObj
=
false
;
//
current input text control
var
setTimeOutId
=
false
;
var
displayDiv
=
false
;
//
display div
function
autoComplate_Init(ObjId)
{
inputObj
=
document.getElementById(ObjId);
_outTime
=
isNaN(parseInt(inputObj.getAttribute(
"
outTime
"
)))
?
_outTime : parseInt(inputObj.getAttribute(
"
outTime
"
));
autoComplate_InitEvent();
//
init input control Event
autoComplate_InitDisplayDiv();
}
function
autoComplate_InitEvent()
{
inputObj.onkeyup
=
autoComplate_ChangeEvent;
//
onchange onpropertychange
inputObj.onblur
=
autoComplate_DisposeEvent;
}
function
autoComplate_InitDisplayDiv()
{
var
divHtml
=
'
<
div id
=
"
autoComplateList
"
></
div
>
';
document.write(divHtml);
displayDiv
=
document.getElementById('autoComplateList');
autoComplate_DisposeEvent();
//
hiddern
displayDiv.style.top
=
(inputObj.offsetTop
+
inputObj.offsetHeight)
+
"
px
"
;
//
top,left
displayDiv.style.left
=
inputObj.offsetLeft
+
"
px
"
;
displayDiv.style.width
=
inputObj.offsetWidth
+
"
px
"
;
//
height,width
}
function
autoComplate_ChangeEvent()
{
if
(inputObj.value
==
'')
{
return
;}
if
(setTimeOutId)
{clearTimeout(setTimeOutId);}
setTimeOutId
=
setTimeout(
function
()
{
//
这里做一些你想在Input控件的事件中处理事务
autoComplate_GetData();
}
, _outTime);
}
function
autoComplate_DisposeEvent()
{
if
(displayDiv)
{
displayDiv.style.visibility
=
'hidden';
displayDiv.style.display
=
'none';
displayDiv.innerHTML
=
'';
//
clear
setTimeOutId
=
false
;
}
}
function
autoComplate_DisplayDivShow()
{
if
(displayDiv)
{
displayDiv.style.visibility
=
'visible';
displayDiv.style.display
=
'block';
setTimeOutId
=
false
;
}
}
function
autoComplate_DisplayDivOnRowOver()
{
eval('
this
.className
=
"
autoComplateList-tr-over
"
');
}
function
autoComplate_DisplayDivOnRowOut()
{
eval('
this
.className
=
"
autoComplateList-tr
"
');
}
function
autoComplate_DisplayDivOnClick()
{
inputObj.value
=
eval('
this
.innerHTML');
autoComplate_DisposeEvent();
//
这里作一些当选中文本后想作的事,比如像google一样提交查询
}
function
autoComplate_DisplayDivSetRowsEvent()
{
for
(
var
index
=
0
; index
<
displayDiv.childNodes.length
-
1
;index
++
)
{
displayDiv.childNodes[index].onmouseover
=
autoComplate_DisplayDivOnRowOver;
displayDiv.childNodes[index].onmouseout
=
autoComplate_DisplayDivOnRowOut;
displayDiv.childNodes[index].onclick
=
autoComplate_DisplayDivOnClick;
}
}
function
autoComplate_GetData()
{
var
ajax
=
new
sack();
ajax.requestFile
=
"
search.aspx?type=4&name=name
"
;
//
请求地址
ajax.onCompletion
=
function
()
{
var
entities
=
ajax.responseXML.getElementsByTagName(
"
entity
"
);
if
(entities.length
<=
0
)
return
;
displayDiv.innerHTML
=
'';
for
(
var
index
=
0
; index
<
entities.length; index
++
)
{
displayDiv.innerHTML
+=
'
<
div class
=
"
autoComplateList-tr
"
>
'
+
entities[index].firstChild.getAttribute(
"
value
"
)
+
'
</
div
>
';
}
//
Close Tag
displayDiv.innerHTML
+=
'
<
div class
=
""
style
=
"
text-align:right;
"
><
a href
=
"
#
"
onclick
=
"
autoComplate_DisposeEvent();
"
>
关闭
</
a
></
div
>
';
//
Add Event
autoComplate_DisplayDivSetRowsEvent();
//
Show
autoComplate_DisplayDivShow();
}
;
ajax.runAJAX();
}
代码示例下载:
http://files.cnblogs.com/sjett/autoComplate.rar
绿色通道:
好文要顶
关注我
收藏该文
与我联系
posted on 2007-11-22 08:29
随 想
阅读(590)
评论(3)
编辑
收藏
Comments
1623107
#1楼
[
楼主
]
随 想
Posted @
2007-11-22 08:31
补充:
<input type="text" id=input1 name=input1 outTime=3000 />
回复
引用
查看
#2楼
jack wang[未注册用户]
Posted @
2009-03-21 11:54
今天搜索到你的这篇文章,我把代码下载下来,但是没有效果。还请指教一二。
回复
引用
#3楼
softdot[未注册用户]
Posted @
2009-08-23 13:20
你这里其实就是用ajax去后台取
在后台数据量十分庞大,而且搜索页面使用比较频繁的情况下
可能会出现等待甚至是http请求超时的情况
回复
引用
注册用户登录后才能发表评论,请
登录
或
注册
,
返回博客园首页
。
首页
博问
闪存
新闻
园子
招聘
知识库
最新IT新闻
:
·
中石化为员工团购奔驰 优惠额度2万元起
·
Lumia 800行货版上市时间曝光
·
乔布斯走后的日子:苹果盛世暗藏危机
·
苹果开年度股东大会:投资者对如何分红持异议
·
Google Maps在中国大城市实现3D建筑视图
»
更多新闻...
最新知识库文章
:
·
编程的艺术:漂亮的代码和漂亮的软件
·
GIT分支管理是一门艺术
·
编程:是一门艺术
·
编程是一门艺术吗?
·
对Java初学者的忠告
»
更多知识库文章...
China-pub 2011秋季教材巡展
China-Pub 计算机绝版图书按需印刷服务