国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

js select支持手動輸入功能實現(xiàn)代碼

瀏覽:71日期:2022-06-10 14:49:20

select下拉框的onkeydown事件,修改下拉框的值

  function catch_keydown(sel){
   switch(event.keyCode) {
    case 13: //回車鍵
     event.returnValue = false;
     break;
    case 27: //Esc鍵
     sel.options[sel.selectedIndex].text = oldText;
     sel.options[sel.selectedIndex].value = oldValue;
     event.returnValue = false;
     break;
    case 8:  //空格健
     var s = sel.options[sel.selectedIndex].text;
     s = s.substr(0,s.length-1);
     if (sel.options[0].value==sel.options[sel.selectedIndex].text){
      sel.options[sel.selectedIndex].value=s;
      sel.options[sel.selectedIndex].text=s;
     }
     event.returnValue = false;
     break;
   }
   if (!event.returnValue && sel.onchange)
    sel.onchange(sel)
  }

select下拉框的onkeypress事件,修改下拉框的值

  function catch_press(sel){
   if(sel.selectedIndex>=0){
    var s = sel.options[sel.selectedIndex].text + String.fromCharCode(event.keyCode);
    if (sel.options[sel.selectedIndex].value==sel.options[sel.selectedIndex].text){
     sel.options[sel.selectedIndex].value=s;
     sel.options[sel.selectedIndex].text=s;
    }
    event.returnValue = false;
    if (!event.returnValue && sel.onchange)
     sel.onchange(sel)
   }
  }

select下拉框的onfocus事件,保存下拉框原來的值

  function catch_focus(sel) {
   oldText = sel.options[sel.selectedIndex].value;
   oldValue = sel.options[sel.selectedIndex].value;
  }   

使用方法

<!--調(diào)用-->
<select style="width:130px;z-index:-1" name="tmpSel"    onkeydown=catch_keydown(this) onkeypress=catch_press(this) onfocus=catch_focus(this)>
  <option value=""></option>
  <option value="">A</option>
  <option value="">B</option>
  <option value="">C</option>
</select>

到此這篇關于js select支持手動輸入功能實現(xiàn)代碼的文章就介紹到這了,更多相關js select 手動輸入內(nèi)容請搜索以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持!

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 高尔夫| 桂阳县| 城市| 忻州市| 科技| 调兵山市| 西华县| 巧家县| 常宁市| 连州市| 广宁县| 蓝田县| 朝阳县| 安阳市| 门头沟区| 拜泉县| 东兴市| 盐源县| 昌平区| 淄博市| 蓬安县| 万州区| 汉源县| 司法| 金沙县| 蕉岭县| 海盐县| 旺苍县| 临沂市| 黔南| 丰都县| 扎赉特旗| 华安县| 城市| 增城市| 建水县| 永胜县| 尼玛县| 红原县| 通许县| 柘荣县|