亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

js實(shí)現(xiàn)鍵盤上下左右鍵選擇文字并顯示在文本框的方法

 更新時(shí)間:2015年05月07日 10:07:33   投稿:shichen2014  
這篇文章主要介紹了js實(shí)現(xiàn)鍵盤上下左右鍵選擇文字并顯示在文本框的方法,涉及javascript操作鍵盤事件及文本框的相關(guān)技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下

本文實(shí)例講述了js實(shí)現(xiàn)鍵盤上下左右鍵選擇文字并顯示在文本框的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

<!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=utf-8">
<title>SimulateUpDownKeySelect.html</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}
#txtInput {width:205px;}
</style>
 </head>
 <body>
<form method="post" action="##">
<input type="text" id="txtInput" value="" autocomplete="off" onkeydown="if(event.keyCode==13)return false;" />
<!--
防止回車鍵觸發(fā)表單提交
onKeyPress
-->
<div id="divSelect">
</div>
<script type="text/javascript">
var list="<ul>"
list+="<li>科幻片</li><li>戰(zhàn)爭(zhēng)片</li><li>動(dòng)作片</li><li>愛(ài)情片</li><li>劇情片</li><li>記錄片</li><li>綜藝片</li><li>喜劇片</li><li>動(dòng)畫(huà)片</li><li>勵(lì)志片</li><li>恐怖片</li><li>古裝片</li><li>電視劇</li><li>讀書(shū)</li><li >小說(shuō)</li><li>作品集</li><li>歷史</li><li>詩(shī)歌</li><li >散文</li><li>軍事</li>";
list+="</ul>"
document.getElementById('divSelect').innerHTML=list;
</script>
</form>
<script type="text/javascript">
<!--
function $(sId)
{
  return document.getElementById(sId);
}
function clearSelectedOptBgColor(target)
{
  if (target.seletedIndex >= 0)
    target.options[target.seletedIndex].style.background = "";
}
function setSelectedOptBgColor(target)
{
  target.options[target.seletedIndex].style.background = "green";
}
var upKeyCode = 38;
var downKeyCode = 40;
var enterKeyCode = 13;
var oInput = $("txtInput");
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;
};
//-->
</script>
</body>
</html>

希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • JS計(jì)算斐波拉切代碼實(shí)例

    JS計(jì)算斐波拉切代碼實(shí)例

    這篇文章主要介紹了js計(jì)算斐波拉切,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-09-09
  • 微信打開(kāi)網(wǎng)址添加在瀏覽器中打開(kāi)提示的辦法

    微信打開(kāi)網(wǎng)址添加在瀏覽器中打開(kāi)提示的辦法

    這篇文章主要介紹了微信打開(kāi)網(wǎng)址添加在瀏覽器中打開(kāi)提示的辦法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-05-05
  • javascript 新聞列表排序簡(jiǎn)單封裝

    javascript 新聞列表排序簡(jiǎn)單封裝

    可以控制列表按日期以及按字?jǐn)?shù)排序.升或者降序.代碼簡(jiǎn)單封裝,按一定的格式調(diào)用即可。
    2009-11-11
  • csdn 博客的css樣式 v3

    csdn 博客的css樣式 v3

    僅相隔一天就出了個(gè)v3。 修正了一個(gè)bug,firefox左側(cè)內(nèi)容寬度錯(cuò)誤。
    2009-02-02
  • javaScript同意等待代碼實(shí)現(xiàn)心得

    javaScript同意等待代碼實(shí)現(xiàn)心得

    javaScript功能描述:本程序?qū)崿F(xiàn)在同意某某協(xié)議頁(yè)面對(duì)同意按鈕進(jìn)行十秒鐘的禁用,同時(shí)在按鈕的Value顯示倒計(jì)時(shí)。
    2011-01-01
  • Firefox/Chrome/Safari的中可直接使用$/$$函數(shù)進(jìn)行調(diào)試

    Firefox/Chrome/Safari的中可直接使用$/$$函數(shù)進(jìn)行調(diào)試

    偶然發(fā)現(xiàn)的,頁(yè)面中沒(méi)有引入Prototype和jQuery。控制臺(tái)中敲$卻發(fā)現(xiàn)是一個(gè)函數(shù)。又試著敲$$,也是個(gè)function
    2012-02-02
  • 詳解A標(biāo)簽中href=

    詳解A標(biāo)簽中href=""的幾種用法

    這篇文章主要介紹了a標(biāo)簽中href=""的幾種用法 ,需要的朋友可以參考下
    2017-08-08
  • JavaScript中的遍歷詳解(多種遍歷)

    JavaScript中的遍歷詳解(多種遍歷)

    編程這么多年,要是每次寫(xiě)遍歷代碼時(shí)都用 for 循環(huán),真心感覺(jué)對(duì)不起 JavaScript 語(yǔ)言,這篇文章為大家分享幾種不同的遍歷方法,需要的朋友可以參考下
    2017-04-04
  • Openlayers+EasyUI Tree動(dòng)態(tài)實(shí)現(xiàn)圖層控制

    Openlayers+EasyUI Tree動(dòng)態(tài)實(shí)現(xiàn)圖層控制

    這篇文章主要為大家詳細(xì)介紹了Openlayers+EasyUI Tree動(dòng)態(tài)實(shí)現(xiàn)圖層控制,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-09-09
  • js特殊字符過(guò)濾的示例代碼

    js特殊字符過(guò)濾的示例代碼

    本篇文章主要是對(duì)js特殊字符過(guò)濾的示例代碼進(jìn)行了介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助
    2014-03-03

最新評(píng)論