javascript制作select列表双向选择

  做项目的时候要用到的一个小功能,用的纯JS,很实用,该功能很常见,其实就是从左边列表的选项进行选择,在右边的文本域里显示选择好的选项。代码如下:

Html代码  

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb18030" />
<title>QQ邮箱 - 编辑联系组</title>
<link rel="stylesheet" type="text/css" href="http://rescdn.qqmail.com/zh_CN/htmledition/style/comm201003a763.css" />
<link rel="stylesheet" type="text/css" href="/cgi-bin/getcss?sid=_3QWaXoa53T1QHg1&ft=skin" />
<style type="text/css">
select {font-family:Arial;}
</style>
<script language="JavaScript" src="http://rescdn.qqmail.com/zh_CN/htmledition/js/all044efa.js"></script>
<script language="javascript">
function MoveAll(FromList,ToList)
{
 for(var i=0;i<FromList.length;i++)
 {
   ToList[ToList.length]=new Option(FromList.options[i].text,FromList.options[i].value);
 }
 FromList.length=0;
};
function MoveSelection(FromList,ToList)
{
 for(var i=0;i<FromList.length;i++)
 {
  if(FromList.options[i].selected)
  {
   ToList[ToList.length]=new Option(FromList.options[i].text,FromList.options[i].value);
  }
 }
 for(i=FromList.length-1;i>=0;i--)
 {
  if(FromList.options[i].selected)FromList.remove(i);
 }
};
function fSelectAllAddress(frm)
{
 for(i=0;i<frm.InGroup.length;i++)
 {
  frm.InGroup.options[i].selected=true;
 }
};
</script>
</head>
<body class="tbody" οnlοad="document.frm.GrpName.focus()">
<form name="frm" id="frm" action="/cgi-bin/addr_grp_addedit_html?sid=_3QWaXoa53T1QHg1" target="actionFrame" method="post" οnsubmit="fSelectAllAddress(this)">
<input type="hidden" name="sid" value="_3QWaXoa53T1QHg1" >

<input TYPE="hidden" name="isqqgroup" value="">
<table width="100%" border="0" cellspacing="0" cellpadding="2" class="toolbg">
 <input type="hidden" name="t">
 <tr>
  <td align="left" nowrap class="barspace toolbgline f_family">
   <input type="submit" value=" 保存信息 " class="wd2 btn btn_true" /><input type="button" value=" 取消 " class="wd1 btn btn_true" οnclick="javascript:location.href='/cgi-bin/addr_listall?sid=_3QWaXoa53T1QHg1'" />
  </td>
 </tr>
</table>
<input TYPE="hidden" name="OperType" value="ADD">
<input TYPE="hidden" name="GrpID" value="0">

<div class="settingtable">
<center>
<div style="width:96%;text-align:left;font:bold 14px Verdana;padding:15px 0 4px 2px" class="addr_line">
 新建联系组&nbsp;
</div>
</center>
<table width="96%" border="0" cellspacing="0" cellpadding="3" align="center">
 <tr>
  <td colspan="3" align="left" style="padding:12px 18px 20px 8px;height:40px;">组名:<input type="text" autocomplete="off" class="txt" name="GrpName" size="36" value=""  />&nbsp;&nbsp;<font color="#FF0000">*必填</font></td>
 </tr>
 <tr>
  <td align="left" width="270" style="padding:2px 5px 2px 8px;line-height:20px;">
   可选联系人<br>
   <select name="OutGroup" size="15" style="width:250px;height:250px" multiple οndblclick="MoveSelection(document.frm.OutGroup,document.frm.InGroup)">
         <option value="14">BOSS &lt;</option>
      <option value="6">岩 &lt;464706@qq.com&gt;</option>
      <option value="62">◇親伱メ尐嘴 &lt;453743@qq.com&gt;</option>
      <option value="10">日落烟痕 &lt;547269@qq.com&gt;</option>
      <option value="18">天上人间 &lt;756813@qq.com&gt;</option>
      <option value="80">为爱守候 &lt;300146@qq.com&gt;</option>
      <option value="109">无悔 &lt;hq6171081@qq.com&gt;</option>
      <option value="105">我也非猪油 &lt;348038@qq.com&gt;</option>
         </select>  
  </td>
  <td align="left" width="60">
   <input type="button" class="wd2 btn btn_true" οnclick="MoveSelection(document.frm.OutGroup,document.frm.InGroup)" value=" 添加 &#8250; " /><br /><br />
   <input type="button" class="wd2 btn btn_true" onClick="MoveSelection(document.frm.InGroup,document.frm.OutGroup)" value=" &#8249; 删除 " /><br /><br />
   <input type="button" class="wd2 btn btn_true" οnclick="MoveAll(document.frm.OutGroup,document.frm.InGroup)"  value="全添加 &#187;" /><br /><br />
   <input type="button" class="wd2 btn btn_true" οnclick="MoveAll(document.frm.InGroup,document.frm.OutGroup)" value="&#171; 全删除" /><br />
  </td>
  <td align="left" style="padding:2px 10px 2px 20px;line-height:20px;">
   已有联系人<br>
   <select name="InGroup" size="15" style="width:250px;height:250px" multiple οndblclick="MoveSelection(document.frm.InGroup,document.frm.OutGroup)">
            </select>
  </td>
 </tr>
 <tr><td colspan="3" align="left" height="35" valign="top" class="addrtitle" style="padding-left:8px;">按住Ctrl键可以多选,shift键可选择范围,双击可以直接添加</td></tr>
</table>
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="2" class="toolbg">
 <input type="hidden" name="AddrID" value="">
 <input type="hidden" name="t">
 <tr>
  <td align="left" nowrap class="barspace toolbgline f_family">
   <input type="submit" value=" 保存信息 " class="wd2 btn btn_true" /><input type="button" value=" 取消 " class="wd1 btn btn_true" οnclick="javascript:location.href='/cgi-bin/addr_listall?sid=_3QWaXoa53T1QHg1'" />
  </td>
 </tr>
</table>
</form>
<script language="javascript">
 PGV();
</script>
</body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值