js使下拉列表框可编辑不单是选择
发布时间:2023-08-22 14:58:21 所属栏目:教程 来源:
导读:代码如下:
<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 = "";
}
}
fu
<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 = "";
}
}
fu
代码如下: <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 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="清除" onclick="ttt();"/> (编辑:聊城站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐