js optiontransferselect
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
function moveSelectedOptions(objSourceElement, objTargetElement, toSort, notMove1, notMove2) {
var test1 = compile(notMove1);
var test2 = compile(notMove2);
moveOptions(objSourceElement, objTargetElement, toSort,
function(opt) {
return (opt.selected && !test1(opt.value) && !test2(opt.value));
}
);
}
function moveAllOptions(objSourceElement, objTargetElement, toSort, notMove1, notMove2) {
var test1 = compile(notMove1);
var test2 = compile(notMove2);
moveOptions(objSourceElement, objTargetElement, toSort,
function(opt) {
return (!test1(opt.value) && !test2(opt.value));
}
);
}
function compile(ptn) {
if (ptn != undefined) {
if (ptn == '' || !window.RegExp) {
return function(val) { return val == ptn; }
} else {
var reg = new RegExp(ptn);
return function (val) {
if (val == '') { // ignore empty option added by template
return true;
}
return reg.test(val); }
}
}
return function(val) { return false; }
}
function moveOptions(objSourceElement, objTargetElement, toSort, chooseFunc) {
var aryTempSourceOptions = new Array();
var aryTempTargetOptions = new Array();
var x = 0;
//looping through source element to find selected options
for (var i = 0; i < objSourceElement.length; i++) {
if (chooseFunc(objSourceElement.options[i])) {
//need to move this option to target element
var intTargetLen = objTargetElement.length++;
objTargetElement.options[intTargetLen].text = objSourceElement.options[i].text;
objTargetElement.options[intTargetLen].value = objSourceElement.options[i].value;
}
else {
//storing options that stay to recreate select element
var objTempValues = new Object();
objTempValues.text = objSourceElement.options[i].text;
objTempValues.value = objSourceElement.options[i].value;
aryTempSourceOptions[x] = objTempValues;
x++;
}
}
//sorting and refilling target list
for (var i = 0; i < objTargetElement.length; i++) {
var objTempValues = new Object();
objTempValues.text = objTargetElement.options[i].text;
objTempValues.value = objTargetElement.options[i].value;
aryTempTargetOptions[i] = objTempValues;
}
if (toSort) {
aryTempTargetOptions.sort(sortByText);
}
for (var i = 0; i < objTargetElement.length; i++) {
objTargetElement.options[i].text = aryTempTargetOptions[i].text;
objTargetElement.options[i].value = aryTempTargetOptions[i].value;
objTargetElement.options[i].selected = false;
}
//resetting length of source
objSourceElement.length = aryTempSourceOptions.length;
//looping through temp array to recreate source select element
for (var i = 0; i < aryTempSourceOptions.length; i++) {
objSourceElement.options[i].text = aryTempSourceOptions[i].text;
objSourceElement.options[i].value = aryTempSourceOptions[i].value;
objSourceElement.options[i].selected = false;
}
}
function sortByText(a, b) {
if (a.text < b.text) {return -1}
if (a.text > b.text) {return 1}
return 0;
}
function selectAllOptionsExceptSome(objTargetElement, type, ptn) {
var test = compile(ptn);
for (var i = 0; i < objTargetElement.length; i++) {
var opt = objTargetElement.options[i];
if ((type == 'key' && !test(opt.value)) ||
(type == 'text' && !test(opt.text))) {
opt.selected = true;
} else {
opt.selected = false;
}
}
return false;
}
function selectAllOptions(objTargetElement) {
for (var i = 0; i < objTargetElement.length; i++) {
if (objTargetElement.options[i].value != '') {
objTargetElement.options[i].selected = true;
}
}
return false;
}
function moveOptionUp(objTargetElement, type, ptn) {
var test = compile(ptn);
for (i=0; i<objTargetElement.length; i++) {
if (objTargetElement[i].selected) {
var v;
if (i != 0 && !objTargetElement[i-1].selected) {
if (type == 'key') {
v = objTargetElement[i-1].value
}
else {
v = objTargetElement[i-1].text;
}
if (!test(v)) {
swapOptions(objTargetElement,i,i-1);
}
}
}
}
}
function moveOptionDown(objTargetElement, type, ptn) {
var test = compile(ptn);
for (i=(objTargetElement.length-1); i>= 0; i--) {
if (objTargetElement[i].selected) {
var v;
if ((i != (objTargetElement.length-1)) && !objTargetElement[i+1].selected) {
if (type == 'key') {
v = objTargetElement[i].value
}
else {
v = objTargetElement[i].text;
}
if (!test(v)) {
swapOptions(objTargetElement,i,i+1);
}
}
}
}
}
function swapOptions(objTargetElement, first, second) {
var opt = objTargetElement.options;
var temp = new Option(opt[first].text, opt[first].value, opt[first].defaultSelected, opt[first].selected);
var temp2= new Option(opt[second].text, opt[second].value, opt[second].defaultSelected, opt[second].selected);
opt[first] = temp2;
opt[second] = temp;
}
</script>
</head>
<body>
<tr>
<td class="tdLabel">
</td>
<td> <mce:script type="text/javascript" src="./optiontransferselect.js" mce_src="optiontransferselect.js"></mce:script>
<table border="0">
<tr>
<td>
<label for="leftTitle">Left Title</label><br />
<select name="leftSideCartoonCharacters" size="15" id="leftSideCartoonCharacters" multiple="multiple">
<option value="headerKey">--- Please Select ---</option>
<option value=""></option>
<option value="Popeye">Popeye</option>
<option value="He-Man">He-Man</option>
<option value="Spiderman">Spiderman</option>
</select>
<input type="button"
onclick="moveOptionDown(document.getElementById('leftSideCartoonCharacters'), 'key', 'headerKey');"
value="v"
/>
<input type="button"
onclick="moveOptionUp(document.getElementById('leftSideCartoonCharacters'), 'key', 'headerKey');"
value="^"
/>
</td>
<td valign="middle" align="center">
<input type="button"
value="<-" onclick="moveSelectedOptions(document.getElementById('rightSideCartoonCharacters'), document.getElementById('leftSideCartoonCharacters'), false, 'doubleHeaderKey', '');" /><br /><br />
<input type="button"
value="->" onclick="moveSelectedOptions(document.getElementById('leftSideCartoonCharacters'), document.getElementById('rightSideCartoonCharacters'), false, 'headerKey', '');" /><br /><br />
<input type="button"
value="<<--" onclick="moveAllOptions(document.getElementById('rightSideCartoonCharacters'), document.getElementById('leftSideCartoonCharacters'), false, 'doubleHeaderKey', '');" /><br /><br />
<input type="button"
value="-->>" onclick="moveAllOptions(document.getElementById('leftSideCartoonCharacters'), document.getElementById('rightSideCartoonCharacters'), false, 'headerKey', '');" /><br /><br />
<input type="button"
value="<*>" onclick="selectAllOptionsExceptSome(document.getElementById('leftSideCartoonCharacters'), 'key', 'headerKey');selectAllOptionsExceptSome(document.getElementById('rightSideCartoonCharacters'), 'key', 'doubleHeaderKey');" /><br /><br />
</td>
<td>
<label for="rightTitle">Right Title</label><br />
<select
name="rightSideCartoonCharacters"
size="15"
multiple="multiple"
id="rightSideCartoonCharacters"
>
<option value="doubleHeaderKey">--- Please Select ---</option>
<option value=""></option>
<option value="Superman">Superman</option>
<option value="Mickey Mouse">Mickey Mouse</option>
<option value="Donald Duck">Donald Duck</option>
</select>
<input type="button"
onclick="moveOptionDown(document.getElementById('rightSideCartoonCharacters'), 'key', 'doubleHeaderKey');"
value="v"
/>
<input type="button"
onclick="moveOptionUp(document.getElementById('rightSideCartoonCharacters'), 'key', 'doubleHeaderKey');"
value="^"
/>
</td>
</tr>
</table>
</td>
</tr>
</body>
</html>
js optiontransferselect的更多相关文章
- Vue.js 和 MVVM 小细节
MVVM 是Model-View-ViewModel 的缩写,它是一种基于前端开发的架构模式,其核心是提供对View 和 ViewModel 的双向数据绑定,这使得ViewModel 的状态改变可以自 ...
- js学习笔记:操作iframe
iframe可以说是比较老得话题了,而且网上也基本上在说少用iframe,其原因大致为:堵塞页面加载.安全问题.兼容性问题.搜索引擎抓取不到等等,不过相对于这些缺点,iframe的优点更牛,跨域请求. ...
- js学习笔记:webpack基础入门(一)
之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...
- JS调用Android、Ios原生控件
在上一篇博客中已经和大家聊了,关于JS与Android.Ios原生控件之间相互通信的详细代码实现,今天我们一起聊一下JS调用Android.Ios通信的相同点和不同点,以便帮助我们在进行混合式开发时, ...
- jquery和Js的区别和基础操作
jqery的语法和js的语法一样,算是把js升级了一下,这两种语法可以一起使用,只不过是用jqery更加方便 一个页面想要使用jqery的话,先要引入一下jqery包,jqery包从网上下一个就可以, ...
- 利用snowfall.jquery.js实现爱心满屏飞
小颖在上一篇一步一步教你用CSS画爱心中已经分享一种画爱心的方法,这次再分享一种方法用css画爱心,并利用snowfall.jquery.js实现爱心满屏飞的效果. 第一步: 利用伪元素before和 ...
- node.js学习(三)简单的node程序&&模块简单使用&&commonJS规范&&深入理解模块原理
一.一个简单的node程序 1.新建一个txt文件 2.修改后缀 修改之后会弹出这个,点击"是" 3.运行test.js 源文件 使用node.js运行之后的. 如果该路径下没有该 ...
- JS正则表达式常用总结
正则表达式的创建 JS正则表达式的创建有两种方式: new RegExp() 和 直接字面量. //使用RegExp对象创建 var regObj = new RegExp("(^\\s+) ...
- 干货分享:让你分分钟学会 JS 闭包
闭包,是 Javascript 比较重要的一个概念,对于初学者来讲,闭包是一个特别抽象的概念,特别是ECMA规范给的定义,如果没有实战经验,很难从定义去理解它.因此,本文不会对闭包的概念进行大篇幅描述 ...
随机推荐
- FIleReader无法解决编码问题
可把FileReader 用InputStreamReader(new FileInputStream(String fileptah),"utf-8")替代
- c#之线程
//Process[] pro= Process.GetProcesses(); //foreach (var item in pro) //{ // Console.WriteLine(item); ...
- c# XML省市联动
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 20151124001 关闭C#主窗体弹出是否关闭对话框
关闭C#主窗体弹出是否关闭对话框 private void Frm_Main_FormClosing(object sender, FormClosingEventArgs e) { ...
- hiho(1081),SPFA最短路,(非主流写法)
题目链接:http://hihocoder.com/problemset/problem/1081 SPFA求最短路,是不应-羁绊大神教我的,附上头像. 我第一次写SPFA,我用的vector存邻接表 ...
- OBD芯片应用开发手册 OBD2开发 内部资料分享 汽车电子通讯开发TDA61 TDA66芯片
OBD产品及各种汽车电子相关的开发.往往需要开发者学习各种汽车协议,深入了解全部OBD规范和汽车各性能参数.这往往需要开发者很长的时间学习研究,大大延缓了OBD产品的上市开发进度.为此深圳芯方案电子公 ...
- Codeforces Round #368 (Div. 2) B
Description Masha wants to open her own bakery and bake muffins in one of the n cities numbered from ...
- Date日期比对
Calendar calendar1 = Calendar.getInstance(); Calendar calendar2 = Calendar.getInstance(); calendar1. ...
- Ubuntu安装后的一些配置
对新安装的Ubuntu的一些配置: #移除无用包 apt-get remove libreoffice-common apt-get remove unity-webapps-common apt-g ...
- Maven项目的目录结构+maven的安装与配置
1.首先下载maven,然后配置环境变量,在MyEclipse里面配置maven 2.配置maven的pom.xml文件 3.下载和更新资源 右击项目,有一个Maven4Myeclipse,里面有三个 ...