多选下拉框数据操作

本文介绍了一段JavaScript脚本,该脚本能实现HTML页面中两个下拉选择框之间的选项移动功能,包括单个移动、全部移动等操作。通过分析脚本代码,展示了如何创建新的选项元素,并在两个选择框之间进行增删操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<script language="javascript">
function leftMove(){
var mailSelect1 = document.getElementById("mailSelect1");
var mailSelect2 = document.getElementById("mailSelect2");

for(var i=0;i<mailSelect2.options.length;i++){
if(mailSelect2.options[i].selected){
var opt = document.createElement("option");
opt.value = mailSelect2.options[i].value;
opt.text = mailSelect2.options[i].text;
mailSelect1.add(opt);
mailSelect2.options.removeChild(mailSelect2.options[i--]);
}
}
}
function leftMoveAll(){
var mailSelect1 = document.getElementById("mailSelect1");
var mailSelect2 = document.getElementById("mailSelect2");

for(var i=0;i<mailSelect2.options.length;i++){
var opt = document.createElement("option");
opt.value = mailSelect2.options[i].value;
opt.text = mailSelect2.options[i].text;
mailSelect1.add(opt);
mailSelect2.options.removeChild(mailSelect2.options[i--]);
}
}
function rightMove(){
var mailSelect1 = document.getElementById("mailSelect1");
var mailSelect2 = document.getElementById("mailSelect2");

for(var i=0;i<mailSelect1.options.length;i++){
if(mailSelect1.options[i].selected){
var opt = document.createElement("option");
opt.value = mailSelect1.options[i].value;
opt.text = mailSelect1.options[i].text;
mailSelect2.add(opt);
mailSelect1.options.removeChild(mailSelect1.options[i--]);
}
}
}
function rightMoveAll(){
var mailSelect1 = document.getElementById("mailSelect1");
var mailSelect2 = document.getElementById("mailSelect2");

for(var i=0;i<mailSelect1.options.length;i++){
var opt = document.createElement("option");
opt.value = mailSelect1.options[i].value;
opt.text = mailSelect1.options[i].text;
mailSelect2.add(opt);
mailSelect1.options.removeChild(mailSelect1.options[i--]);
}
}
</script>
<BODY>
<center>
<table>
<tr>
<td>
<select name="mailSelect1" multiple>
<option value="form1">form1</option>
<option value="form2">form2</option>
<option value="form3">form3</option>
<option value="form4">form4</option>
</select>
</td>
<td>
<input type="button" value="<" onclick="leftMove()"/>
<input type="button" value=">" onclick="rightMove()"/>
<input type="button" value="<<" onclick="leftMoveAll()"/>
<input type="button" value=">>" onclick="rightMoveAll()"/>
</td>
<td>
<select name="mailSelect2" multiple>
<option value="a">--a--</option>
<option value="b">--b--</option>
<option value="c">--c--</option>
<option value="d">--d--</option>
</select>
</td>
</tr>
<table>
</center>

</BODY>
</HTML>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值