标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
" x9 ^6 G3 J+ q- U, Q6 X
c pageencoding="gb2312"
! T8 t1 _* ^0 _: E3 z7 m
%>
3 L: j4 V E2 U3 o4 W
<style>
+ z2 v: V# ?3 `& T* [
.f9{ font-size:9pt; }
6 y5 U4 J) a% E' M! i9 I: Y) D
.bgc{ background-color:#aecaf9; color: #0033ff }
! M" @3 O6 y5 [0 _+ `+ a
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
+ k/ j1 n5 j7 y# p& \& B( A
border-bottom: solid 1px #4e7dc1;
6 b4 P1 C) f7 | t$ a: t
border-left: solid 1px #aecaf9;
3 ^4 `: k# D3 S- E7 i8 N
border-right: solid 1px #5679bd;
% t; E9 n7 B3 A
padding:1px;
7 X/ C7 \- G2 R: \
margin:0px;}
7 y* W) C! I; X i2 x( K3 G
</style>
/ R. @4 T! k' C3 l5 w, d$ l
<script language="javascript">
$ M1 f4 V! {0 }2 y
<!--
3 y9 n P6 C* y. d
function rv()
6 I$ L2 M& B: H
{
5 [0 C8 U9 R) G2 V+ h
var val="";
# O E& O0 f1 n" s! |
for(i=0;i<combo_box.list2.length;i++){
}8 K2 o( H6 X" {- F: e2 ?* o! d
val+=","+combo_box.list2
.value;
; t3 ]/ o" G- T+ l% a
}
. \- a) Q" U( q1 I9 I% H+ e; v
if(val.charat(0)==","){
* T! R" p5 j9 d0 y9 u
val=val.substr(1,val.length);
$ u$ W( x( h, C) F+ @+ U
}
- J: I9 i/ |2 ~ y6 u4 }8 u
opener.form1.frecname.value=val;
8 g% U0 p- H7 ]' J9 r- T- r
self.close();
. b7 N9 r6 \' t. @0 K# ~: ]
}
2 [, F+ v" Z+ U U
//-->
# I! i% F8 I5 M- B# S
</script>
- R* `" H( @" C, g+ t- g
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
1 a% w0 D" n- {+ b( T9 s9 P- P
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
1 ~3 F3 t7 D: f+ _' H! E
<%
+ L# m) C F4 h7 r% j" z
cdatasource ds=new cdatasource(); //数据联结bean实例
+ e5 Z. B3 U# O0 g0 l% l; ~
java.sql.connection conn=ds.getconnection();
9 _9 T; e6 K0 S5 K R! P
java.sql.statement stmt=null;
8 u; a3 `( D6 L. }" D( u
java.sql.resultset rs=null;
! D4 N/ B3 n `
cdatacheck dc=new cdatacheck();
! P" g7 ]$ R$ J
%>
. c: C( b: Y: R/ F& }( t, Z
<%
" E* h, B& t) z1 g! }9 ], n
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";
' e. x+ c k8 l; M4 k5 p
stmt=conn.createstatement();
9 f/ |5 g- A( g9 G" X5 Z- ]
rs=stmt.executequery(sqlu);
9 k3 u; j* R; l) s8 ~
%>
& K( X8 y( r9 B2 H/ A: Y
<script language='javascript'>
! t$ g: I# K. V6 _! G: u, l
arr = new array();
! \* `3 Y' X+ h: V8 x6 D: g
<% int temp=0;
# k5 E6 G5 f- ^/ s- B
while(rs.next())
4 t7 _, I2 J3 ^
{
/ c o( c" J! m
%>
2 Y: x* M# Q" Y7 _2 L( p
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
( |# `! Q$ ]2 s! ^9 L/ y/ s
<%
4 L$ ]8 N! B) B( ^. K
temp = temp + 1;
5 {, ^! u, W! [7 J2 u! W5 ~
}
( f4 N, K! _4 a* E6 M8 R. g
%>
* q+ U- y1 u! b" G4 K
temp=<%=temp%>;
% t$ \9 R8 s/ j4 e M. {
function changelocation(id){
) L& U# Z4 ]* r
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
. i; Z2 X( \6 H) `' [0 v& }
var i = 0;
$ d6 W7 P/ T$ S$ W# E% [9 G, r4 p
document.combo_box.city.options[0]=new option('-------','');
2 x- l9 O+ G' i- ~
for(i=0;i<temp;i++){
|+ P7 A: P/ f/ |. k# [# W
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
! Q- C0 o. ?( O2 B) j. v* J Y
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
j- b' _( m& \2 S1 T, i4 m! M
}
; A# W9 v$ t2 x2 E) ^2 x
}
! E9 V$ @' x+ X2 v6 S$ V0 b
}
: ?8 W" X ?$ \$ t8 b- N/ ~- E) j3 `, Q
</script>
& T; q8 S' s3 U9 m# z e
- d- E; W# o# K! m1 S
<form name="combo_box">
. N5 }# x9 g ^/ A" h b+ I
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
+ Y0 o1 V% D' g3 ]
<tr height="24">
; q9 o% C6 o- u l# I% B6 x' \
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
. b; a4 \1 N$ M& v% [8 b: k
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
: f3 J: B' H0 R) z( q
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
9 J* L( C. n; A) d, A
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
! M7 s& E/ S% L& [) }$ l, C6 i
</tr>
# }3 s8 g3 U+ n, G# P& m4 T9 N: Q
<tr>
( W& F( p, e+ |
<td>
' Y+ \" r2 e% y# X: m
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
- ]0 V) _6 Q# H) A
<option value="0">请选择部门 ---></option>
6 F. o2 {6 a0 R( \
<%
) X0 u) o. e( L2 b- _
string sqld="select * from tdept";
4 M" h$ E# k% f% L* G" L4 S
stmt=conn.createstatement();
! K- X1 m8 o1 |$ b: b. _3 Q# u( @
rs=stmt.executequery(sqld);
9 H1 C# P& y1 r4 u/ e7 y' G. p1 T
while(rs.next())
" l" ^$ S# h& z( |% {& G& f
{
! s- z* x, q0 R" _, i, y' y
%>
2 ?0 I8 L/ A3 t* l
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
; S9 x! [+ z- R/ X' I" I4 W5 H
<%
0 X& g3 R D! f! Q, l
}
1 _: D% n* F; n0 Z# `
%>
# r7 p' ]6 |# H& r2 ^$ U
</select>
* X# p$ P9 l) D3 A8 P6 Y
</td>
" V: \$ q0 @/ d9 b( f1 c
<td>
: w6 O# h) H# i O I! K! m+ h$ h
<select multiple id=city style="width:150;height:200" class="bgc">
' g! {0 C4 O. k. K4 Q3 p
</select>
0 X+ ]( |! \$ e8 E
</td>
& X$ H* ~# l. r- c8 Q
<td nowrap align="center" class="bgc">
k$ f' g# Q0 k6 ]% }+ |4 X" n
<input type="button" value="<<" class="buttons">
, f" x( Q) y: o' G+ y
<input type="button" value=">>" class="buttons">
* h K# ~* W2 J. I/ A1 \4 D
</td>
1 N! y" ~ Q5 R4 o. ~0 U- h
<td>
4 l0 D/ w( v' r2 Q/ B: [
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
$ l3 |& D H E6 f
</select>
% n; `) c8 a( C
</td>
% o) k) }# B4 ~. f# p0 g
</tr>
; u& ^5 y& V8 e: t+ e
<tr class="bgc">
9 p0 N6 i; j1 T) B; ]7 {) [$ f! G
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
& `2 _: f" I; {6 \+ G4 b
</tr>
4 ~0 w8 @, e, L1 c0 @; H0 w2 F) ?* _( i
</table>
. Q* Z. A2 p( l5 s3 \% V4 p
</form>
7 k8 h! t. q/ r. a
<script language="javascript">
2 P0 S+ G8 m3 D8 n2 \. q6 `+ j+ k, R
//人名移动
- D% B7 D- k% L
function move(fbox, tbox) {
4 D: H" y! ?! ]: l; x0 q3 t
var arrfbox = new array();
' G6 {7 c. r. i1 E
var arrtbox = new array();
% Q& }! f% u( A" A" ]0 c
var arrlookup = new array();
: ?1 g! T% ]4 Y# |& l# b+ f* U
var i;
3 J7 J8 J# w* S" E% a, l
for (i = 0; i < tbox.options.length; i++) {
! E5 ?0 P; c* ?* u, ~
arrlookup[tbox.options
.text] = tbox.options
.value;
% h2 B `5 g& i& j- t+ X
arrtbox
= tbox.options
.text;
n! S6 n1 ^; K4 l& ]
}
' v; H% R# l! T% o" p+ y
var flength = 0;
7 @. B, ~( d* n. L, p% I
var tlength = arrtbox.length;
; p; V: a# n s
for(i = 0; i < fbox.options.length; i++) {
& ]; }) }8 c3 t+ ~5 ?9 }* N* S
arrlookup[fbox.options
.text] = fbox.options
.value;
& P: z+ q* z1 [# e. @* i
if (fbox.options
.selected && fbox.options
.value != "") {
0 ]$ \5 A9 f1 ~- R2 e
arrtbox[tlength] = fbox.options
.text;
( p4 ]9 Q$ u& C1 f7 K7 f/ z
tlength++;
X! C9 R. e1 s; ~
}
* o) U( z8 {$ d8 e; c, ]$ W$ ~
else {
. N; \) V( |% h1 m9 \
arrfbox[flength] = fbox.options
.text;
3 i: R% n: ]5 p8 j0 ~4 X: P8 X
flength++;
l% w6 j; e+ f9 y# M
}
0 K5 l* _4 Q! H
}
& A' y3 h2 Q7 X4 t1 u& Y& h
arrfbox.sort();
1 [) W1 u H" U' q3 i) y
arrtbox.sort();
1 _7 j5 |7 S& O; e# r
3 C8 b! e- |: m! b/ t: T
fbox.length = 0;
7 E$ i1 b' w) l
tbox.length = 0;
2 k7 T) E. s6 D# }( A* y. j$ w
var c;
( S$ U8 Q, }* t& C: G
for(c = 0; c < arrfbox.length; c++) {
: D: T/ D8 G. l
var no = new option();
; m& v* y2 d. |: `, Z- ?$ f
no.value = arrlookup[arrfbox[c]];
# |& k/ v" D1 @" Z# k5 Z
no.text = arrfbox[c];
e, ^9 W. Y) A
fbox[c] = no;
/ Q' \% B& v- f5 l
}
2 L0 W' d' t8 `- I' [
for(c = 0; c < arrtbox.length; c++) {
9 s: c; v" [0 n* `1 o* @
var no = new option();
0 x# H0 e% v, s: w
no.value = arrlookup[arrtbox[c]];
- j3 i. o1 P: H5 \2 P% c1 ~
no.text = arrtbox[c];
* i( Y, I8 ]' t) a; Q% E! s+ S
tbox[c] = no;
* I# Q( m2 E' U; ^+ x
}
) ^5 W( d$ u ?/ p2 U, I2 Y
}
* ?- s3 |/ J) a. ~& S6 l
</script>
! q0 r2 k8 D& i
</body>
/ h4 y! m% M# P! s) |' |0 B5 U
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2