您正在使用 IPV4 [3.145.52.86] 访问本站,您本次已经查看了 1 页
用户名: 密 码: 验证码:     用QQ登录本站
首页 软件 编程 笑话 知识 公告 台风 日历 计算器
[公益]保护绿色环境,构建和谐社会       悟空收录网      

【腾讯云】 爆款2核2G3M云服务器首年 61元,叠加红包再享折上折      
[公益] 地球是我家,绿化靠大家      
2024年 劳动节 012
2024年 端午节 052
2025年 元 旦 257
2025年 春 节 285
 
您现在的位置:首页 >> 脚本代码 >> 内容
本类新增
本类热门
js select支持手动输入功能实现代码
内容摘要: select下拉框的onkeydown事件,修改下拉框的值functioncatch_keydown(sel){switch(event.keyCode){case13://回车键event.returnValue=false;break;case27://Esc键sel.options[sel.selectedIndex].text=oldText;sel......
select下拉框的onkeydown事件,修改下拉框的值

functioncatch_keydown(sel){

switch(event.keyCode){

case13://回车键

event.returnValue=false;

break;

case27://Esc键

sel.options[sel.selectedIndex].text=oldText;

sel.options[sel.selectedIndex].value=oldValue;

event.returnValue=false;

break;

case8://空格健

vars=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事件,修改下拉框的值

functioncatch_press(sel){

if(sel.selectedIndex>=0){

vars=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事件,保存下拉框原来的值

functioncatch_focus(sel){

oldText=sel.options[sel.selectedIndex].value;

oldValue=sel.options[sel.selectedIndex].value;

}

使用方法

<!--调用-->

<selectstyle='width:130px;z-index:-1'name='tmpSel'onkeydown=catch_keydown(this)onkeypress=catch_press(this)onfocus=catch_focus(this)>

<optionvalue=''></option>

<optionvalue=''>A</option>

<optionvalue=''>B</option>

<optionvalue=''>C</option>

</select>

版权声明:本内容来源于网络,如有侵犯您的版权,请联系站长,本站收到您的信息后将及时处理。
上一篇:html+css实现div居中的8种方法

 

下一篇:纯JS实现本地图片预览的方法

发布日期:2023/5/29
手机扫二维码直达本页
发布时间:16:58:26
点  击:8
录  入:壹家怡园
相关文章
Baidu
YiJiaCMS 7.3.8 build231228(MSSQL) 闽ICP备05000814号-1
本空间由腾讯云(轻量应用服务器)提供,Cloudflare提供加速防护
运行时间载入中.....