Js makes the drop down list box editable for more than just selection

  • 2020-03-30 00:53:19
  • OfStack

 
<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){//In order to avoid another annoying mess in firefox, try commenting this sentence to see how it works 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 value of options in the previous writeSelect function at the same time, so that you can directly use the value in the program
jQuery("#aa").empty(); 
jQuery("#aa").append("<option value=''></option>"); 
} 

</script> 

 
<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=" remove " onclick="ttt();"/> 

Related articles: