首页 > 代码库 > 可输入的Select【屏蔽了backspace事件】
可输入的Select【屏蔽了backspace事件】
window.onload=function(){
document.getElementsByTagName("body")[0].onkeydown =function(){
if(event.keyCode==8){
var elem = event.srcElement;
var name = elem.nodeName;
if(name!=‘INPUT‘ && name!=‘TEXTAREA‘){
event.returnValue = http://www.mamicode.com/false ;
return ;
}
var type_e = elem.type.toUpperCase();
if(name==‘INPUT‘ && (type_e!=‘TEXT‘ && type_e!=‘TEXTAREA‘ && type_e!=‘PASSWORD‘ && type_e!=‘FILE‘)){
event.returnValue = http://www.mamicode.com/false ;
return ;
}
if(name==‘INPUT‘ && (elem.readOnly==true || elem.disabled ==true)){
event.returnValue = http://www.mamicode.com/false ;
return ;
}
}
}
}
var Select = {
del : function(obj,e){
if((e.keyCode||e.which||e.charCode) == 8){
var opt = obj.options[0];
opt.text = opt.value = http://www.mamicode.com/opt.value.substring(0, opt.value.length>0?opt.value.length-1:0);
}
},
write : function(obj,e){
if((e.keyCode||e.which||e.charCode) == 8)return ;
var opt = obj.options[0];
opt.selected = "selected";
opt.text = opt.value += String.fromCharCode(e.charCode||e.which||e.keyCode);
}
}
可输入的Select【屏蔽了backspace事件】