ajax下拉动态提示

ajax下拉动态提示
<scriptlanguage="javascript">
varintIndex=0;arrList=newArray();
arrList[intIndex++]="1sdfsdf.com";
arrList[intIndex++]="a11sdafs.net";
arrList[intIndex++]="b22dsafsdf";
arrList[intIndex++]="c333asdfsadf";
arrList[intIndex++]="4444dsafasdf";
arrList[intIndex++]="dddsfddsafdsaf";
arrList[intIndex++]="121213dsafsdaf";
arrList[intIndex++]="43213asdfadsf";
arrList[intIndex++]="dsa3121dasf3";
arrList[intIndex++]="a213";
arrList[intIndex++]="323313";
arrList[intIndex++]="3213";
arrList[intIndex++]="32213";
arrList[intIndex++]="dsfsdddd";
arrList[intIndex++]="ds11dfsfd";
arrList[intIndex++]="ffdafd";
arrList[intIndex++]="afdfd";
arrList[intIndex++]="afd";
arrList[intIndex++]="baffad";
arrList[intIndex++]="2fda2fd";
arrList[intIndex++]="dasd";

functionsmanPromptList(arrList,objInputId){
this.style="background:#E8F7EB;border:1pxsolid#CCCCCC;font-size:14px;cursor:default;"
if(arrList.constructor!=Array){alert('smanPromptList初始化失败:第一个参数非数组!');return;}
window.onload=function(){
arrList.sort(function(a,b){
if(a.length>b.length)return1;
elseif(a.length==b.length)returna.localeCompare(b);
elsereturn-1;
})
varobjouter=document.getElementById("__smanDisp")//显示的DIV对象
varobjInput=document.getElementById(objInputId);//文本框对象
varselectedIndex=-1;
varintTmp;//循环用的:)
if(objInput==null){alert('smanPromptList初始化失败:没有找到"'+objInputId+'"文本框');return;}
//文本框失去焦点
objInput.onblur=function(){
objouter.style.display='none';
}
//文本框按键抬起
objInput.onkeyup=checkKeyCode;
//文本框得到焦点
objInput.onfocus=checkAndShow;
functioncheckKeyCode(){
varie=(document.all)?true:false
if(ie){
varkeyCode=event.keyCode
if(keyCode==40||keyCode==38){//下上
varisUp=false
if(keyCode==40)isUp=true;
chageSelection(isUp)
}elseif(keyCode==13){//回车
outSelection(selectedIndex);
}else{
checkAndShow()
}
}else{
checkAndShow()
}
divPosition()
}

functioncheckAndShow(){
varstrInput=objInput.value
if(strInput!=""){
divPosition();
selectedIndex=-1;
objouter.innerHTML="";
for(intTmp=0;intTmp<arrList.length;intTmp++){
if(arrList[intTmp].substr(0,strInput.length).toUpperCase()==strInput.toUpperCase()){
addOption(arrList[intTmp]);
}
}
objouter.style.display='';
}else{
objouter.style.display='none';
}
functionaddOption(value){
objouter.innerHTML+="<divonmouseover=\"this.className='sman_selectedStyle'\"onmouseout=\"this.className=''\"onmousedown=\"document.getElementById('"+objInputId+"').value='"+value+"'\">"+value+"</div>"
}
}
functionchageSelection(isUp){
if(objouter.style.display=='none'){
objouter.style.display='';
}else{
if(isUp)
selectedIndex++
else
selectedIndex--
}
varmaxIndex=objouter.children.length-1;
if(selectedIndex<0){selectedIndex=0}
if(selectedIndex>maxIndex){selectedIndex=maxIndex}
for(intTmp=0;intTmp<=maxIndex;intTmp++){

if(intTmp==selectedIndex){
objouter.children[intTmp].className="sman_selectedStyle";
}else{
objouter.children[intTmp].className="";
}
}
}
functionoutSelection(Index){
objInput.value=objouter.children[Index].innerText;
objouter.style.display='none';
}
functiondivPosition(){
objouter.style.top=getAbsoluteHeight(objInput)+getAbsoluteTop(objInput);
objouter.style.left=getAbsoluteLeft(objInput);
objouter.style.width=getAbsoluteWidth(objInput)
}
}
document.write("<divid='__smanDisp'style='position:absolute;display:none;"+this.style+"'onbulr></div>");
document.write("<style>.sman_selectedStyle{background-Color:#102681;color:#FFFFFF}</style>");
functiongetAbsoluteHeight(ob){
returnob.offsetHeight
}
functiongetAbsoluteWidth(ob){
returnob.offsetWidth
}
functiongetAbsoluteLeft(ob){
varmendingLeft=ob.offsetLeft;
while(ob!=null&&ob.offsetParent!=null&&ob.offsetParent.tagName!="BODY"){
mendingLeft+=ob.offsetParent.offsetLeft;
mendingOb=ob.offsetParent;
}
returnmendingLeft;
}
functiongetAbsoluteTop(ob){
varmendingTop=ob.offsetTop;
while(ob!=null&&ob.offsetParent!=null&&ob.offsetParent.tagName!="BODY"){
mendingTop+=ob.offsetParent.offsetTop;
ob=ob.offsetParent;
}
returnmendingTop;
}
}
smanPromptList(arrList,"inputer")
</script>

<inputtype="text"id="inputer">
http://www.corange.cn/archives/2008/03/564.html

你可能感兴趣的:(JavaScript,Ajax,.net,IE)