代码如下:
<input onkeyup="showtips();if(event.keyCode==27)c();" id=txt onkeydown='enterTips()'>(eg. JiangSu)输完按回车键<br>
<select id=sel style='display:none' multiple onclick=rv() onkeydown='if(event.keyCode==13)rv()'></select>
<script>
var msg = new Array("Beijing","Tianjing","Shanghai","Guangdong","ShanDong","Shanxi","Hunan","Hubei","JiangSu","JiangXi");
var msg2=new Array("北京","天津","上海","广东","山东","陕西","湖南","湖北","江苏","江西");
function showtips(){
eo=event.srcElement;
sel.length=0;
var len=msg.length;
var re=new RegExp("^"+eo.value,"i")
for(i=0;i<len;i++) if(re.test(msg[i])==true) sel.style.display='',sel.add(new Option(msg[i],msg2[i])),sel.selectedIndex=0;
}
function enterTips(){
e=event.keyCode;
if(sel.style.display!='none'){
if(e==13) event.srcElement.value=sel.value,sel.style.display='none';
if(e==40) sel.focus();
}
}
function rv(){txt.value=sel.value,c()}
function c(){sel.style.display='none';txt.focus()}
document.onclick=function(){c()}
</script>
[Ctrl+A 全选 提示:你可先修改部分代码,再点运行代码]