标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
+ t! @! y2 b+ n
c pageencoding="gb2312"
2 H1 X( v: h" M, O$ M$ W8 o% U6 t# Y
%>
$ m/ J# V) I4 F6 Z
<style>
_9 T) V/ d9 F# X8 ~* `! e4 }/ a
.f9{ font-size:9pt; }
; H) v" ~ P/ {) i' H) C. ?9 O
.bgc{ background-color:#aecaf9; color: #0033ff }
9 {' o! H! H0 v
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
2 ]# ^2 ?1 p+ G- ~9 ~
border-bottom: solid 1px #4e7dc1;
4 `8 u+ n8 C9 a5 ]
border-left: solid 1px #aecaf9;
. B& u% t E6 B% \5 Z
border-right: solid 1px #5679bd;
, t9 c: n% F* S+ X
padding:1px;
6 J4 E, G. F2 E& F- @; `, {2 R- u, y
margin:0px;}
8 @4 s7 e% e& E+ R9 M# N
</style>
3 A7 }2 D3 } o. }* c( r
<script language="javascript">
- g( G* i2 F+ e5 E1 z W V& h
<!--
4 n' c$ n) f, O3 N5 q. e8 H0 u
function rv()
9 G" |& `4 e* }% m6 N
{
5 k9 b6 g' D$ s7 ]) m/ ?: a; h% Z
var val="";
, c$ e" a8 n3 x& H, p* b
for(i=0;i<combo_box.list2.length;i++){
) t* }/ @1 y4 ^. e9 j. n
val+=","+combo_box.list2
.value;
. _+ L4 W, Q% S0 s8 d
}
" m* \" e, a& ?* E$ }( |; S, |# w
if(val.charat(0)==","){
9 n$ n; }& G* f; V) ?) x
val=val.substr(1,val.length);
6 x+ v1 N/ `% [' q4 }
}
* n' W5 }9 `! m
opener.form1.frecname.value=val;
* a- ^" M1 O, g" [8 U
self.close();
! N4 i9 d+ }6 y4 s7 K
}
+ @% k4 O" s# @! P0 J( N
//-->
4 m6 m, ~$ f& c8 F
</script>
2 {3 U9 `' ^7 o$ [- ` e7 n6 n# x3 }* I2 z
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
( d8 `0 o0 e0 L; C5 {! V4 b: `
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
5 y. j4 y: R$ r9 t
<%
! M8 d: ~7 j) G O" ~8 u! D
cdatasource ds=new cdatasource(); //数据联结bean实例
# j9 D1 a% A$ ?: E5 L$ y5 p. n
java.sql.connection conn=ds.getconnection();
/ k3 u; M& K: \7 ]5 `+ p- L! N& d
java.sql.statement stmt=null;
! i$ i3 n. f% U% A9 F
java.sql.resultset rs=null;
! F3 w1 L* P2 V B- V* ~2 {
cdatacheck dc=new cdatacheck();
9 d. K# ~ j+ q
%>
Y0 k/ c+ z' |+ f2 E' ?
<%
) M# A5 i7 E7 b1 l* i
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";
; N4 Q( u# K( @2 N4 \, }( q6 T
stmt=conn.createstatement();
+ p7 j+ u% f( U' `
rs=stmt.executequery(sqlu);
/ J h" h: p& E! z% z& [% t# W
%>
9 q" T: J( z" {% g
<script language='javascript'>
' S4 O6 _& q K4 _1 n
arr = new array();
! [6 [& G; w% D- l3 J b( ]; u
<% int temp=0;
0 {& _4 P" j5 I) p" o" y
while(rs.next())
) H# J: }6 f0 S: g& e+ s( X' R3 o
{
4 o: N# x- \% @; x" j! N
%>
0 T/ u" }* G9 [7 |- S. u% G
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
^6 L+ s- M) z) v/ T* E3 U; f0 a
<%
& B8 ]: O1 v% ?7 |
temp = temp + 1;
- x8 h* x9 s# c0 F; y: B- t
}
) q6 d; N T# N
%>
u8 ~+ l( e8 Q6 b! E2 J) y
temp=<%=temp%>;
7 j( F; T" n" q" L I! `+ U
function changelocation(id){
0 [6 ^9 Z, ]; ~& _! h
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
" M. b+ A$ ?1 H& H
var i = 0;
/ Z! n O- c9 q) X B
document.combo_box.city.options[0]=new option('-------','');
, | N. r9 l' Q1 l( L; D% P) J
for(i=0;i<temp;i++){
3 @# r; P9 U1 ^% u$ A5 W0 n& r
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
4 _: h+ e6 A% k9 L9 g
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
/ }( E/ p+ M2 M: l2 K" S
}
$ z7 I! _( A) A p; a
}
% N7 X2 E& z* j4 e: v
}
* i, i6 ^0 x' t3 `
</script>
- x2 R, Y0 X7 b2 v
. I* L3 O& p" j# W4 R
<form name="combo_box">
; S4 V9 K9 g$ U; K
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
. z' t" F/ \& d+ ] y, Q
<tr height="24">
1 M$ W Y& l! L4 q( v' D, L, ?
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
8 `& M3 ^& C4 N4 S) K7 d
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
. A- [* G2 G/ i$ i1 x! W
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
' w: [* @0 a z( T y! @
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
0 J: k$ Y! X3 F
</tr>
p+ G& s* j7 a
<tr>
9 ]; u7 ^2 ~6 [# i3 l
<td>
- J" _( y$ P9 }
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
' o- {4 h9 ]# \* U# u/ y
<option value="0">请选择部门 ---></option>
! g+ p4 [* i- V" Q
<%
, J% w0 p1 N: f- z% Q9 D- Y
string sqld="select * from tdept";
5 d u1 j) l" `6 j- U
stmt=conn.createstatement();
0 R6 F) b/ M p" V w1 w+ c+ e
rs=stmt.executequery(sqld);
+ k" [! r/ `" e! o+ b8 H. p9 W
while(rs.next())
! |6 \* ]8 @$ u+ Q% e
{
( ~+ @; T- s {7 Y
%>
$ J7 T7 p4 J! {1 F8 @! _7 n
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
/ D. c6 I4 s) T* v
<%
, W$ b, g9 j: e
}
. S) X* A$ \% O, M' C$ ?
%>
) D) \% ^+ }' y( Q5 t$ i0 M
</select>
# @/ C8 N* v( X3 H6 X1 `" O
</td>
1 y- ]0 T# B0 F% `
<td>
! X7 |) f* K; E1 l; N
<select multiple id=city style="width:150;height:200" class="bgc">
7 ], \& M( c5 u1 f' Y* w
</select>
|3 S. I4 {. j2 h3 q9 c
</td>
# Z5 r8 b* X/ C5 }& R
<td nowrap align="center" class="bgc">
8 U+ V- F+ |3 Z( n8 v
<input type="button" value="<<" class="buttons">
0 j- m) R. M7 w% d/ V
<input type="button" value=">>" class="buttons">
% ]2 J* I6 x, E- c, F
</td>
& m% Y6 U# ~# s3 C
<td>
& M% ? Z2 t) T! J, k1 C
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
( S$ C! f# e5 ?0 u
</select>
; R7 G, H( q0 a5 e7 s0 g; `; O; G
</td>
2 z4 \- ]3 ] q4 i, F
</tr>
/ ?0 P, ~, h$ j0 Y" Q$ ?% g
<tr class="bgc">
: H& D7 |8 a. I$ P$ d
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
: z5 c7 B& F4 ^+ ]
</tr>
4 W N" O" @' T- @) T. p' B
</table>
3 c* ^! R$ e' k: J4 U F
</form>
4 H! w) h* M7 d0 c1 y8 ~, I
<script language="javascript">
7 V" e- [- z/ h/ D/ Z( i4 B5 r; A
//人名移动
2 C; O( ?% e/ ^$ ` \# r! I, @
function move(fbox, tbox) {
6 i3 N8 Q# o T1 a
var arrfbox = new array();
9 l1 [7 A9 R6 ]5 H$ R) Z3 _
var arrtbox = new array();
: R7 {% a8 }9 L ]1 w7 e4 _2 l
var arrlookup = new array();
6 S2 p2 a0 {4 \4 q& u
var i;
9 t5 |/ R/ t* g, k# v) g
for (i = 0; i < tbox.options.length; i++) {
; H! G; U( d$ U, s2 F5 N3 T
arrlookup[tbox.options
.text] = tbox.options
.value;
, E. J; ?7 Z3 F( W$ y1 T
arrtbox
= tbox.options
.text;
+ v' O0 o, E( d) v# [
}
9 x0 ^/ N9 V \( f& `3 W
var flength = 0;
1 H7 O4 P j- i
var tlength = arrtbox.length;
/ s5 Z5 c7 t6 T) v
for(i = 0; i < fbox.options.length; i++) {
/ u7 S' R. u& Y8 G# L/ f$ P
arrlookup[fbox.options
.text] = fbox.options
.value;
% h7 M% q5 g( ]- W C
if (fbox.options
.selected && fbox.options
.value != "") {
. m' N7 Z, v( B1 n5 E
arrtbox[tlength] = fbox.options
.text;
3 ?& N; T8 k8 l
tlength++;
' f2 @$ X# [0 n+ }* ~
}
: G8 X# d% A" s
else {
' b' a7 { a; m: l/ U4 |. s
arrfbox[flength] = fbox.options
.text;
9 E% N/ [6 @" ^8 Y, N/ h
flength++;
0 M/ M( m: Y' f( N- K' i
}
k" Q! n9 Q$ G# C# X$ _! J. u8 ]
}
( a1 Q) ~; W9 L# F8 K
arrfbox.sort();
3 a6 k! H4 x3 u1 I% V: N
arrtbox.sort();
; ^. {( I8 c, a' R4 z! ^4 Z/ F
) y8 \; M3 U! p
fbox.length = 0;
5 a; C! F7 V' {( ~0 |* Z& O
tbox.length = 0;
|/ U2 d3 V% J C
var c;
2 o* W( W5 L2 ]2 b
for(c = 0; c < arrfbox.length; c++) {
: n* P; t" P6 ]. S, P! P0 p1 Z
var no = new option();
! J4 R3 q' N3 j
no.value = arrlookup[arrfbox[c]];
5 G% ^5 r* g0 ^6 V7 o
no.text = arrfbox[c];
" ^# D8 ?+ ?; ~
fbox[c] = no;
+ b/ U- p) b# y# [1 c
}
@# f1 e4 d2 ^
for(c = 0; c < arrtbox.length; c++) {
/ J2 {1 B0 C' c4 S, g
var no = new option();
+ J+ |/ H% q4 |- |4 q" C
no.value = arrlookup[arrtbox[c]];
. e9 r, t" q2 n2 r! L1 J
no.text = arrtbox[c];
6 [" j0 q8 `9 `3 H; t: ?( S: B, j
tbox[c] = no;
( L9 ]4 V9 x. G/ d7 s( X. G
}
2 r" `5 E# f* K. Y. v/ x, r
}
" C J. l" Z& ^5 X
</script>
2 e5 T( t; q* c" S" L( L X n! G
</body>
. C4 x: E+ e6 B7 f! r
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2