下面是我写的 test ,跑一下,发现可以完成你所需要的功能<html>
<body>
<div>
<SELECT ID="oSelect1" NAME="Cars" SIZE="3" MULTIPLE onchange="change1()">
<OPTION VALUE="1" >BMW
<OPTION VALUE="2">Porsche
<OPTION VALUE="3" >Mercedes
</SELECT>
<SELECT ID="oSelect2" NAME="Cars" SIZE="3" MULTIPLE onchange="change2()">
<OPTION VALUE="1" >BMW
<OPTION VALUE="2">Porsche
<OPTION VALUE="3" >Mercedes
</SELECT>
</div>
</body>
</html>
<script language="javascript">
function change1() {
var selectItem = oSelect1.options[oSelect1.selectedIndex];
var option = document.createElement("<option/>");
option.text = selectItem.text;
oSelect2.add(option);
oSelect1.remove(oSelect1.selectedIndex);
}
function change2() {
var selectItem = oSelect2.options[oSelect2.selectedIndex];
var option = document.createElement("<option/>");
option.text = selectItem.text;
oSelect1.add(option);
oSelect2.remove(oSelect2.selectedIndex);
}</script>
<body>
<div>
<SELECT ID="oSelect1" NAME="Cars" SIZE="3" MULTIPLE onchange="change1()">
<OPTION VALUE="1" >BMW
<OPTION VALUE="2">Porsche
<OPTION VALUE="3" >Mercedes
</SELECT>
<SELECT ID="oSelect2" NAME="Cars" SIZE="3" MULTIPLE onchange="change2()">
<OPTION VALUE="1" >BMW
<OPTION VALUE="2">Porsche
<OPTION VALUE="3" >Mercedes
</SELECT>
</div>
</body>
</html>
<script language="javascript">
function change1() {
var selectItem = oSelect1.options[oSelect1.selectedIndex];
var option = document.createElement("<option/>");
option.text = selectItem.text;
oSelect2.add(option);
oSelect1.remove(oSelect1.selectedIndex);
}
function change2() {
var selectItem = oSelect2.options[oSelect2.selectedIndex];
var option = document.createElement("<option/>");
option.text = selectItem.text;
oSelect1.add(option);
oSelect2.remove(oSelect2.selectedIndex);
}</script>
解决方案 »
- 收藏本页的js代码
- js或jquery如何检测页面发生了变化,想在每次变化后执行一个函数。
- 开发一个论坛的一般步骤~~~~~~~~~~
- extjs grid点击列名不排序
- 求助,取当前时间
- 怎样提交表单到showModalDialog???在线等!!!!!谢谢!!!!!!
- input中,输入超过指定长度后,如何折行显示输入内容?
- radio问题,点一下选中了,如何再点一下又变成不选中??苯问题。。。:(
- 如何控制数字的输入
- JavaScript 实现枚举类型 enumeration
- 各位大哥姐姐,请问要什么样才可以防止SQL注入?(要求最精且效率最高且最坚固)小弟谢谢了!
- 请问在JavaScript里怎么取得系统时间???谢谢大家了!!!
http://community.csdn.net/Expert/topic/4066/4066545.xml?temp=.3428766
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2800.1106" name=GENERATOR></HEAD>
<BODY MS_POSITIONING="GridLayout"><FONT face=宋体></FONT><FONT face=宋体></FONT><FONT face=宋体></FONT><BR><BR>
<FORM id=Form1 action=do.asp method=post>
<TABLE align=center>
<TBODY>
<TR align=middle>
<TD width=160><SELECT style="WIDTH: 120px" size=10 name=list1> <OPTION value=1>1111111</OPTION> <OPTION value=2>2222222</OPTION> <OPTION value=3>3333333</OPTION> <OPTION value=4>4444444</OPTION> <OPTION value=5>5555555</OPTION> <OPTION value=6>6666666</OPTION> <OPTION value=7>7777777</OPTION></SELECT></TD>
<TD><INPUT onclick=add() type=button value="增 加>>>"> <BR><BR><INPUT onclick=del() type=button value="<<<删 除"> </TD>
<TD width=79><SELECT id=seqItem style="WIDTH: 120px" multiple size=10 name=seqItem></SELECT></TD>
<TD width=79></TD></TR></TBODY></TABLE>
<DIV align=center><INPUT onclick=doRe() type=button value="重 置"> <INPUT onclick=goClick() type=button value="提 交" name=ok> </DIV></FORM>
<SCRIPT language=javascript>
var seqSelect=document.forms[0].seqItem;
//var length=5;
function doRe(){
document.forms[0].action="";
document.forms[0].submit();
}
function setCursor(objStyle,cursor)
{
objStyle.cursor = cursor;
}
function goClick()
{
var res=""
{for(var i=0;i<seqSelect.options.length;i++ )
res=res+","+seqSelect.options[i].value
}
alert(res);
}
function add_singer(object,value,text)//添加数据
{
if(singer_exist(object,value)==false)
{
object.options.add(new Option(text,value,true,true));
return true;
}
return false;
}
function remove_singer(object,index)//删除数据
{
if(index<0)return false;
object.options.remove(index)
}
function singer_exist(object,value)//检查是否存在
{
for(var i=0;i<object.options.length; i++)
{
if(object.options[i].value==value)
return true;
}
return false;
}
function add()
{
var obj1=document.all.list1;
var index=obj1.selectedIndex;
if (index<0) return false;
value=obj1.options[index].value;
text=obj1.options[index].text;
var obj2=document.all.seqItem;
add_singer(obj2,value,text)
remove_singer(obj1,index)
}
function del()
{
var obj2=document.all.seqItem;
var index=obj2.selectedIndex;
if (index<0) return false;
value=obj2.options[index].value;
text=obj2.options[index].text;
var obj1=document.all.list1;
add_singer(obj1,value,text)
remove_singer(obj2,index)
}
</SCRIPT>
</BODY></HTML>