转:下拉框固定行数
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <script> function f(sel1) { var sel2=document.getElementById('select2'); var i=sel2.selectedIndex>0 ?sel2.selectedIndex :0; var name =sel2.options[i].innerHTML; var tmp=new Option(name,sel2.value); sel1.options[0]=tmp; sel2.style.display='inline'; sel1.style.width=sel2.offsetWidth; sel2.focus(); } function c(sel2) { var sel1=document.getElementById('select1'); var i=sel2.selectedIndex>0 ?sel2.selectedIndex :0; var name =sel2.options[i].innerHTML; var temp=new Option(name,sel2.value); sel1.options[0]=temp; sel2.style.display="none"; } </script> </head> <body> <select id="select1" onFocus="f(this)"> <option>dhh </option> </select> <br> <select id="select2" name="select" size="5" style="display:none;z-index:2; position:absolute;" onChange="c(this)" onBlur="this.style.display='none'"> <option>dhh </option> <option>bbb </option> <option>3 </option> <option>4 </option> <option>5 </option> <option>6 </option> <option>7 </option> <option>8 </option> <option>9 </option> <option>10 </option> </select> </body> </html>