Js makes the drop-down list box editable not only select
The drop-down list box cannot be edited by default. The following describes a good way to edit the drop-down list box. The specific implementation is as follows. For more information, see
The Code is as follows:
<Script>
Function clearOption (obj, e ){
Var currKey = 0, e = e | event;
CurrKey = e. keyCode | e. which | e. charCode;
If (currKey = 8 ){
Obj. options [0]. text = "";
}
}
Function writeSelect (obj, e ){
Var currKey = 0, e = e | event;
CurrKey = e. keyCode | e. which | e. charCode;
Obj. options [0]. selected = "select ";
If (currKey! = 8) {// This part is intended to avoid annoying Garbled text in firefox. You can try to comment this sentence to see the effect in firefox.
Obj. options [0]. text = obj. options [0]. text + String. fromCharCode (currKey );
}
E. returnValue = false;
Return obj. options [0]. text;
}
Function ttt (){
Var jg = document. getElementById ("aa"). options [document. getElementById ("aa"). selectedIndex]. text;
// Of course, you can also set the options value in the previous writeSelect function. In this way, you can use the value in the program to retrieve the value.
JQuery ("# aa"). empty ();
JQuery ("# aa"). append ("<option value =''> </option> ");
}
</Script>
The Code is as follows:
<Select style = 'width: 150px; z-index:-1 'id = "aa" name = "selectHelpCode" onkeydown = "clearOption (this, event) "onkeypress =" writeSelect (this, event) ">
<Option value = ""> </option>
<Option value = "11"> 11 </option>
<Option value = "22"> 22 </option>
<Option value = "33"> 33 </option>
</Select>
<Input type = "button" value = "clear" onclick = "ttt ();"/>