标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
, q1 Q- M; ^1 c) q2 v
c pageencoding="gb2312"
7 X+ ~- U, v; s- p
%>
; {; n4 F Z% ^( x+ B
<style>
7 G8 s6 g( W. O) z( v# L7 c; X
.f9{ font-size:9pt; }
3 Z( w8 R( Y+ m% v6 a+ o" g
.bgc{ background-color:#aecaf9; color: #0033ff }
; p1 X9 K U* d* S- U# n
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
# L* h6 Y, b1 b
border-bottom: solid 1px #4e7dc1;
3 E8 p/ _' z. I- O# \) v6 q' [
border-left: solid 1px #aecaf9;
/ O4 f3 d1 w- u/ D* G2 f1 n
border-right: solid 1px #5679bd;
+ C( M& \: _# z2 W p& T. x
padding:1px;
- @. ?! ^2 R% E2 \+ o) D( I6 u+ O
margin:0px;}
! r2 G" t y: `5 X; z3 e \
</style>
; t$ F/ P4 ?& ^/ u" `# f2 d
<script language="javascript">
- P+ I# b0 x4 }8 a5 n7 q* o
<!--
) }4 |/ [. \" A& v$ ?8 \
function rv()
. s v% Q6 ~5 {$ X7 N1 B
{
% s- g/ g! ~% N# m
var val="";
' F+ r0 p! C6 a9 a+ n
for(i=0;i<combo_box.list2.length;i++){
1 n' g* n# ~8 H& H* A8 X
val+=","+combo_box.list2
.value;
' } q1 o; v$ B
}
9 g8 o# R" s% q, ?! g6 `
if(val.charat(0)==","){
% T+ Y# P. ?2 v$ z1 M
val=val.substr(1,val.length);
/ x9 t% E0 K* o, A! P# \4 e
}
' p' a/ A, n& n
opener.form1.frecname.value=val;
2 G0 b) u7 m% K$ `
self.close();
1 s% z% k7 |. J4 I5 `( q% A
}
/ H- v6 {" f; ]4 [* D
//-->
7 @. o7 L1 Z, _$ g$ [8 f
</script>
7 j! o0 [" j1 F9 M/ j0 `
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
) k8 @; g4 O3 @/ |
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
* d! k: ?9 x5 A9 k- T( i
<%
7 r$ x, V+ f& z3 v* j% A3 B6 f: p
cdatasource ds=new cdatasource(); //数据联结bean实例
, `5 X, W& k$ b
java.sql.connection conn=ds.getconnection();
$ D5 ]1 t9 i3 _
java.sql.statement stmt=null;
2 l: X# Y u( ^& @, s; Y% U
java.sql.resultset rs=null;
! f) U! \/ f* Z' s7 d- @
cdatacheck dc=new cdatacheck();
l3 |# n' @: O* b) \
%>
9 D9 w4 C3 ]2 I$ d$ z; j6 m& W& H
<%
, q5 P+ Y1 l* n3 N( b
string sqlu="select t1.fno, t1.fname, t2.fname as fdept from tuser t1 left outer join tdept t2 on t1.fdept = t2.fno order by t2.fname";
/ q& j! Y) H; d8 X
stmt=conn.createstatement();
$ q( {' ]* H' ?" x
rs=stmt.executequery(sqlu);
. d" M& W& Y8 o+ ~" c b
%>
; C& j9 h. @+ C) `
<script language='javascript'>
8 S2 H/ s. m1 T% |0 r
arr = new array();
# L W j! r! Q( @) U* u
<% int temp=0;
3 K+ D" e/ N- h/ Z6 s1 @
while(rs.next())
% ^: f( G- P, X- } o3 L
{
2 C* X; X$ P! R7 ~+ a
%>
I9 j- w! r6 G! \
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
1 i& y" p2 h, h5 J0 M1 U1 p
<%
. N& C1 N$ M% |! ?8 Z: u
temp = temp + 1;
& i1 a; I% {8 x6 w1 u7 {
}
; @; [+ S4 f5 |5 @
%>
8 ?( T5 z% m# U* ~8 u8 L- B
temp=<%=temp%>;
; ~1 }( k. @% K) m0 M
function changelocation(id){
% \1 N c, G. ^7 b. S; y5 O9 C/ ~( J
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
8 G; C3 _4 Q: m
var i = 0;
( a% I; {: E& z' M
document.combo_box.city.options[0]=new option('-------','');
4 f% c) v) B4 d6 H
for(i=0;i<temp;i++){
0 p6 A+ n4 q" E# ?6 x1 I5 m
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
* J8 B# _) W( l7 ^" m. h1 |
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
+ }7 H1 ?4 t Z) p5 b6 g: e8 J! S
}
" s% Z4 u+ B" [6 I& C% p; i
}
. M" x% N/ ?) E; ?) W. W
}
+ h, O3 g) {8 j- A K: K s
</script>
3 O+ J9 U) G0 Q0 q' {" D
/ a* T4 l2 G) a! p
<form name="combo_box">
3 j/ P4 [. _( r" Q @
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
9 H c: ^# ?3 [8 K* S. R* f5 b: I
<tr height="24">
, T& }1 _1 o, I. n5 v$ _
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
' I% K! Y; N2 c; e! P# b. z; Y9 r+ a
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
7 U: J4 |- a# d/ Z
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
( [) ~& N$ v) |# H! c) i( }
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
/ {7 J; b+ s4 O8 l! R
</tr>
. p8 l, L7 a8 {% _7 u1 ] Q
<tr>
% q( ?0 C$ `; A4 f9 _
<td>
2 ^6 m9 ^# ]6 b
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
# O9 g$ w! f. W4 R
<option value="0">请选择部门 ---></option>
7 G$ c7 g% @1 H. b- J
<%
$ l, G* z9 M& d5 _# }
string sqld="select * from tdept";
7 V6 [; v% P0 O: E0 i
stmt=conn.createstatement();
, I/ e9 m/ }* q7 W6 q+ e
rs=stmt.executequery(sqld);
7 e7 t v" L8 y
while(rs.next())
- Q; K6 N7 u& B5 S/ }' X
{
5 W. R% ~3 z& `+ @1 z4 X) k
%>
( S& D4 W& ]: I% L/ [$ p
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
7 B- w0 x9 Y p
<%
5 Z) D( ~) ?* p; I. }
}
1 M* G) W0 ~& [
%>
+ s) M/ {; p2 F& y D6 |1 p2 U7 B
</select>
" c8 t$ |0 F/ \) p H' f4 P+ m+ e
</td>
4 Q _+ R5 M: i! n2 ~
<td>
* B" d3 ?4 C! l( }) o: F
<select multiple id=city style="width:150;height:200" class="bgc">
8 k+ Z. H' s4 @( {5 _
</select>
4 Y1 t( y1 \2 L! H, r6 D+ s/ L' g5 w
</td>
+ M y8 i* F+ q8 v, I7 t# r3 b
<td nowrap align="center" class="bgc">
* }/ |/ W/ y3 G9 p& S9 p0 `
<input type="button" value="<<" class="buttons">
. H% ] u( q9 K: @# x
<input type="button" value=">>" class="buttons">
3 P2 n# k) h$ v7 Z
</td>
s- e, s. U* D, O& _# Z* B
<td>
7 x" w) ^) E( K) m0 Y( B% t# l! M
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
5 g% P* @, G' |- g" `, _% I! D
</select>
% s7 U0 v1 J4 H- J2 @; k
</td>
@& U1 j$ B' G7 R3 n K
</tr>
" Z' U# I2 i! Z* m
<tr class="bgc">
; A( W! Q5 y* [8 ?/ @
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
' ~& R7 x4 U9 I( M" i9 `
</tr>
) s; r+ ?( o- K4 R
</table>
- S5 y) }) i% J# G; E
</form>
$ E, R b8 R2 e: u, @* R3 T
<script language="javascript">
" {+ j. q5 w7 K* e, M2 z* K
//人名移动
& Q- W) N3 K( T' W# \6 e
function move(fbox, tbox) {
2 N/ U' O4 F, Q
var arrfbox = new array();
. z8 S! u; t9 J+ m
var arrtbox = new array();
0 X1 X0 {9 U/ v T% c) k
var arrlookup = new array();
& I* s" @% H. A' D
var i;
4 G# S9 [5 q% K! M7 a% W( Y; g0 i% J
for (i = 0; i < tbox.options.length; i++) {
0 v8 f+ g; z( U9 X. c! a
arrlookup[tbox.options
.text] = tbox.options
.value;
( j. a& Q( J! g& @; Q# h5 j) U
arrtbox
= tbox.options
.text;
4 T% ^' N* }1 Z) B0 k$ O4 P# r
}
$ B# P& U4 K$ m
var flength = 0;
- Z# q1 \1 S0 i
var tlength = arrtbox.length;
3 I# I/ m8 F7 y6 Y( a) n, V+ g
for(i = 0; i < fbox.options.length; i++) {
2 B5 _) [) u4 n( t8 T
arrlookup[fbox.options
.text] = fbox.options
.value;
k0 _; Q; d* O' [% n8 i* N
if (fbox.options
.selected && fbox.options
.value != "") {
2 \1 U% P) c3 [1 Z. S8 |
arrtbox[tlength] = fbox.options
.text;
) z& u$ W* ~, `. }4 \8 a) p6 E
tlength++;
8 ]: Q5 _& `$ Y& }
}
5 {8 U4 H8 A6 m. C- r
else {
# U9 O% k% \5 s* O! K
arrfbox[flength] = fbox.options
.text;
8 r3 h) e/ s: R$ ?
flength++;
, j7 J$ F" U, [ D
}
$ U1 [# y7 [1 U' u# v# H+ L
}
) g8 J9 ]9 O' M* }9 a V! T3 C
arrfbox.sort();
& c% g9 ~4 b& Q( }% o" U
arrtbox.sort();
7 N* y1 }( \5 Y. ]8 v! j
. ^# L& e; ?9 {5 o$ @8 M
fbox.length = 0;
; [( h1 b3 E* b- s, D+ `
tbox.length = 0;
( ?( K0 B7 d, S0 @; c Q e
var c;
- _, a/ d. U+ q% Z! ]* ~0 F# v/ M
for(c = 0; c < arrfbox.length; c++) {
6 T: R# @- r6 Q- j9 B/ Z2 p! R# R
var no = new option();
$ K) L! |; k |; u2 ~9 ~, L; J8 s
no.value = arrlookup[arrfbox[c]];
% j' i- H( G- o
no.text = arrfbox[c];
0 V, c. ?7 c* a' P6 _
fbox[c] = no;
0 x& E8 R+ `- f/ _6 G3 |3 {4 w2 r- Y: A
}
. {: X Q$ {" U% p; w: P( N
for(c = 0; c < arrtbox.length; c++) {
. W. r- r8 e7 D! l, k: ~
var no = new option();
, o/ I1 R7 i1 F3 D7 ~
no.value = arrlookup[arrtbox[c]];
" M& d% Q6 H" C U1 H5 @% a' a
no.text = arrtbox[c];
4 U2 L3 `3 B7 s3 o4 U. a) w; v
tbox[c] = no;
3 t- l- f, d6 R. ]0 N7 ~
}
/ f0 C& `- {2 t) U2 Y
}
8 T! F4 C! G( t# C/ |
</script>
) c; ^9 @ B; C" w/ O
</body>
( X2 Z( C9 x# U$ y0 l
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2