JSP编程教程:jsp中两个框中内容互换可以添加也可以移除
2015-5-9编辑:ljnbset
在项目中需要实现如下的效果内容。如图:
具体实现的源码如下:
两个框的页面源码:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
已选角色:< br /> < select multiple = "multiple" name = "roleIds" size = "10" id = "roleIds" >
< option value = "1" >
主任
< CODE> |
实现的js代码:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
function moveOptions(oSource, oTarget) {
while (oSource.selectedIndex > -1) {
var opt = oSource.options[oSource.selectedIndex];
oSource.removeChild(opt);
var mark = true ;
for ( var i = 0; i < oTarget.options.length; i++){
if (opt.value == oTarget.options[i].value){
mark = false ;
}
}
if (mark){
var newOpt = document.createElement( "OPTION" );
oTarget.appendChild(newOpt);
newOpt.value = opt.value;
newOpt.text = opt.text;
newOpt.selected = true ;
}
}
}
|