标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
' f) j& F: ] v9 a' Q! a- b, M6 P
c pageencoding="gb2312"
9 \8 u) O! X# `1 l
%>
. z, {/ I; j9 [. h2 ]
<style>
$ U8 Y' B: C) S b. q( h
.f9{ font-size:9pt; }
% w J; I1 x$ R
.bgc{ background-color:#aecaf9; color: #0033ff }
1 X7 ?- H" v$ C
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
- H! ]3 ?) M; `# X
border-bottom: solid 1px #4e7dc1;
8 Z: T) n6 A, {7 @ K
border-left: solid 1px #aecaf9;
6 u4 i# a) u1 D+ @7 y! I; F
border-right: solid 1px #5679bd;
1 E$ ~! [% }; ?, z0 ^
padding:1px;
& Z# h, K6 o, k. p: ]
margin:0px;}
! F7 P8 @: ]' u# x e
</style>
1 S' D0 X- M* V! M* w# W' A
<script language="javascript">
& Y6 {# _: g. N: @' |+ B0 ?# ^
<!--
& N/ N9 g' M" @% O
function rv()
' n0 k. H) S/ z7 v5 D3 c, g
{
1 B" n: V2 T$ k% N% e+ p7 G# [+ h
var val="";
# b8 B7 @- X. ~. i- |- d- @
for(i=0;i<combo_box.list2.length;i++){
" U; G& z% X' D4 l2 i
val+=","+combo_box.list2
.value;
, h6 I. ^+ j5 t1 _( }% t1 C
}
4 \( V" l, a/ C0 c# j! C. @
if(val.charat(0)==","){
7 _" X- g, U2 x6 x5 S7 k( c! g
val=val.substr(1,val.length);
* x- q9 Y2 w& f% a, }
}
; U6 k( {# l9 E$ Y2 q
opener.form1.frecname.value=val;
, v) l; q+ x* C3 I) A3 M/ S
self.close();
- F3 l' G8 W, g5 a
}
# V& w$ L h8 L1 g0 J4 a
//-->
! Y, Z; V8 K9 ~6 w+ k8 ?
</script>
& G- R0 s. ~2 C1 Y8 E9 @( y% g* a
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
5 {7 |/ h* R! [3 m. b
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
! t$ Y' H0 Z8 _% ?, d/ g- W/ M
<%
9 E$ d. j! D( P: f. e: d8 b3 \
cdatasource ds=new cdatasource(); //数据联结bean实例
5 L$ v" l3 @/ s% m+ T* ^$ F _
java.sql.connection conn=ds.getconnection();
% n( n) h. J3 d; l Y; _' e$ V
java.sql.statement stmt=null;
+ P6 n: o) m7 o' q3 }! Q
java.sql.resultset rs=null;
! M6 Z. S, W% z7 w. }# U
cdatacheck dc=new cdatacheck();
+ c1 Q A0 l+ u' H) R
%>
# H m3 T6 N3 |9 f# b5 l7 ^
<%
* J: X+ @7 g7 E1 \6 B% m8 x
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";
0 F6 N' X# s2 e. |& f" N
stmt=conn.createstatement();
# X$ ~' I! F' v) n$ R
rs=stmt.executequery(sqlu);
; x& v" z0 W ~7 K$ p# }
%>
1 {8 M' G2 L$ |6 L4 l0 K7 C& R. O
<script language='javascript'>
, A3 Q5 F, {- A- u& Y$ A
arr = new array();
: {# l9 J/ U; I4 L1 z% V
<% int temp=0;
! z- W7 ]" G1 d1 @* a2 [6 K
while(rs.next())
+ H; ?& i5 w* q; r4 o$ L
{
( A; g' B& j8 T+ e
%>
& i( z. I; n6 S8 [: r* d
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
2 s; z4 `3 e) M9 a, P! x! R; Z$ T
<%
1 I( V0 ]1 ^. L. v$ r, f! T" B
temp = temp + 1;
% c: q1 c9 i; K
}
: t$ }, q. V: w# S* ?
%>
9 e+ I7 G" o& k# {4 W, j0 U
temp=<%=temp%>;
. S1 \0 V. C7 C8 F$ h9 k
function changelocation(id){
1 n" L8 L: W9 N# e! n5 k
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
* w E" n. |/ v: a2 r) i; b! p
var i = 0;
/ g4 R9 ~" ?1 T! x7 l) y& `
document.combo_box.city.options[0]=new option('-------','');
: d+ }4 v3 [: s# i, }2 `
for(i=0;i<temp;i++){
2 V/ k$ m; c, @2 [4 M5 p9 g1 K
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
1 G' f, O2 o% U6 |/ R5 h8 S' A
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
, ?) p1 _/ I8 P: w0 u
}
* \* ^6 E' r0 Z) l
}
n$ u) u8 b+ U! d) M& D
}
" D. ~3 |0 d; y% V- I
</script>
, }: J H7 R: _; v# m3 A
$ j) s; \- v D
<form name="combo_box">
, F$ i! k8 E3 O9 v+ \/ ]1 X0 s( h( e
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
4 Z' V2 D* I; g. j. j l. m1 k& k
<tr height="24">
. e7 m8 q8 x' Z1 S0 N
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
u7 o$ G: M: n* P2 ~ |1 ^. c
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
. C- Y% I8 {& D8 n: T
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
9 p7 G& W* ?5 t+ i0 F/ d. R
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
5 Y' j9 v5 P' z- p. s$ W
</tr>
4 z9 n0 |1 ~3 u6 Z' v8 _, @* O, t: k) z
<tr>
1 S; d, n0 I7 c
<td>
/ V* G: U5 W. h3 F) C; T2 k
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
& t2 ]& ~6 _! N0 G
<option value="0">请选择部门 ---></option>
0 G+ ^, S$ I1 e* r
<%
; v6 C- D% _, f- c! d5 h( C9 f
string sqld="select * from tdept";
/ A# z5 ?& |# R3 E
stmt=conn.createstatement();
( {& h6 e( j# n5 C8 @
rs=stmt.executequery(sqld);
4 I* P7 K3 ~3 H% U* s
while(rs.next())
7 c& B Z7 l6 w3 V2 u/ g
{
/ k3 w, A3 u- Q1 a) l) R4 }0 P0 H% O6 m
%>
1 U! w3 Z7 _ `6 @, ~; K: Y8 k: U, G
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
) A5 Y& r* f a+ U) B0 W6 J9 F8 d
<%
3 o) b% _% a+ F" P2 c5 ?! P
}
' M9 y# h- V1 s/ q/ j! s
%>
8 S: o+ {+ u( w$ ]
</select>
. q- m8 k5 F e! M; D
</td>
9 l) w+ j# d8 q5 n5 U; C
<td>
- d( {; a8 E( G, X; o7 O" \( X
<select multiple id=city style="width:150;height:200" class="bgc">
+ L# L- Y9 S1 o, X
</select>
% s5 p( Y9 E" U6 C" ^: d, }
</td>
2 @/ r4 F: x* w4 T" X! E1 c+ \& O. a
<td nowrap align="center" class="bgc">
; F/ x& j. [6 r0 W3 L
<input type="button" value="<<" class="buttons">
# ^; Y! R" l l1 L0 } V4 m0 t- [
<input type="button" value=">>" class="buttons">
& O! O0 e9 A$ O2 e W* k
</td>
! |7 _2 o" Q: G& m5 `9 S2 e1 e4 |% S
<td>
/ V+ [( ~! q4 j- n$ E
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
$ Y4 l+ }, U$ a" u
</select>
' k# m& K6 g+ F, R
</td>
7 J6 t" i3 R1 E
</tr>
" C0 ~) E a. w! @
<tr class="bgc">
( |# k9 f: S5 i% t
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
7 |2 z8 a5 b7 H: [, K1 F
</tr>
& c; Y$ t9 H: p/ U0 v
</table>
$ x( l) E$ m/ Z- Z9 w1 e# O
</form>
% [9 H u8 |% y
<script language="javascript">
- S( s2 I7 O- y D% l$ e4 K
//人名移动
2 I: z! C. q- @" G: r
function move(fbox, tbox) {
' \9 ^3 @3 U8 k8 F7 u: K
var arrfbox = new array();
- j/ b2 F' y6 j2 f; V+ U
var arrtbox = new array();
6 ^' \ \& ?, `$ Q# a
var arrlookup = new array();
) d9 B1 o( i# T4 B
var i;
6 [: U6 m, A1 n# Z0 ~6 _+ b2 [0 B
for (i = 0; i < tbox.options.length; i++) {
! I7 q9 N6 O, A# Y, e$ c
arrlookup[tbox.options
.text] = tbox.options
.value;
# h# g2 T5 _: y. n
arrtbox
= tbox.options
.text;
0 \* V1 S% Z3 F( ?: a4 B
}
1 L( _3 H+ o: `$ r8 D( P5 v
var flength = 0;
% C; H2 f3 W$ P. c+ u
var tlength = arrtbox.length;
2 z& P% {3 y% _' t. ^+ B1 w! ~
for(i = 0; i < fbox.options.length; i++) {
4 `0 X6 Q0 W5 ]) U" S* d& W
arrlookup[fbox.options
.text] = fbox.options
.value;
4 K. Q8 ^! K, j/ m2 Z/ _
if (fbox.options
.selected && fbox.options
.value != "") {
. d6 b6 _0 G# ?& t
arrtbox[tlength] = fbox.options
.text;
6 W& R2 |5 W" L$ V
tlength++;
6 E$ P8 \+ p5 g+ e2 u5 W
}
r5 v2 _+ S: B: ~: x9 I$ d
else {
, S5 |" `$ j: F& {
arrfbox[flength] = fbox.options
.text;
2 A4 T- X% ]4 G* J) H* I) n
flength++;
2 ~/ F/ L& }8 a! u2 N5 z
}
# g3 q, w E: D G0 I+ l
}
- j+ ?2 l U4 U: S* {. l) r7 S% @2 R
arrfbox.sort();
# l1 Y8 ^, n5 \
arrtbox.sort();
0 \) ` \+ V! q x8 ]
I- I1 d9 f# \! ~
fbox.length = 0;
, ?7 @0 y/ K. q/ y& U: R
tbox.length = 0;
/ ~ d: h& R( S( ~
var c;
) @1 d, h3 l$ G. G+ `! e7 e
for(c = 0; c < arrfbox.length; c++) {
2 r, W7 g0 u8 S( ] t3 h6 b
var no = new option();
9 i0 y2 [5 r) e; l7 n( T& o5 \
no.value = arrlookup[arrfbox[c]];
+ k, X( @) L0 |- n2 p9 f7 n
no.text = arrfbox[c];
$ V4 _2 Q/ P) `2 s$ L9 i
fbox[c] = no;
5 _- s+ | V/ }" W3 c% w* h% R
}
2 K! O$ e: w/ a6 U
for(c = 0; c < arrtbox.length; c++) {
: U$ C2 K: K( V9 u7 H. d/ A7 J
var no = new option();
4 F* A* T. G, T! k' V
no.value = arrlookup[arrtbox[c]];
- O u7 l2 k2 Y% L- u$ ]- j9 J
no.text = arrtbox[c];
- i8 K+ C9 G2 v$ _- i
tbox[c] = no;
. v9 M1 U$ [, i* V
}
- D7 x' e# j$ G1 v/ G+ ~) Y" Y# P
}
) U/ |% }; z) H6 u& t, k
</script>
* M' |0 S3 h5 d0 O3 w: B
</body>
" ]7 H; Q! j, [5 Z
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2