Copy the code code 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 place is to avoid annoying garbled characters in firefox. You can try commenting 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;
}
functionttt(){
var jg = document.getElementById("aa").options[document.getElementById("aa").selectedIndex].text;
//Of course, you can also set the value of options in the previous writeSelect function at the same time. In this case, you can directly use the value to take it out in the program.
jQuery("#aa").empty();
jQuery("#aa").append("<option value=''></option>");
}
</script>
Copy the code code 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();"/>