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>
|