将select中的项从一个移动到另一个select中

<!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>将select中的项互相移动(添加或移除)</title>
 <script language="javascript" type="text/javascript">

  function execSelectGroup(tagContentID, flag)
  {
      var obj = document.getElementById(tagContentID).getElementsByTagName("select");
      var i, j, moveFrom, moveTo;
      if(flag == 1 || flag == 2)                  //全部添加或添加
      {
          moveFrom = obj[0];                      //availableGroups           
          moveTo = obj[1];                        //selectedGroups
      }
      else if(flag == 3 || flag == 4)             //删除或全部删除
      {
          moveFrom = obj[1];
          moveTo = obj[0];
      }
     
      for(i = 0; i < moveFrom.length;)
      {
          var op = moveFrom.options[i];
          if(flag == 1 || flag == 4 || moveFrom.options[i].selected)  //全部添加或移除
          {
              var newOption = document.createElement("option");
              newOption.value = op.value;
              newOption.text = op.text;
              moveTo.options.add(newOption);      //增加一个
              moveFrom.remove(i);
          }
             else
                 i++;
      }
  }
 </script>
</head>

<body>
 <div id="addAccount_tagContent3" class="tagContent">
  <table width="600" border="0" cellspacing="0" cellpadding="5">
    <tr>
   <td>
       <fieldset>
        <legend>组信息</legend>
     <table width="100%" border="0" cellspacing="0" cellpadding="2" align="center">
       <tr>
      <td style="width:40%;text-align:center;">
       可选组
      </td>
      <td>&nbsp;
       
      </td>
      <td style="width:40%;text-align:center;">
       已选组
      </td>
       </tr>
       <tr>
      <td style="width:40%;text-align:center;">
       <select name="availableGroups" size="10" style="width:120px;" multiple>
        <option value="1">可选组一</option>
        <option value="2">可选组二</option>
        <option value="3">可选组三</option>
       </select>
      </td>
      <td align="center">
       <input type="button" name="selectAll" value=">>" style="width:35px; height:18px; margin-bottom:2px;" title="全部添加" οnclick="execSelectGroup('addAccount_tagContent3', 1)" /><br/>
       <input type="button" name="addThis" value=">" style="width:35px; height:18px; margin-bottom:2px;" title="添加" οnclick="execSelectGroup('addAccount_tagContent3', 2)" /><br/>
       <input type="button" name="deleteThis" value="<" style="width:35px; height:18px; margin-bottom:2px;" title="删除" οnclick="execSelectGroup('addAccount_tagContent3', 3)" /><br/>
       <input type="button" name="deleteAll" value="<<" style="width:35px; height:18px; margin-bottom:2px;" title="全部删除" οnclick="execSelectGroup('addAccount_tagContent3', 4)" /><br/>
      </td>
      <td style="width:40%;text-align:center;">
       <select name="selectedGroups" size="10" style="width:120px;" multiple>
        <option value="1">已选组一</option>
        <option value="2">已选组二</option>
        <option value="3">已选组三</option>
        <option value="4">已选组四</option>
       </select>
      </td>
       </tr>
     </table>
       </fieldset>
   </td>
    </tr>
  </table>
 </div>
 <div id="editAccount_tagContent3" class="tagContent">
     <table width="600" border="0" cellspacing="0" cellpadding="5">
       <tr>
      <td>
          <fieldset>
           <legend>组信息</legend>
        <table width="100%" border="0" cellspacing="0" cellpadding="2" align="center">
          <tr>
         <td style="width:40%;text-align:center;">
          可选组
         </td>
         <td>&nbsp;
          
         </td>
         <td style="width:40%;text-align:center;">
          已选组
         </td>
          </tr>
          <tr>
         <td style="width:40%;text-align:center;">
          <select name="availableGroups" size="10" style="width:120px;" multiple>
           <option value="1">可选组一</option>
           <option value="2">可选组二</option>
           <option value="3">可选组三</option>
           <option value="4">可选组四</option>
           <option value="5">可选组五</option>
          </select>
         </td>
         <td align="center">
          <input type="button" name="selectAll" value=">>" style="width:35px; height:18px; margin-bottom:2px;" title="全部添加" οnclick="execSelectGroup('editAccount_tagContent3', 1)" /><br>
          <input type="button" name="addThis" value=">" style="width:35px; height:18px; margin-bottom:2px;" title="添加" οnclick="execSelectGroup('editAccount_tagContent3', 2)" /><br>
          <input type="button" name="deleteThis" value="<" style="width:35px; height:18px; margin-bottom:2px;" title="删除" οnclick="execSelectGroup('editAccount_tagContent3', 3)" /><br>
          <input type="button" name="deleteAll" value="<<" style="width:35px; height:18px; margin-bottom:2px;" title="全部删除" οnclick="execSelectGroup('editAccount_tagContent3', 4)" /><br>
         </td>
         <td style="width:40%;text-align:center;">
          <select name="selectedGroups" size="10" style="width:120px;" multiple>
           <option value="1">已选组一</option>
           <option value="2">已选组二</option>
          </select>
         </td>
          </tr>
        </table>
          </fieldset>
      </td>
       </tr>
     </table>
    </div>
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值