用jquery写的自动提示效果
作者:亮亮 来源:亮亮blog 时间:2008-06-17 14:27:00
在填写表单的时候为了让用户有更好的体验,有时需要根据用户的输入出现提示共用户选择,我这个就是根据输入的内容,从数据库取出相关内容以供选择,这样填写起来就方便快捷多了。
支持上下键和鼠标选择。
好了,废话少说,看演示。
js代码
<script type="text/javascript">
var a_i;
function showGs(event){
if($.browser.msie){
var keyStr=event.keyCode;
}
else var keyStr=event.which;
if(keyStr!=38&&keyStr!=40&&keyStr!=13){
$("#ts").empty();
var vsGsName=escape($("#sGsName").val());
if(vsGsName!=""){
$("#ts").html("正在加载...");
$.post("s.asp",{sGsName:vsGsName},function(m){
$("#ts").html(unescape(m));
$("#ts>a").bind("click",vst);
$("#ts").css("display","block");
//初始化全局变量
a_i=-1;
});
}
else $("#ts").css("display","none");
}
else{
//使用键盘上下键选择
if($("#ts").css("display")=="block"){
//得到选择列表的长度
var aLen=$("#ts>a").length;
var _aLen=Number(aLen)-1;
//按下键盘向下方向键
if(keyStr==38){
if(a_i>=0&&a_i<=_aLen) $("#ts>a").get(a_i).style.backgroundColor="";
a_i=Number(a_i)-1;
if(a_i<0) a_i=_aLen;
$("#ts>a").get(a_i).style.backgroundColor="#CCCCCC";
}
//按下键盘的向上方向键
else if(keyStr==40){
if(a_i>=0&&a_i<=_aLen) $("#ts>a").get(a_i).style.backgroundColor="";
a_i=Number(a_i)+1;
if(a_i>=aLen) a_i=0;
$("#ts>a").get(a_i).style.backgroundColor="#CCCCCC";
}
//按下回车键
else if(keyStr==13){
var entLiText=$("#ts>a").get(a_i).innerHTML;
$("#sGsName").val(entLiText);
$("#ts").css("display","none");
}
}
}
}
function vst(){
var liText=$(this).text();
$("#sGsName").val(liText);
$("#ts").css("display","none");
}
//返回查询的公司的信息
function gsInfo(){
var vsGsName=$("#sGsName").val();
if(vsGsName!=""){
$.post("addEmp1_1.asp",{sGsName:vsGsName},function(m){
$("#content").html(m);
});
}
}
</script>
服务端代码
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
response.Charset="utf-8"
sGsName=unescape(trim(request.Form("sGsName")))
dbpath="demo.mdb"
sqlStr="select top 5 sgName from cominfo where sgName like '%"&sGsName&"%'"
connstr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath(dbPath)
set conn=server.CreateObject("adodb.connection")
conn.open connstr
set rs=conn.execute(sqlStr)
if not rs.bof and not rs.eof then
do while not rs.eof
str=str&"<a>"&rs("sgName")&"</a>"
rs.movenext
loop
else
str="<a>没有此公司</a>"
end if
rs.close
set rs=nothing
set conn=nothing
response.Write(escape(str))
%>
标签:jquery,提示,用户,鼠标
0
投稿
猜你喜欢
vue简单实现购物车结算功能
2024-05-28 15:54:57
你是真正的用户体验设计者吗? Ⅵ
2008-04-19 18:23:00
window.location的重写及判断location是否被重写
2024-04-28 10:18:17
TensorFlow人工智能学习按索引取数据及维度变换详解
2024-01-04 13:18:55
SqlServer 2005 T-SQL Query 学习笔记(1)
2024-01-25 17:01:56
thinkphp微信开发(消息加密解密)
2023-11-21 06:08:43
python 中关于pycharm选择运行环境的问题
2021-09-01 21:56:10
利用Axure封装视觉标准
2008-10-21 10:42:00
Python Matplotlib简易教程(小白教程)
2023-12-29 05:31:57
PyTorch的SoftMax交叉熵损失和梯度用法
2023-06-17 12:46:49
一文了解MySQL二级索引的查询过程
2024-01-25 23:24:54
IntelliJ IDEA下的SVN使用(傻瓜式教学)
2023-07-20 05:36:58
Python:Scrapy框架中Item Pipeline组件使用详解
2021-04-18 22:22:47
optgroup、sub、sup和bdo标签
2009-07-26 18:39:00
python如何判断IP地址合法性
2022-12-25 06:09:29
Pandas修改DataFrame列名的两种方法实例
2021-09-30 06:26:16
在Python的Flask中使用WTForms表单框架的基础教程
2023-05-10 05:20:08
javascript应用:Iframe自适应其加载的内容高度
2024-02-25 13:46:07
Python2包含中文报错的解决方法
2021-09-12 20:51:24
GOLANG版的冒泡排序和快速排序分享
2023-07-05 05:31:09