当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 可输入的select

Javascript
纯JS半透明Tip效果代码
JavaScript 读URL参数增强改进版版
JS对URL字符串进行编码/解码分析
javescript完整操作Table的增加行,删除行的列子大全
js可填可选的下拉框
prototype Element学习笔记(篇一)
prototype Element学习笔记(篇二)
prototype Element学习笔记(Element篇三)
Prototype使用指南之selector.js说明
不唐突的JavaScript的七条准则整理收集
js判断变量是否空值的代码
Firefox getBoxObjectFor getBoundingClientRect联系
Div自动滚动到末尾的代码
javascript笔试题目附答案
javascript引导程序
js身份证验证超强脚本
JS给元素注册事件的代码
JavaScript函数、方法、对象代码
JS写的数字拼图小游戏代码[学习参考]
关于B/S判断浏览器断开的问题讨论

Javascript 中的 可输入的select


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-10   浏览: 495 ::
收藏到网摘: n/a

做了一点小修改,希望对大家有用!!

<html>
<head>
<style>
<!--
.cls1 { position:absolute; left:250px; top:89px; width:216px; height:72px; z-index:1; }
.cls2 { position:absolute; left:250px; top:89px; width:95px; height:18px; z-index:2 }
input { font-size: 12px; padding-top: 2px; padding-left: 2px;width:127;}
//-->
</style>
</head>
<script>
<!--
function addOption(pos){

 if(event.keyCode==13)
 {
  var select_obj = document.getElementById("myselect");
  var text_value   = document.getElementById("test").value;

  if (select_obj.length)
  {
   for (var i=0;i<select_obj.length;i++)
   {
    // 如果已经存在,不添加,直接退出
    if (select_obj.options[i].text==text_value)
     alert("选项已存在,请重新输入");
   }
  }
  var the_option= new Option(text_value,text_value);
  
  select_obj.add(the_option);

  select_obj.selectedIndex = select_obj.options.length-1
 }  
 
}
//-->
</script>
<div class="cls1" style="clip: rect(3 280 21 110)">
  <select name="myselect" style="width:127" onchange="document.getElementById('test').value=this.value">
  </select>
</div>
<div class="cls2">
<input type="text" name="test" onkeydown="addOption()" size="20" style="width: 127; height: 23">
</div>

</body>
</html>