源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

js使下拉列表框可编辑不止是选择

  • 时间:2020-07-08 09:39 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:js使下拉列表框可编辑不止是选择
[u]复制代码[/u] 代码如下:
<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>
[u]复制代码[/u] 代码如下:
<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();"/>
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部