【js】左右上下移动

//说明:左右移动别且模糊查询
//将人员已选未选全部封装在数组中
var empArr = new Array();
empArr[0] = new Array();
empArr[1] = new Array();
var index=0;
<c:forEach items="${empList}" var="emp" varStatus="status">
	empArr[0][<c:out value="${status.index}"/>] = '<c:out value="${emp.employeeID}"/>';
	empArr[1][<c:out value="${status.index}"/>] = '<c:out value="${emp.employeeName}"/>';
	index=<c:out value="${status.index}"/>;
</c:forEach>
index++;
<c:forEach items="${positionDTO.userList}" var="emp" varStatus="status">
	empArr[0][index+<c:out value="${status.index}"/>] = '<c:out value="${emp.employeeID}"/>';
	empArr[1][index+<c:out value="${status.index}"/>] = '<c:out value="${emp.employeeName}"/>';
	
</c:forEach>
//左右移动对象
function moveOption(original, destination, isMoveAll){
	var originalObj = eval('document.forms[0].' + original);
	var originalOoptions = originalObj.options;
	var destinationObj = eval('document.forms[0].' + destination);
	var destinationOoptions = destinationObj.options;
	for(var i = 0; i < originalOoptions.length; i++){
		if(isMoveAll || originalOoptions[i].selected){
			var option = originalOoptions[i];
			destinationOoptions.add(new Option(option.text, option.value));
			originalObj.remove(i);
			i--;
		}
	}
	//显示已选、未选的对象数,显示总数的span的ID等于下拉菜单的Name加上'Num'
	displayNum(original + 'Num', destination + 'Num', originalOoptions.length, destinationOoptions.length);
	//当选择对象的下拉菜单发生变化才重新生成
	if(original == 'notUsers' || original == 'users'){
		filteActor(document.forms[0].empName.value);
	}
}

//显示已选、未选的对象数
function displayNum(originalID, destinationID, originalNum, destinationNum){
	document.getElementById(originalID).innerText = '(' + originalNum + ')';
	document.getElementById(destinationID).innerText = '(' + destinationNum + ')';
}


//通过输入的对象名称过滤多选下拉菜单中的对象//键盘按起来事件
function filteActor(inputValue){
	inputValue = inputValue.trim();
	var actorUnSelected = document.forms[0].notUsers;
	var actorSelected = document.forms[0].users;
	var actorUnSelectedNum = document.getElementById('notUsersNum');	
	actorUnSelected.options.length = 0;
	for(var i = 0; i < empArr[1].length; i++){
		var actorName = empArr[1][i];
		var hasSelected = false;
		for(var j = 0; j < actorSelected.length; j++){
			//判断查出的对象是否已经被选择,若已选择则不添加到选项中
			if(actorSelected[j].value == empArr[0][i]){
				hasSelected = true;
				break;
			}
		}
		if(hasSelected){
			continue;
		}
		if(inputValue == ''){
			actorUnSelected.add(new Option(empArr[1][i], empArr[0][i]));
		}else if(actorName.indexOf(inputValue) >= 0){ 
			actorUnSelected.add(new Option(empArr[1][i], empArr[0][i])); 
		} 

	}
	actorUnSelectedNum.innerText = '(' + actorUnSelected.options.length + ')';
}

================================================================
// 上下移动改变列表顺序
function moveItems(objname,upperOrnext)//select对象,向上向下
{
	var strlength = objname.options.length;//长度
	if(strlength==0){
		return ;
	}
	var index=objname.selectedIndex;//被选中的对象的索引
	if(index==-1 ){
		alert("请先选择人员!");
		return false;
	}
	var selectedObj=objname.options[index];//被选中的对象
	if(upperOrnext=="upper")//上移
	{
		if(index==0)
		{
			return false;
		}
		var _name=objname.options[index-1].text;
		var _value=objname.options[index-1].value;
		objname.options[index-1].text=selectedObj.text;
		objname.options[index-1].value=selectedObj.value;
		objname.options[index].text=_name;
		objname.options[index].value=_value;
		objname.options[index].selected=false;
		objname.options[index-1].selected=true;
	}
	else
	{
		if(index==strlength-1)
		{
			return false;
		}
		var _name=objname.options[index+1].text;
		var _value=objname.options[index+1].value;
		objname.options[index+1].text=selectedObj.text;
		objname.options[index+1].value=selectedObj.value;
		objname.options[index].text=_name;
		objname.options[index].value=_value;
		objname.options[index].selected=false;
		objname.options[index+1].selected=true;
	}
}
   
---------------------------------------------------
// 左右移动
function moveItemsLR(selByOne,selByTwo,moveDirection)//selByOne对象1,selByTwo对象2,向左向右
{
	if(moveDirection == "lr"){//左右移
		for(var i = selByOne.options.length - 1 ; i >= 0 ; i--)
		{
			if(selByOne.options[i].selected)
			{
				var opt = new Option(selByOne.options[i].text,selByOne.options[i].value);
				opt.selected = true;
				selByTwo.options.add(opt);
				selByOne.remove(i);
			}
		}
	}else if(moveDirection == "all"){//全部左右移动
		
		for(var i = selByOne.options.length - 1 ; i >= 0 ; i--)
		{
			var opt = new Option(selByOne.options[i].text,selByOne.options[i].value);
			opt.selected = true;
			selByTwo.options.add(opt);
			selByOne.remove(i);
		}
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值