This article describes the practical method of clicking the input box to pop up the selection box in JS+CSS. Share it for your reference. The specific implementation method is as follows:
Copy the code as follows:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JS+CSS creates a practical click input box pop-up selection box effect</title>
<style type="text/css">
.black_overlay{display:none;position:absolute;top:0%;left:0%;width:100%;height:100%;background-color:#FFFFF;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:16px solid orange;margin:-32px;background-color:white;z-index:1002;overflow:auto;}
</style>
<script language="javascript" type="text/javascript">
function moveselect(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)
var newoption=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
var newoption=document.createElement("OPTION");
newoption.text=mot
newoption.value=mov
target.add(newoption)
}
obj.options.length=0
}
}
function dakai(){
document.getElementById('light').style.display='block';
document.getElementById('fade').style.display='block'
}
function guanbi(){
//Pass the value of select on the right to the text box
var yuanGong=document.getElementById("yuanGong")
yuanGong.value=""//If this sentence is not added, the result of each selection will be added.
var huoQu=document.getElementById("D2")
for(var k=0;k<huoQu.length;k++)
yuanGong.value=yuanGong.value + huoQu.options[k].value + " "//" "The middle is a space, the character separator, which can be changed to another
document.getElementById('light').style.display='none';
document.getElementById('fade').style.display='none'
}
</script>
</head>
<body>
<input type="text" id="yuanGong" onclick="dakai()" size="50">
<div id="light">
<table id="table4" bordercolor="#CCCCCC" bordercolordark="#CCCCCC" bordercolorlight="#FFFFF" cellpadding="3" cellpacing="0">
<tr>
<td align="center" valign="middle">
Employees in this department
<select size="12" name="D1" ondblclick="moveselect(this,'D2')" multiple="multiple">
<option value="Zhang San">Zhang San</option>
<option value="Li Si">Li Si</option>
<option value="Xiao Wang">Xiao Wang</option>
</select>
</td>
<td align="center" valign="middle">
<input type="button" value="<<" name="B3" onclick="moveselect('D2','D1',1)"><br>
<input type="button" value="<" name="B5" onclick="moveselect('D2','D1')"><br>
<input type="button" value=">" name="B6" onclick="moveselect('D1','D2')"><br>
<input type="button" value=">>" name="B4" onclick="moveselect('D1','D2',1)"><br>
</td>
<td align="center" valign="middle">
Employees waiting to divide departments
<select size="12" name="D2" id="D2" ondblclick="moveselect(this,'D1')" multiple="multiple">
<option value="Employee X">Employee X</option>
<option value="Employer Y">Employer Y</option>
</select>
</td>
</tr>
</table>
<a href="javascript:void(0)" onclick="guanbi()">Confirm</a>
<input type="button" name="button" onclick="guanbi()" value="button can also be confirmed">
</div>
<div id="fade"></div>
</body>
</html>
</body>
</html>
I hope this article will be helpful to everyone's JavaScript programming.