JavaScript双向列表选择框

train

功能介绍:

1、  部门、组、成员之间的三级联动

2、  双击左侧成员自动添加到右侧

3、  双击右侧成员自动删除所选成员

4、  左侧选择多个成员点击右导入按钮成员批量导入到右侧

5、  右侧选择多个成员点击左导入按钮成员批量删除

JavaScrip

$(function(){
//部门
$(“#deptId”).change(function(){
dval = $(this).val();$(“#groupId option”).remove();
$(“#leftSelect option”).remove();//小组
$.post(“/train/getgroupoptions”, {id:$(this).val()}, function(data){

if (data.length > 2) {
var dataObjects = eval(data);

for(var i=0;iif ($.browser.msie) {
$(“#groupId”).get(0).options.add(new Option(dataObjects[i].name,dataObjects[i].value));
} else {
$(new Option(dataObjects[i].name,dataObjects[i].value)).appendTo(“#groupId”);
}
}
}
});

$.post(“/train/getproduceroptions/” Math.random(), {did:$(this).val(),}, function(data){
var dataObjects = eval(data);

for(var i=0;iif ($.browser.msie) {
$(“#leftSelect”).get(0).options.add(new Option(dataObjects[i].name, dval “_” dataObjects[i].group “_” dataObjects[i].value));
} else {
$(new Option(dataObjects[i].name, dval “_” dataObjects[i].group “_” dataObjects[i].value)).appendTo(“#leftSelect”);
}
}
});
});
})

//组改变
$(“#groupId”).change(function(){
dval = $(“#deptId”).get(0).options[$(“#deptId”).get(0).selectedIndex].value;
gval = $(this).val();

$.post(“/train/othergetproduceroptions”, {did:dval, gid:$(this).val()}, function(data){
var dataObjects = eval(data);
$(“#leftSelect option”).remove();

for(var i=0;iif ($.browser.msie) {
$(“#leftSelect”).get(0).options.add(new Option(dataObjects[i].name, dval “_” gval “_” dataObjects[i].value));
} else {
$(new Option(dataObjects[i].name, dval “_” gval “_” dataObjects[i].value)).appendTo(“#leftSelect”);
}
}
});
});

var re_lop = [];

function selectOption()
{
e1 = document.getElementById(“leftSelect”);
e2 = document.getElementById(“right”);

for (i = 0; i < e1.options.length; i ) {
if (e1.options[i].selected) {
e = e1.options[i];

if (!re_lop[e.value]) {
e2.options.add(new Option(e.text, e.value));
for (j = 0; j < e2.options.length; j ) {
e2.options[j].selected = true;
}
re_lop[e.value] = e.text;
}
}
}
}

function lostOption()
{
e2 = document.getElementById(“right”);

for (i = 0; i < e2.options.length; i ) {
if (e2.options[i].selected) {
e = e2.options[i];
e2.options.remove(i);
re_lop[e.value] = “”;
i = -1;
}
}
}