<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>

解决方案 »

  1.   

    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>New Page 1</title>
    </head><body>
    <select name="select" style="position:absolute; left: 197px; top: 80px; width: 120px; height: 22px; clip: rect(0 120 22 100)" id="select" onchange="clientUser.value=select.options[select.selectedIndex].text;clientUser.select()">
    <option value="1" selected>aaaaaa</option>
    <option value="2">bbbbb</option>
    </select> 
    <input type="text" style="position:absolute; left: 198px; top: 81px; width: 100px; height: 18px" name="clientUser" value="请选择二批名称" onfocus="this.select();">
    </body></html>