<!doctype html><html><head>?? ?<meta charset="UTF-8">?? ?<title>Document</title>?? ?<style type="text/css">?? ?#sea{?? ??? ?width: 300px;?? ??? ?height: 35px;?? ??? ?border: solid #666 1px;?? ??? ?padding-left: 5px;?? ?}?? ?#ul1,li,input{?? ??? ?padding: 0;?? ??? ?margin: 0;?? ??? ?list-style: none?? ?}?? ?#ul1{?? ??? ?border: solid #666 1px;?? ??? ?width: 305px;?? ??? ?margin-top: -2px; ?? ??? ??? ??? ?display: none;?? ?}?? ?#ul1 li a{?? ??? ?line-height: 35px;?? ??? ??? ??? ?display: block;?? ??? ?width: 300px;?? ??? ?padding-left: 5px;?? ??? ?text-decoration: none;?? ??? ?color: black;?? ??? ??? ?}?? ??? ??? ?</style>?? ?<script type="text/javascript">?? ?function maiov(data){?? ?var oUl=document.getElementById('ul1')?? ?var html=" ";?? ?for (var i = 0; i < data.s.length; i++) {?? ??? ?html += '<li><a target="_blank" + data.s[i] +'</a></li>';?? ?};??????????? oUl.style.display="block"?? ?oUl.innerHTML=html;?? ?}?? ??? ?window.onload=function(){????????????????? ??? ??? ?var s=document.getElementById('sea');?? ??? ?var oLl=document.getElementById('ul1').getElementsByTagName('li')?? ??? ?s.onkeyup=function(){?? ??? ???? var oScript=document.createElement("script")?? ??? ???? oScript.src='http://suggestion.baidu.com/su?wd='+this.value+'&cb=maiov'?? ??? ???? document.body.appendChild(oScript);?? ??? ??? ?};?? ??? ?var index=-1;?? ??????????????? ??? ?????????? document.onkeydown=function(event){?? ????????? ??? ?if(event.keyCode===40){?? ????????? ??? ??? ?for (var i = 0; i < oLl.length; i++) {?? ????????? ??? ??? ??? ?oLl[index].style.backgroundColor="red"?? ????????? ??? ??? ?};?? ?????????? ??? ?}?? ?????? }?? ?}?? ??? ?</script>?? ?</head><body>?? ?<input id="sea" type="text">?? ?<ul id="ul1">?? ??? ?</ul>?? ?</body></html>
想做用鍵盤上下鍵控制高亮,可是綁定了documental.keydown事件后鍵盤松開后,高亮瞬間又沒了,真心求解
慕粉4084340
2016-12-28 20:28:07