标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
0 c. F+ |/ I5 F
c pageencoding="gb2312"
8 f4 e* W$ E6 z
%>
6 m* S4 e: x' F+ V' V7 U
<style>
1 n' N6 {1 M% L' Z
.f9{ font-size:9pt; }
. y: Y% e& N5 G2 l
.bgc{ background-color:#aecaf9; color: #0033ff }
5 p' Y+ j' _0 U! [8 u3 U% g* }
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
+ t$ { Z2 j7 r
border-bottom: solid 1px #4e7dc1;
4 s( c2 U' C W
border-left: solid 1px #aecaf9;
7 n% {: K) E+ O* t, @
border-right: solid 1px #5679bd;
* A/ J: O7 D/ w7 V$ L* Q
padding:1px;
; ^ Z8 I$ {8 S
margin:0px;}
) G, q. k/ R1 Z p' E2 e
</style>
" Z7 C) j/ }3 f& w) {) N
<script language="javascript">
* f! Z* P" U( O" \4 Z5 ~3 D
<!--
2 I+ b9 ~4 Q8 }2 \
function rv()
- z3 Z; Z! X' _8 A9 ^3 f5 l
{
+ \: k5 W+ \: z4 W6 s
var val="";
6 u! l5 t# ]5 }* D K
for(i=0;i<combo_box.list2.length;i++){
/ ?% x# `5 \' x- F1 J& d
val+=","+combo_box.list2
.value;
( b$ W6 S) R* p$ ]. x0 D
}
$ _- L( N) K6 w0 Y" }" f
if(val.charat(0)==","){
2 s0 |- J/ U. {
val=val.substr(1,val.length);
3 i* Q% x- u7 s( ?5 n8 h
}
% _2 n8 j. S3 ^7 \
opener.form1.frecname.value=val;
4 e7 b" J- i8 e% {
self.close();
; u/ s6 Q1 M2 h5 e6 u- l4 C' ~
}
9 k8 g9 \* K4 c1 P& @9 U
//-->
: H; U6 w( Q8 U( M* O
</script>
( m$ l( n" {) @- W4 Q! }8 a
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
& L# V# }, Y S; ^2 r
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
) |% \& X( X( e8 A# A$ L% j
<%
) h. w* x9 i$ j" w
cdatasource ds=new cdatasource(); //数据联结bean实例
5 ]! J( @; j- z' f( [
java.sql.connection conn=ds.getconnection();
1 h c# s5 q) i/ k
java.sql.statement stmt=null;
: Y/ b# G+ R4 q6 K0 E& k
java.sql.resultset rs=null;
7 ^! Y$ A' X' K1 j& b
cdatacheck dc=new cdatacheck();
. {/ ^, a. E- X+ w1 b4 x. Z8 b
%>
$ _$ _* B# N' L' c1 G
<%
3 G' @0 ~6 K' x9 Y; b# q( T
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";
/ P: E" H3 e- @6 {0 J C$ G* I7 Y. r
stmt=conn.createstatement();
/ M, M3 f7 J& L/ V; w
rs=stmt.executequery(sqlu);
) P( \: Y7 ^. k. |
%>
9 a) {3 F& E$ K: s& D: \/ p
<script language='javascript'>
1 A' E0 x" ?0 t% H" F( F5 C8 L6 t8 W. r2 S
arr = new array();
/ t' G j( F: `4 d, e7 P% W R$ o* K
<% int temp=0;
) [; Z+ y( z# q& @
while(rs.next())
* C% t& m6 G5 P- z
{
@6 a& e9 S- ?( T4 \
%>
; s% [' \* s$ G: [% p
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
3 i* J0 o: G; Q {1 I/ }
<%
' z* Y. M9 o `3 z( s% D1 q
temp = temp + 1;
# t s+ D# G* y) f0 l
}
% u8 i+ C- k6 s P
%>
8 C' G. V: e& C
temp=<%=temp%>;
' t; `9 ?% p- P9 i) v1 c
function changelocation(id){
+ A' R8 ?4 \2 r5 Q( y! W) ?
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
) [1 o, j9 y3 S
var i = 0;
! C G9 G& j# X; S' I
document.combo_box.city.options[0]=new option('-------','');
) S. k* M! J. k3 b6 B% [) l s
for(i=0;i<temp;i++){
# N1 e' m4 B/ m( y+ J
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
* y) p: o( X4 c' a: R3 a, ?3 W" k
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
8 D. S3 ?" ]6 t0 o g
}
0 _0 z4 H8 \, _/ r
}
# C/ _$ o1 Y6 a0 I
}
3 o, O0 H9 O) Q4 C
</script>
( T* I9 T, z, T5 `
* R3 t2 D2 t% P; L
<form name="combo_box">
+ n7 [/ I! B x. A* D5 y
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
) m- S* ] ?! }
<tr height="24">
# k3 [1 r, A1 q$ A
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
& J" x% L# V/ A1 n# G, E; H1 A
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
$ |, T* o" [( D
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
E; m6 v( @ J( a% j" n" r; K' r
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
; R' i e9 t( r8 X% L- @ z
</tr>
( }( {) S# w. U& R
<tr>
( O: p. {, `0 A/ y
<td>
# n1 o; n3 i0 y0 @# L j
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
; C+ E; X3 L9 g/ x3 v. F0 A
<option value="0">请选择部门 ---></option>
' z4 d9 l1 ]* a/ O1 ^
<%
# x! C3 u: [% r. y4 Q6 M* g4 R3 `3 x
string sqld="select * from tdept";
- j+ S0 m4 r3 B1 F) z" S, p
stmt=conn.createstatement();
T0 m' Z; j" [/ F; k
rs=stmt.executequery(sqld);
4 K$ D0 m: w- u& U3 w& D
while(rs.next())
9 p! r) t) h: {0 g# G/ F Z
{
9 b3 ?0 d- P0 x# k
%>
: m9 M# B4 e/ k
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
d. x R9 P% O9 E* J
<%
4 j7 v/ X& A3 k5 H' M( r! Y
}
0 g; H' Q% i. N' X
%>
( M1 S4 w) [; F, @: k- W8 o
</select>
- n9 i# ? F8 q, k5 d0 p" {
</td>
% M3 M. d' F2 U5 W' v: x; g
<td>
, b+ o O+ Z) G5 U! _! g
<select multiple id=city style="width:150;height:200" class="bgc">
3 }: s8 }1 p) J5 W! v" K d+ u
</select>
& i4 O* i- D7 I' k. Z4 X6 O4 x
</td>
7 m: x9 }8 P1 y* J4 M9 k# M
<td nowrap align="center" class="bgc">
& A: M) l" _9 a6 c# d* r
<input type="button" value="<<" class="buttons">
* O8 o. Z& A/ ]; t
<input type="button" value=">>" class="buttons">
# B' ]7 e& H2 c& N4 `/ m7 V. W8 n
</td>
: k8 I; O2 m$ v, H6 g( C
<td>
/ N3 K) b8 G2 P& u1 ?/ v
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
# \9 Q( ?7 o& i' S- e4 ?) @2 s
</select>
0 Q3 C5 I% o' E
</td>
! V& g( T0 E( F3 j0 u2 F
</tr>
2 e1 S' y5 d; P, s8 V
<tr class="bgc">
3 q: U+ N" p ~" O! C/ [
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
( R) I e h. h3 P9 F% {8 y
</tr>
1 O* V/ C k. Q0 ~* |7 k
</table>
' D2 G: d5 L: i$ `3 r' s% n! A
</form>
7 M# U& q# p4 {$ J% \3 O
<script language="javascript">
2 J9 C, q3 W) A& ?
//人名移动
- W6 g7 [* P- q
function move(fbox, tbox) {
1 N9 m' [ A8 r
var arrfbox = new array();
/ j6 j* h. H: j5 K# w
var arrtbox = new array();
% X) Q9 [7 M( T2 t) r2 C
var arrlookup = new array();
( @4 _# n6 c p5 g5 {
var i;
- p6 H8 k. ]$ a) c7 `/ U P f
for (i = 0; i < tbox.options.length; i++) {
6 V+ N3 v! P* \( j; B5 T
arrlookup[tbox.options
.text] = tbox.options
.value;
% V" J! K/ X w1 J) u" F& p) a9 R4 c3 s
arrtbox
= tbox.options
.text;
7 V3 {1 e7 h/ r% p* ~
}
! U ^! F$ }4 L _7 Z% }1 q
var flength = 0;
w( t* ]2 F1 z2 h" Z# M
var tlength = arrtbox.length;
) i& r0 u- M" x6 O1 }5 b. p- A
for(i = 0; i < fbox.options.length; i++) {
% \9 g+ F1 W/ ?( f
arrlookup[fbox.options
.text] = fbox.options
.value;
8 @6 f! | q b7 A+ E4 `
if (fbox.options
.selected && fbox.options
.value != "") {
/ l% \( j7 f6 e- I" \4 p; m9 N M; e. X
arrtbox[tlength] = fbox.options
.text;
! f) ?7 w& _& d; z) k x) \
tlength++;
8 ^$ N$ S7 w- M2 V" }$ U4 ]
}
# V" [5 i$ L( X+ L( c: K
else {
$ W# G) L. ~3 M p( r# @9 r
arrfbox[flength] = fbox.options
.text;
) M6 e. ?, S M& ~1 V4 r U# ?
flength++;
1 v: @/ |0 j6 X8 E: d$ z/ c( r
}
+ ]4 F; k( {# K2 h! V
}
. W3 j4 f7 s$ N" R4 s5 k
arrfbox.sort();
) ?! N0 r' s% @: c% G; I- K+ Y) H) [
arrtbox.sort();
, a, ^9 t* n1 h+ t& ]! t0 y
2 K5 E' D$ i: Q8 @
fbox.length = 0;
7 } W& U% a# L- T, p
tbox.length = 0;
9 J9 d) A8 b, G$ W3 c; m+ I
var c;
9 ~7 P) q+ Q8 [9 A/ ]
for(c = 0; c < arrfbox.length; c++) {
5 Q6 Q0 }. [. f( s* x
var no = new option();
$ \+ S& X/ i" s( l# c3 `( E& c
no.value = arrlookup[arrfbox[c]];
$ _' t# ^% [5 _3 Q$ M! Z3 K
no.text = arrfbox[c];
q9 A# k) p% S! R- g
fbox[c] = no;
6 Q/ P8 ^8 Y! l2 p( H" U3 v4 d6 l1 a) R
}
+ X7 x! J( P [
for(c = 0; c < arrtbox.length; c++) {
4 V. j! {4 V1 N
var no = new option();
7 @' u* g: b I: |$ I$ e3 @1 P
no.value = arrlookup[arrtbox[c]];
6 `9 ]8 V2 G; I4 d4 `+ h# {
no.text = arrtbox[c];
) t3 L+ D6 c) h8 s1 q
tbox[c] = no;
; G& ^6 y% T. x" y/ `- L2 A i
}
2 p9 g0 a3 t9 i
}
# S2 T% [, j- p6 P; g
</script>
# O( E! J! Z0 p, Y5 y
</body>
7 t/ E$ P# ?8 U, Z3 d( f( a. N+ }
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2