一张表单用到多个带提示的输入框该怎么做? 我现在做了一个表单,里面有多个输入框是需要提示的,累死百度、google那样的。提示内容都是从数据库中读取出来的,选中一调后,进入输入框的是名称,id进入隐藏的输入框。请教各位这个该怎么做。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用autocomplete控件吧参考:http://topic.csdn.net/u/20110802/14/0A36241C-327A-472F-8864-A9413DE3EFCD.html 顶1楼 用过autocomplete控件不错 使用ajax具体应该怎么做呢,有没有例子给推荐下 <!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> <title></title> <style type ="text/css"> html,body{width:100%;height:100%} ul{padding:0px;margin:0px;list-style:none;} li{cursor:pointer;padding:0px 5px; line-height:25px;height:25px;} </style></head><body> <p> <input type='text' id='txtInput' onkeyup='getSearchKeys()'/> <div id='divShow' style="position:absolute; z-index:9999; width:200px; height:auto; display:none;border:1px solid #ddd"> <ul> <li>aaa</li> </ul> </div> </p></body><script type="text/javascript">var keys=['ada','sdfsd','bbb','sfga','dfhgfh','235s','dfew','ghjk','hjkghjk','fgjgfjf','fghjgfj','2345f','fthtr','sfgerw','tyerth','vnmu','wertewr','wert','asdfaf','zxcvd','gkju','dvfgdh','2354af','adsf','erterter','fghdfg','xvdfg','kjhu','qweasdas','xzce','werwre','zzczc','rtewtrew']; // 搜索值,可以用Ajax从数据库获取var txtInput ;var divShow ;window.onload=function(){ txtInput =document.getElementById("txtInput"); divShow = document.getElementById("divShow"); var p =getAbsPoint(txtInput); divShow.style.left = p.x +'px'; divShow.style.top = p.y + txtInput.offsetHeight + 'px'; txtInput.onclick = divShow.onclick=function(e) { e = e||event; var t = e.target||e.srcElement if(t.tagName.toLowerCase()=='li') { txtInput.value = t.innerHTML; divShow.style.display = "none"; return; } if(e && e.stopPropagation){ //W3C取消冒泡事件 e.stopPropagation(); }else{ //IE取消冒泡事件 window.event.cancelBubble = true; } }; document.body.onclick=function(e) { divShow.style.display = "none"; };};function getSearchKeys(){ var s= txtInput.value; if(s=='') { divShow.style.display = "none"; return; } var arr=['<ul>']; for(var i=0;i<keys.length;i++) { if(keys[i].indexOf(s)>=0){ arr.push('<li>'+keys[i]+'</li>'); } } if(arr.length>1){ arr.push('</ul>'); divShow.innerHTML = arr.join(''); divShow.style.display = "block"; }else{ divShow.style.display = "none"; }}function getAbsPoint(e){ var x = e.offsetLeft; var y = e.offsetTop; while(e = e.offsetParent) { x += e.offsetLeft; y += e.offsetTop; } return {"x": x, "y": y};}</script></html> 版主救命 IE6 png opacity 把click更改成mouseover 最好用toggle 这段简单的js如何修改呢,不解啊 IE动态修改 input hidden 的值!! 现在哪个公司招人啊,我想去当程序员了(限广州) 怪哉!!return confirm()和 return true(在线) 为什么我的表单不能提交 window.open 大哥们帮忙!!!!!!111 关于JS的onload方法问题 请高手优化此代码,功能已经实现,想改善页面运行速度,望赐教 jsp500错误
参考:
http://topic.csdn.net/u/20110802/14/0A36241C-327A-472F-8864-A9413DE3EFCD.html
<!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>
<title></title>
<style type ="text/css">
html,body{width:100%;height:100%}
ul{padding:0px;margin:0px;list-style:none;}
li{cursor:pointer;padding:0px 5px; line-height:25px;height:25px;}
</style>
</head>
<body>
<p>
<input type='text' id='txtInput' onkeyup='getSearchKeys()'/>
<div id='divShow' style="position:absolute; z-index:9999; width:200px; height:auto; display:none;border:1px solid #ddd">
<ul>
<li>aaa</li>
</ul>
</div>
</p>
</body>
<script type="text/javascript">
var keys=['ada','sdfsd','bbb','sfga','dfhgfh','235s','dfew','ghjk','hjkghjk','fgjgfjf','fghjgfj','2345f','fthtr','sfgerw','tyerth','vnmu','wertewr','wert','asdfaf','zxcvd','gkju','dvfgdh','2354af','adsf','erterter','fghdfg','xvdfg','kjhu','qweasdas','xzce','werwre','zzczc','rtewtrew']; // 搜索值,可以用Ajax从数据库获取
var txtInput ;
var divShow ;
window.onload=function()
{
txtInput =document.getElementById("txtInput");
divShow = document.getElementById("divShow");
var p =getAbsPoint(txtInput);
divShow.style.left = p.x +'px';
divShow.style.top = p.y + txtInput.offsetHeight + 'px';
txtInput.onclick = divShow.onclick=function(e)
{
e = e||event;
var t = e.target||e.srcElement if(t.tagName.toLowerCase()=='li')
{
txtInput.value = t.innerHTML;
divShow.style.display = "none";
return;
}
if(e && e.stopPropagation){
//W3C取消冒泡事件
e.stopPropagation();
}else{
//IE取消冒泡事件
window.event.cancelBubble = true;
}
};
document.body.onclick=function(e)
{
divShow.style.display = "none";
};
};
function getSearchKeys()
{
var s= txtInput.value;
if(s=='')
{
divShow.style.display = "none";
return;
}
var arr=['<ul>'];
for(var i=0;i<keys.length;i++)
{
if(keys[i].indexOf(s)>=0){
arr.push('<li>'+keys[i]+'</li>');
}
}
if(arr.length>1){
arr.push('</ul>');
divShow.innerHTML = arr.join('');
divShow.style.display = "block";
}else{
divShow.style.display = "none";
}
}function getAbsPoint(e)
{
var x = e.offsetLeft;
var y = e.offsetTop;
while(e = e.offsetParent)
{
x += e.offsetLeft;
y += e.offsetTop;
}
return {"x": x, "y": y};
}
</script>
</html>