js?select支持手動輸入功能實現(xiàn)代碼
更新時間:2023年05月16日 00:32:10 作者:小魚娟娟
這篇文章主要介紹了js?select支持手動輸入實現(xiàn)代碼,需要的朋友可以參考下
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; }
使用方法
<!--調用--> <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之Canvas_動力節(jié)點Java學院整理
這篇文章主要介紹了JavaScript之Canvas,Canvas是HTML5新增的組件,它就像一塊幕布,可以用JavaScript在上面繪制各種圖表、動畫等2017-07-07layui(1.0.9)文件上傳upload,前后端的實例代碼
今天小編就為大家分享一篇layui(1.0.9)文件上傳upload,前后端的實例代碼,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-09-09