復制代碼 代碼如下:
 
<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){//這個地方是為了避免在firefox又出現令人厭煩的亂碼,可以試試注釋這句話,看看在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; 
//當然也可以在前面的writeSelect函數里面同時設置options的value,這樣的話,直接可以在該程序里面用value取出 
jQuery("#aa").empty(); 
jQuery("#aa").append("<option value=''></option>"); 
} 
</script> 
復制代碼 代碼如下:
 
<select 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="清除"/> 
新聞熱點
疑難解答
圖片精選