Copy codeThe Code is 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 key to edit a verbatim deletion function
{
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 edit a word-by-word deletion.
{
Opt. value = "";
Opt. text = opt. value;
}
// Other buttons can be responded
}
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 () // to prevent the Back-to-Previous Page function of backspace from conflicting with the Edit function of the drop-down box in IE, you must disable the backspace function. 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>