The code copy is as follows:
<select id="name" name="name"
onkeydown="clearSelect(this,event);"
onkeypress="writeSelect(this,event);">
<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 key to implement the verbatim editing function of deletion verbatim
{
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 achieve the verbatim editing function
{
opt.value = "";
opt.text = opt.value;
}
//It can also realize the response of other keys
}
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()//In order to avoid backspace's return to the previous page function and conflict with the editing function of this drop-down box in IE, the backspace function needs to be disabled. forbidBackSpace can be written in <body onkeydown="forbidBackSpace();">.
{
if((event.keyCode == 8) && (event.srcElement.type != "text" && event.srcElement.type != "textarea" && event.srcElement.type != "password"))
{
event.keyCode = 0;
event.returnValue = false;
}
}
</script>