文章詳情頁
js select支持手動(dòng)輸入功能實(shí)現(xiàn)代碼
瀏覽:105日期: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. 如何對(duì)php程序中的常見漏洞進(jìn)行攻擊2. PHP循環(huán)與分支知識(shí)點(diǎn)梳理3. JSP+Servlet實(shí)現(xiàn)文件上傳到服務(wù)器功能4. ThinkPHP5 通過ajax插入圖片并實(shí)時(shí)顯示(完整代碼)5. JavaWeb Servlet中url-pattern的使用6. Spring MVC+ajax進(jìn)行信息驗(yàn)證的方法7. jsp EL表達(dá)式詳解8. ASP中格式化時(shí)間短日期補(bǔ)0變兩位長(zhǎng)日期的方法9. JSP之表單提交get和post的區(qū)別詳解及實(shí)例10. 利用ajax+php實(shí)現(xiàn)商品價(jià)格計(jì)算
排行榜
