JS+CSS实现实用的单击输入框弹出选择框的方法
本文实例讲述了JS+CSS实现实用的单击输入框弹出选择框的方法。分享给大家供大家参考。具体实现方法如下:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <htmlxmlns="http://www.w3.org/1999/xhtml"> <head> <title>JS+CSS打造实用的单击输入框弹出选择框效果</title> <styletype="text/css"> .black_overlay{display:none;position:absolute;top:0%;left:0%;width:100%;height:100%;background-color:#FFFFFF;z-index:1001;-moz-opacity:0.8;opacity:.80;filter:alpha(opacity=80);} .white_content{display:none;position:absolute;top:25%;left:25%;width:50%;height:50%;padding:16px;border:16pxsolidorange;margin:-32px;background-color:white;z-index:1002;overflow:auto;} </style> <scriptlanguage="javascript"type="text/javascript"> functionmoveselect(obj,target,all){ if(!all)all=0 if(obj!="[object]")obj=eval("document.all."+obj) target=eval("document.all."+target) if(all==0) { while(obj.selectedIndex>-1){ //alert(obj.selectedIndex) mot=obj.options[obj.selectedIndex].text mov=obj.options[obj.selectedIndex].value obj.remove(obj.selectedIndex) varnewoption=document.createElement("OPTION"); newoption.text=mot newoption.value=mov target.add(newoption) } } else { //alert(obj.options.length) for(i=0;i<obj.length;i++) { mot=obj.options[i].text mov=obj.options[i].value varnewoption=document.createElement("OPTION"); newoption.text=mot newoption.value=mov target.add(newoption) } obj.options.length=0 } } functiondakai(){ document.getElementById('light').style.display='block'; document.getElementById('fade').style.display='block' } functionguanbi(){ //把右边select的值传到文本框内 varyuanGong=document.getElementById("yuanGong") yuanGong.value=""//如果不加这句,则每次选择的结果追加 varhuoQu=document.getElementById("D2") for(vark=0;k<huoQu.length;k++) yuanGong.value=yuanGong.value+huoQu.options[k].value+""//""中间为空格,字符分隔符,可以改成别的 document.getElementById('light').style.display='none'; document.getElementById('fade').style.display='none' } </script> </head> <body> <inputtype="text"id="yuanGong"onclick="dakai()"size="50"> <divid="light"class="white_content"> <tableborder="1"width="350"id="table4"bordercolor="#CCCCCC"bordercolordark="#CCCCCC"bordercolorlight="#FFFFFF"cellpadding="3"cellspacing="0"> <tr> <tdwidth="150"height="200"align="center"valign="middle"> 本部门员工 <selectsize="12"name="D1"ondblclick="moveselect(this,'D2')"multiple="multiple"style="width:140px"> <optionvalue="张三">张三</option> <optionvalue="李四">李四</option> <optionvalue="小王">小王</option> </select> </td> <tdwidth="50"height="200"align="center"valign="middle"> <inputtype="button"value="<<"name="B3"onclick="moveselect('D2','D1',1)"><br> <inputtype="button"value="<"name="B5"onclick="moveselect('D2','D1')"><br> <inputtype="button"value=">"name="B6"onclick="moveselect('D1','D2')"><br> <inputtype="button"value=">>"name="B4"onclick="moveselect('D1','D2',1)"><br> </td> <tdwidth="150"height="200"align="center"valign="middle"> 等待划分部门的员工 <selectsize="12"name="D2"id="D2"ondblclick="moveselect(this,'D1')"multiple="multiple"style="width:140px"> <optionvalue="员工X">员工X</option> <optionvalue="员工Y">员工Y</option> </select> </td> </tr> </table> <ahref="javascript:void(0)"onclick="guanbi()">确定</a> <inputtype="button"name="button"onclick="guanbi()"value="按钮也可确定"> </div> <divid="fade"class="black_overlay"></div> </body> </html> </body> </html>
希望本文所述对大家的javascript程序设计有所帮助。