按方向键后能在多个下拉选项中自由选择某个选项值,然后把选中的值写入光标所在的文本框位置。
<!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> <meta http-equiv="content-type" content="text/html;charset=gb2312"> <meta name="keywords" content="武鸣人网站,武鸣信息网,武鸣本地网,武鸣信息资源平台,减肥,健身,励志,励志语录,js特效,网页特效,www.wuming.ren"> <meta name="description" content="欢迎来到武鸣人信息资源平台,各种信息免费发布,资源共享合作共赢,分享互联网流行的励志语录经典短句,减肥健身健康小常识及打卡记录,收集各种js特效代码。"> <title>通过方向键来选择项目_武鸣人</title> <style type="text/css"> #divSelect{border:1px solid red;width:208px !important;width:210px;} #divSelect ul{width:200px;margin:3px;margin-left:-35px;*margin-left:3px;overflow:hidden;} #divSelect ul li{float:left;list-style-type:none;width:45px;height:14px;line-height:20px;font:14px arial;text-align:center;padding:2px;} #divSelect li:hover{background:green;cursor:pointer;} #www_wuming_ren{width:205px;} </style> </head> <body> <a href="https://www.wuming.ren">武鸣人</a>,各种信息资源免费发布,分享励志语录经典短句,减肥健身常识,各种js特效代码。网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)<hr> <!--欢迎来到武鸣人信息资源平台,各种信息免费发布,资源共享合作共赢,分享互联网流行的励志语录经典短句,减肥健身健康小常识及打卡记录,收集各种js特效代码。--> <script type="text/javascript" src="https://www.wuming.ren/ad/tc.js"></script> <script type="text/javascript" src="https://www.wuming.ren/ad/a.js"></script> 点下下面的文本框然后按方向键<br /> <form method="post" action="##"> <input type="text" id="www_wuming_ren" value="" autocomplete="off" onkeydown="if(event.keyCode==13)return false;"> <!-- 防止回车键触发表单提交 onKeyPress --> <div id="divSelect"></div> <script type="text/javascript"> var list="<ul>" list+="<li>wuming</li><li>战争片</li><li>动作片</li><li>爱情片</li><li>剧情片</li><li>记录片</li><li>fbac</li><li>bbca</li><li>defe</li><li>gzza</li><li>恐怖片</li><li>古装片</li><li>电视剧</li><li>读书</li><li >小说</li><li>作品集</li><li>历史</li><li>诗歌</li><li >散文</li><li>军事</li>"; list+="</ul>" document.getElementById('divSelect').innerHTML=list; </script> </form> <script type="text/javascript"> <!-- function $(sId) { return document.getElementById(sId); }//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀) function clearSelectedOptBgColor(target) { if (target.seletedIndex >= 0) target.options[target.seletedIndex].style.background = ""; }//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀) function setSelectedOptBgColor(target) { target.options[target.seletedIndex].style.background = "green"; }//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀) var upKeyCode = 38; var downKeyCode = 40; var enterKeyCode = 13; var oInput = $("www_wuming_ren"); oInput.options = $("divSelect").getElementsByTagName("li"); oInput.seletedIndex = -1; oInput.focus(); //oInput.onKeyPress{} oInput.onkeyup = function(event){ if (event == undefined) event = window.event; switch (event.keyCode) { case 37: clearSelectedOptBgColor(this); this.seletedIndex--; if (this.seletedIndex < 0) this.seletedIndex = this.options.length - 1; this.value = this.options[this.seletedIndex].innerHTML; setSelectedOptBgColor(this); break; case 38: clearSelectedOptBgColor(this); this.seletedIndex= this.seletedIndex-4; if (this.seletedIndex < 0) this.seletedIndex = this.options.length - 1; this.value = this.options[this.seletedIndex].innerHTML; setSelectedOptBgColor(this); break; case 39: clearSelectedOptBgColor(this); this.seletedIndex++; if (this.seletedIndex >= this.options.length) this.seletedIndex = 0; this.value = this.options[this.seletedIndex].innerHTML; setSelectedOptBgColor(this); break; case 40: clearSelectedOptBgColor(this); this.seletedIndex= this.seletedIndex+4; if (this.seletedIndex >= this.options.length) this.seletedIndex = 0; this.value = this.options[this.seletedIndex].innerHTML; setSelectedOptBgColor(this); break; case enterKeyCode: this.value = this.options[this.seletedIndex].innerHTML; //alert('aa') break; } }; oInput.onblur = function(){ clearSelectedOptBgColor(this); this.seletedIndex = 1; };//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀) //--> </script> </body> </html>
本文来自武鸣人网站,转载请注明出处