实现以下效果的:
<style>
.div1{
width:110px;
height:200px;
float:left;
text-align:center;
line-height:190px;
}
.s{
width:100px;
height:200px;
background-color:#99CCFF;
}
.s1{ background-color:#889EC4;
}
</style>
</head>
<body>
<div style=" width:350px; height:200px;position:absolute; left:350px;; top:20px;">
<div class="div1">
<select class="s" multiple name="ss1" id="ss1">
<option value="red" >红色</option>
<option value="blue">橙色</option>
<option value="green">黄色</option>
<option value="yellow">绿色</option>
<option value="orange">蓝色</option>
<option value="orange">青色</option>
<option value="orange">紫色</option>
</select>
</div>
<div class="div1">
<input class="s1" type="button" value="获取选中项索引" style="margin-top:60px;" οnclick="GetSelectedIndex();"><br />
<input class="s1" type="button" value=" >> " οnclick="AllSel(ss1,ss2);" /><br />
<input class="s1"type="button" οnclick="AllSel(ss2,ss1);" value=" << " />
</div>
<div class="div1">
<select class="s" multiple name="ss2" id="ss2">
</select>
</div></div>
</body>
<script language="javascript" type="text/javascript">
function GetSelectedIndex(){
var s11=document.getElementById("ss1");
var arr=new Array();
for(var i=0;i<s11.options.length;i++){
if(s11.options[i].selected)
//arr[]=i;//js动态数组不支持这种写法
arr.push(i);
}
alert(arr.length);
}
//第一个οnclick="AllSel(ss1,ss2);"
//第二个οnclick="AllSel(ss2,ss1);"
//我太爱这个函数了!
function AllSel(ss1,ss2){
for(ss1.selectedIndex!=-1)
{
ss2.options.add(new Option(ss1.options[ss1.selectedIndex].text));
ss1.remove(ss1.selectedIndex);
}
}
</script>