Select下拉列表框进行多选、移除、交换内容(包括修改反显)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Select下拉列表框进行多选、移除、交换内容</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body style="font-size:12px">
<form name="form1" method="post" action="">
<table width="380" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="150">
<table width="150" border="0" cellpadding="1" cellspacing="1" bgcolor="#CAFAFC">
<tr>
<td height="25" background="/electbg.jpg" bgcolor="#FFFFFF">   请选择:</td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">
<select name="sel_place1" size="6" multiple id="sel_place1" style="width:100px " >
<option value="sel1">江苏省</option>
<option value="sel2">广东省</option>
<option value="sel3">河南省</option>
<option value="sel4">吉林省</option>
<option value="sel5">浙江省</option>
</select>
</td>
</tr>
</table></td>
<td width="80" align="center" valign="bottom">
<input name="sure1" type="button" id="sure1" onClick="allsel(document.form1.sel_place2,document.form1.sel_place1);" value="<<">  
<input name="sure2" type="button" id="sure2" onClick="allsel(document.form1.sel_place1,document.form1.sel_place2);" value=">>" align="center" height="2">
</td>
<td width="150">
<table width="150" border="0" cellpadding="1" cellspacing="1" bgcolor="#CAFAFC">
<tr>
<td height="25" background="/selectbg.jpg" bgcolor="#FFFFFF">   已选择:</td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">
<select name="sel_place2" size="6" multiple id="sel_place2" style="width:100px "> </select>
</td>
</tr>
</table></td>
</tr>
</table>
</br></br>
<center>
<input type="button" id="btn1" onClick="submitForm();" value="提交">
</center>
</form>
<script language="javascript">
function allsel(n1,n2)
{
while(n1.selectedIndex!=-1)
{
var indx=n1.selectedIndex;
var t=n1.options[indx].text;
var v=n1.options[indx].value;
n2.options.add(new Option(t,v));
n1.remove(indx);
}
}
//提交存值
function submitForm(){
n2 = document.form1.sel_place2;
n2_len= n2.options.length;
var n2_val='';
for(i=0;i<n2_len;i++){
n2_val+=n2.options[i].value;
if(i!=n2_len-1){
n2_val+='|';
}
}
alert(n2_val);//存值:例如:
}

//初始化反显 dfzhao
window.onload = function() {
n1 = document.form1.sel_place1;
n2 = document.form1.sel_place2;
init_val='sel1|sel5|sel3';
init_arra=init_val.split("|");
for (var i=0;i<init_arra.length ;i++ ) {
for(var x=0; x<n1.options.length ;x++){
if(init_arra[i]==n1.options[x].value){
n2.options.add(new Option(n1.options[x].text,n1.options[x].value));
n1.remove(x);
}
}
}
}

</script>

</body>
</html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现下拉列表多选功能,并使用 xm-select 插件进行操作,可以按照以下步骤进行: 1. 引入必要的依赖文件。在 HTML 页面中引入 jQuery 和 xm-select 的 CSS 和 JavaScript 文件。 ```html <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/xm-select/2.4.1/xm-select.css"> <script src="https://cdn.bootcdn.net/ajax/libs/xm-select/2.4.1/xm-select.js"></script> ``` 2. 创建一个 `<select>` 元素,并为其添加一个唯一的 id。 ```html <select id="mySelect" multiple> <!-- 动态生成的选项将在这里插入 --> </select> ``` 3. 使用 JavaScript 动态生成选项,并初始化 xm-select 插件。 ```javascript // 获取需要插入选项的 select 元素 var selectElement = document.getElementById("mySelect"); // 定义动态生成的选项数据 var options = [ { name: "选项1", value: "option1" }, { name: "选项2", value: "option2" }, { name: "选项3", value: "option3" }, // 其他选项... ]; // 动态生成选项 options.forEach(function (option) { var optionElement = document.createElement("option"); optionElement.text = option.name; optionElement.value = option.value; selectElement.appendChild(optionElement); }); // 初始化 xm-select 插件 xmSelect.render({ el: '#mySelect', tips: '请选择选项', }); ``` 通过以上步骤,就可以实现使用 xm-select 插件实现下拉列表的动态数据多选功能。请注意,上述代码只是一个简单的示例,你可以根据自己的实际需求进行相应的修改和扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值