Copy Code code as follows:
<select id= "name" name= "name"
Onkeydown= "Clearselect (this,event);"
Onkeypress= "Writeselect (this,event);" style= "width:70px;" >
<option value= "" ></option>
<option value= "Test1" >test1</option>
<option value= "Test2" >test2</option>
<option value= "Test3" >test3</option>
</select>
<script>
function Clearselect (obj,e)
{
opt = obj.options[0];
opt.selected = "selected";
if ((e.keycode== 8) | | | (e.charcode==8)) Use the BACKSPACE (BACKSPACE) key to implement the edit function for verbatim deletion
{
Opt.value = opt.value.substring (0, opt.value.length>0?opt.value.length-1:0);
Opt.text = Opt.value;
}
if ((e.keycode== 46) | | | (e.charcode==46)) Use the Delete key to implement the edit feature for verbatim deletion
{
Opt.value = "";
Opt.text = Opt.value;
}
You can also implement the response of other keystrokes
}
function Writeselect (obj,e)
{
opt = obj.options[0];
opt.selected = "selected";
Opt.value + + string.fromcharcode (e.charcode| | E.keycode);
Opt.text = Opt.value;
}
function Forbidbackspace ()//For in IE, to avoid backspace return to the previous page function, and this drop-down box edit function conflict, need to ban the function of backspace. Forbidbackspace can be written in <body onkeydown= "Forbidbackspace ();" > in.
{
if ((Event.keycode = 8) && (event.srcElement.type!= "text" && event.srcElement.type!= "textarea" && Amp Event.srcElement.type!= "password"))
{
Event.keycode = 0;
Event.returnvalue = false;
}
}
</script>