<!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>
</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>
</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>