文章詳情頁
js select支持手動(dòng)輸入功能實(shí)現(xiàn)代碼
瀏覽:82日期: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>
到此這篇關(guān)于js select支持手動(dòng)輸入功能實(shí)現(xiàn)代碼的文章就介紹到這了,更多相關(guān)js select 手動(dòng)輸入內(nèi)容請(qǐng)搜索以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持!
標(biāo)簽:
JavaScript
相關(guān)文章:
1. JavaScript設(shè)計(jì)模式之策略模式實(shí)現(xiàn)原理詳解2. idea設(shè)置代碼格式化的方法步驟3. Python tkinter制作單機(jī)五子棋游戲4. 八種Vue組件間通訊方式合集(推薦)5. GIT相關(guān)-IDEA/ECLIPSE工具配置的教程詳解6. Django Auth用戶認(rèn)證組件實(shí)現(xiàn)代碼7. 完美實(shí)現(xiàn)CSS垂直居中的11種方法8. vue項(xiàng)目登錄成功拿到令牌跳轉(zhuǎn)失敗401無登錄信息的解決9. JSP頁面跳轉(zhuǎn)方法大全10. ASP中if語句、select 、while循環(huán)的使用方法
排行榜
