可输入的下拉列表js

    技术2022-05-11  17

    <HEAD>   <style>    <!--     .cls1 { position:absolute; left:20px; top:20px; width:216px; height:72px; z-index:1; }     .cls2 { position:absolute; left:20px; top:20px; width:95px; height:18px; z-index:2 }     input { font-size: 12px; padding-top: 2px; padding-left: 2px;width:127;}    //-->   </style>   <script language="javascript">   function add(val) {   var all = document.getElementById("n");   var max = all.options.length;   if(val.replace(/(/s+)/,'')==''){   return;   }   for (var i=0;i<max;i++) {   if (all.options[i].text==val) {   return;   }   }   all.options.add(new Option(val));   }     function selectchange(val)   {    var fl = 0;    var all = document.getElementById("n");    var max = all.options.length;    if(val.replace(/(/s+)/,'')==''){    alert("11");    return;    }    for (var i=0;i<max;i++)    {     if (all.options[i].text==val)     {      fl = 1;      all.value = all.options[i].value;      //alert(all.value);      return;     }    }    if(fl == 0)    {     alert("111");     document.getElementById("m").focus();    }   }   </script>  </HEAD>  <body>   <form name="form1">    <div class="cls2">     <input type="text" name="m" value="1" onPaste="alert('in put');return false" onBlur="selectchange(this.value)" size="20" style="width: 127; height: 23">    </div>    <div class="cls1" style="clip: rect(3 280 21 110)">     <select  name="n" onChange="this.form.m.value=this.options[selectedIndex].text" id="n" style="width:127; height: 23" >      <option value=1>1</option>      <option value=2>2</option>      <option value=3>3</option>     </select>    </div>   </form>  </body> 

    最新回复(0)