//说明:左右移动别且模糊查询
//将人员已选未选全部封装在数组中
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);
}
}
}
【js】左右上下移动
最新推荐文章于 2022-02-23 15:02:25 发布