select multiple 多选 移除
此代码通过实例验证
<html>
<title>select,multiple</title>
<head>
<mce:script type="text/javascript"><!--
function addOrRomove(method){
var s1 = document.getElementById("select");
var s2 = document.getElementById("selected");
var ids;
var names;
var optionArray = new Array();
if (method == "add"){ //添加
for (var i=0;i<s1.options.length;i++){
if (s1.options[i].selected == true){
optionArray.push(s1.options[i]);
}
}
for (var j in optionArray){
optionArray[j].selected = false;
s2.options.appendChild(optionArray[j]);
}
}
else if (method == "remove"){ //删除
for (var i=0;i<s2.options.length;i++){
if (s2.options[i].selected == true){
optionArray.push(s2.options[i]);
}
}
for (var j in optionArray){
optionArray[j].selected = false;
s1.options.appendChild(optionArray[j]);
}
}
for(var i=0;i<s2.options.length;i++){
if(i == 0){
ids = s2.options[i].value;
names = s2.options[i].text;
}else{
ids += ","+s2.options[i].value;
names += ","+s2.options[i].text;
}
}
document.getElementById("ids").value = ids;
document.getElementById("names").value = names;
}
// --></mce:script>
</head>
<body>
<div>
<table>
<tr>
<td>
<select id="select" multiple="multiple" onDblClick="addOrRomove('add')">
<option value="1">语文</option>
<option value="2">数学</option>
<option value="3">英语</option>
<option value="4">物理</option>
<option value="5">化学</option>
</select>
</td>
<td>
<div>
<input type="button" value=">>" οnclick="addOrRomove('add');"/>
</div>
<div>
<input type="button" value="<<" οnclick="addOrRomove('remove');"/>
</div>
</td>
<td>
<select id="selected" multiple="multiple" onDblClick="addOrRomove('remove')"></select>
</td>
</tr>
</table>
</div>
<input type="text" name="ids" id="ids">
<input type="text" name="names" id="names">
</body>
</html>