给你一个这方面的例子,你参考一下:
<script language="javascript">function addUserToSelect()
{
var oSeleSrc;
var oSeleDest = document.all("selRoleUser")
oSeleSrc = document.all("selUserList");
AddSelectedItem(oSeleSrc,oSeleDest)
}function removeUserFromSelect()
{
var oSele = document.all("selRoleUser")
DeleteSeletedItem(oSele);
}function AddSelectedItem(oSelSrc,oSelDest)
{
try
{
var iIndexSrc,iIndexDest;
var sValue,sInnerText;
var isExistItem;
var oOption;
var sArr,sUserID,sUserName,sUserType;
var isGroup = false;
if(oSelSrc.selectedIndex == -1)
return false; for(iIndexSrc = 0; iIndexSrc < oSelSrc.options.length; iIndexSrc ++)
{
if(oSelSrc.options(iIndexSrc).selected)
{ isExistItem = false;
sValue = oSelSrc.options(iIndexSrc).value; for(intIndexDest = 0; intIndexDest < oSelDest.options.length; intIndexDest ++)
{
if(oSelDest.options(intIndexDest).value == sValue)
{
isExistItem = true;
}
}
if(!isExistItem)
{
oOption = document.createElement("OPTION");
oSelDest.options.add(oOption);
oOption.innerText = oSelSrc.options(iIndexSrc).innerText;
oOption.value = sValue;
oOption = null;
}
}
}
return true;
}
catch(e)
{
alert(e.description);
}}function DeleteSeletedItem(objSeleDel)
{
try
{
var intIndex;
var intLength;
intLength = objSeleDel.options.length;
if(objSeleDel.selectedIndex == -1)
return false; var sValue;
var sArr,sUserID;
for(intIndex = 0; intIndex < intLength; intIndex ++)
{
if(objSeleDel.selectedIndex != -1)
{
sValue = objSeleDel.options(objSeleDel.selectedIndex).value;
objSeleDel.options.remove(objSeleDel.selectedIndex);
}
} return true;
}
catch(e)
{
alert(e.description);
}
}
function addallUserToSelect()
{
removeallUserFromSelect()
i=0
for (i=0;i<document.all.selUserID.length;i++)
{
oOption = document.createElement("OPTION");
document.all.selRoleUser.options.add(oOption);
oOption.innerText = document.all.selUserID.options(i).innerText;
oOption.value = document.all.selUserID.options(i).value;
oOption = null;
}
}
function removeallUserFromSelect()
{
lengths=document.all.selRoleUser.length;
for(i=0;i< lengths;i++)
{
document.all.selRoleUser.options.remove(0);
}
}
</script>
<body>
<div align="center">
<center>
<table border="0" width="100" cellspacing="1">
<tr>
<td width="16%">
<select id="selUserList" size="1" name="selUserID" multiple style="width: 120; height: 140" ondblclick="document.all.addoption.onclick();">
<option value="1">aaaaa</option>
<option value="2">bbbbb</option>
<option value="3">ccccc</option>
<option value="4">ddddd</option>
<option value="5">eeeee</option>
</select>
</td>
<td width="19%">
<input class="userbutton" type="button" value=" 增加>>" name="addoption" onclick="addUserToSelect()"><br>
<input class="userbutton" type="button" value="<<删除 " name="deloption" onclick="removeUserFromSelect()"><br>
<input class="userbutton" type="button" value=" 全加>>" name="addalloption" onclick="addallUserToSelect()">
<input class="userbutton" type="button" value="<<全删 " name="delalloption" onclick="removeallUserFromSelect()">
</td>
<td width="65%">
<select id="selRoleUser" size="1" name="selRoleUser" multiple style="width: 120; height: 140" ondblclick="document.all.deloption.onclick();">
</select></td>
</tr>
</table>
</center>
</div>
</body>
<script language="javascript">function addUserToSelect()
{
var oSeleSrc;
var oSeleDest = document.all("selRoleUser")
oSeleSrc = document.all("selUserList");
AddSelectedItem(oSeleSrc,oSeleDest)
}function removeUserFromSelect()
{
var oSele = document.all("selRoleUser")
DeleteSeletedItem(oSele);
}function AddSelectedItem(oSelSrc,oSelDest)
{
try
{
var iIndexSrc,iIndexDest;
var sValue,sInnerText;
var isExistItem;
var oOption;
var sArr,sUserID,sUserName,sUserType;
var isGroup = false;
if(oSelSrc.selectedIndex == -1)
return false; for(iIndexSrc = 0; iIndexSrc < oSelSrc.options.length; iIndexSrc ++)
{
if(oSelSrc.options(iIndexSrc).selected)
{ isExistItem = false;
sValue = oSelSrc.options(iIndexSrc).value; for(intIndexDest = 0; intIndexDest < oSelDest.options.length; intIndexDest ++)
{
if(oSelDest.options(intIndexDest).value == sValue)
{
isExistItem = true;
}
}
if(!isExistItem)
{
oOption = document.createElement("OPTION");
oSelDest.options.add(oOption);
oOption.innerText = oSelSrc.options(iIndexSrc).innerText;
oOption.value = sValue;
oOption = null;
}
}
}
return true;
}
catch(e)
{
alert(e.description);
}}function DeleteSeletedItem(objSeleDel)
{
try
{
var intIndex;
var intLength;
intLength = objSeleDel.options.length;
if(objSeleDel.selectedIndex == -1)
return false; var sValue;
var sArr,sUserID;
for(intIndex = 0; intIndex < intLength; intIndex ++)
{
if(objSeleDel.selectedIndex != -1)
{
sValue = objSeleDel.options(objSeleDel.selectedIndex).value;
objSeleDel.options.remove(objSeleDel.selectedIndex);
}
} return true;
}
catch(e)
{
alert(e.description);
}
}
function addallUserToSelect()
{
removeallUserFromSelect()
i=0
for (i=0;i<document.all.selUserID.length;i++)
{
oOption = document.createElement("OPTION");
document.all.selRoleUser.options.add(oOption);
oOption.innerText = document.all.selUserID.options(i).innerText;
oOption.value = document.all.selUserID.options(i).value;
oOption = null;
}
}
function removeallUserFromSelect()
{
lengths=document.all.selRoleUser.length;
for(i=0;i< lengths;i++)
{
document.all.selRoleUser.options.remove(0);
}
}
</script>
<body>
<div align="center">
<center>
<table border="0" width="100" cellspacing="1">
<tr>
<td width="16%">
<select id="selUserList" size="1" name="selUserID" multiple style="width: 120; height: 140" ondblclick="document.all.addoption.onclick();">
<option value="1">aaaaa</option>
<option value="2">bbbbb</option>
<option value="3">ccccc</option>
<option value="4">ddddd</option>
<option value="5">eeeee</option>
</select>
</td>
<td width="19%">
<input class="userbutton" type="button" value=" 增加>>" name="addoption" onclick="addUserToSelect()"><br>
<input class="userbutton" type="button" value="<<删除 " name="deloption" onclick="removeUserFromSelect()"><br>
<input class="userbutton" type="button" value=" 全加>>" name="addalloption" onclick="addallUserToSelect()">
<input class="userbutton" type="button" value="<<全删 " name="delalloption" onclick="removeallUserFromSelect()">
</td>
<td width="65%">
<select id="selRoleUser" size="1" name="selRoleUser" multiple style="width: 120; height: 140" ondblclick="document.all.deloption.onclick();">
</select></td>
</tr>
</table>
</center>
</div>
</body>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货