双向选择,通常用于给多向配置

<div class="col-xs-6">
	<h5>匹配</h5>
	<p>选定一项或多项然后点击添加或移除(按住shift或ctrl可以多选),或在选择项上双击进行添加和移除。</p>
	<form method="post" name="myform">
		<table border="0" width="300">
			<tr>
				<td width="40%">
				   <select style="WIDTH: 100%" multiple id="morechannel" name="list1" size="12" ondblclick="moveOption(document.myform.list1,             document.myform.list2)">
				    </select>
				 </td>
				<td width="20%" align="center"><input type="button" value="添加"
					 onclick="moveOption(document.myform.list1, document.myform.list2)"><br />
					 <br /> 
					 <input type="button" value="删除" onclick="moveOption(document.myform.list2, document.myform.list1)">
				 </td>
				 <td width="40%">
				      <select style="WIDTH: 100%" multiple id="list2" name="list2" size="12" ondblclick="moveOption(document.myform.list2, document.myform.list1)">
				      </select>
				 </td>
			   </tr>
	          </table>
		   值:<input type="text" name="city" size="40">
	  </form>
</div>




     左右选择
	function moveOption(e1, e2) {
		try {
			for (var i = 0; i < e1.options.length; i++) {
				if (e1.options[i].selected) {
					var e = e1.options[i];
					e2.options.add(new Option(e.text, e.value));
					e1.remove(i);
					ii = i - 1
				}
			}
			document.myform.city.value = getvalue(document.myform.list2);
		} catch (e) {
		}
	}
	function getvalue(geto) {
		var allvalue = "";
		for (var i = 0; i < geto.options.length; i++) {
			allvalue += geto.options[i].value + ",";
		}
		return allvalue;
	}






	function changepos(obj, index) {
		if (index == -1) {
			if (obj.selectedIndex > 0) {
				obj.options(obj.selectedIndex).swapNode(
						obj.options(obj.selectedIndex - 1))
			}
		} else if (index == 1) {
			if (obj.selectedIndex < obj.options.length - 1) {
				obj.options(obj.selectedIndex).swapNode(
						obj.options(obj.selectedIndex + 1))
			}
		}
	}




	获取值:   var zhi = document.myform.city.value;  通过ajax 传向后台
	后台以字符串接收   String channelString = request.getParameter("channel");
			   String[] channelArray = channelString.split(",");
				for (int i = 0; i < channelArray.length; i++) {
					String string = channelArray[i];//分别获取到值
						
				}

猜你喜欢

转载自blog.csdn.net/panshoujia/article/details/78732666