DropDownList既能選擇又能輸入

來源:互聯網
上載者:User

<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("選項已存在,請重新輸入");

          return;

   }
  }
  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">
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
  </select>
</div>
<div class="cls2">
<input type="text" name="test" onkeydown="addOption()" size="20" style="width: 127; height: 23">
</div>

</body>
</html>

原貼地址:http://singlepine.cnblogs.com/articles/255144.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.