标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
: z7 V! r8 ]# C# v
c pageencoding="gb2312"
: P- j, _" Y2 A/ |1 G9 T j
%>
' V3 Q: K$ g5 r
<style>
3 m; h! T8 a' R! s( K6 V1 w
.f9{ font-size:9pt; }
9 h4 m- G2 s, D$ _ M) D
.bgc{ background-color:#aecaf9; color: #0033ff }
9 p5 u: x6 h/ C0 j
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
, d( k9 o* I, i0 H1 j2 U
border-bottom: solid 1px #4e7dc1;
3 Q1 p) O$ l/ M1 A$ @, P( D
border-left: solid 1px #aecaf9;
( \% B! e: p4 `; K: @& N" g) B
border-right: solid 1px #5679bd;
* k$ _, T: |+ C
padding:1px;
. Y i2 |9 A- {
margin:0px;}
2 b6 J* g2 t, t. }; t1 ^% u
</style>
/ v* V; b' K. ^8 g3 {7 g
<script language="javascript">
9 v8 Q7 K# l# L8 B2 B3 k7 h; c t
<!--
3 m c4 e1 Y3 K Z
function rv()
7 v+ ^% k3 C2 l& `
{
. H, G4 F- l- o! B
var val="";
: T/ c' }4 S6 N* s3 I
for(i=0;i<combo_box.list2.length;i++){
" a) p& O% X2 _# h* Q
val+=","+combo_box.list2
.value;
5 p' p; }0 L# e; q( r6 _
}
, V- g }$ v2 M1 k
if(val.charat(0)==","){
3 n* u0 {/ e. _6 Z8 P
val=val.substr(1,val.length);
; c; V$ i/ }1 s/ E% Y, S+ I
}
8 L* M) j6 Q; i' f/ _1 a: V
opener.form1.frecname.value=val;
3 n* [. C" |* n. y
self.close();
" D1 Y. ^% [1 ?- d2 K P& C. H2 O
}
# g$ Q8 c8 C n8 F) Y
//-->
9 m( p, L4 l$ b
</script>
8 j0 b: Y! h6 @3 `6 L v {
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
3 b7 a" j: J$ \" a9 L4 @, Y2 n" K
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
$ J1 L" _* A# P! i" F
<%
* e2 A! P+ V/ H
cdatasource ds=new cdatasource(); //数据联结bean实例
! ~1 x. N, O$ o- ]7 i
java.sql.connection conn=ds.getconnection();
& T$ D: [: a1 h; D. N
java.sql.statement stmt=null;
! M: W a/ C0 d2 o" t! k
java.sql.resultset rs=null;
4 \# Q* G Q* }, K' K9 o. _) }& ?
cdatacheck dc=new cdatacheck();
; _/ d$ `& Y8 G
%>
6 m5 L; e z& T- q) \
<%
( d: F0 \, o& c' f0 h6 k; E! E( z
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";
" D l6 y+ H. n- R, J7 i' s
stmt=conn.createstatement();
# V' m* K, E' K# t, @. t$ c! A
rs=stmt.executequery(sqlu);
2 P' u$ U h* F" [/ \, c
%>
, H# d6 J! A+ h% }. N
<script language='javascript'>
5 K L4 g" ~- W% S1 P' u: u8 @
arr = new array();
" F, w& U c0 J, M5 e
<% int temp=0;
! D I) R4 b6 x4 C$ a Y: L4 d7 V
while(rs.next())
; R! ?4 T$ J* I, I9 v* A5 a0 U' W/ b
{
1 i6 ^3 @& m% A; ~3 A
%>
7 T4 @9 y9 l8 e. H8 [
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
9 P4 a1 i4 [6 N! C* u
<%
* k: l- @( y* y- y4 \( Y4 j
temp = temp + 1;
' s: |0 u+ ]; ?2 R/ j/ n
}
5 H& x* F1 T! k5 a; J- t8 f
%>
% [* J# \! z/ }5 ^
temp=<%=temp%>;
* Q# M( Z8 [) _7 o: L
function changelocation(id){
8 `, R, ^! m2 P& R2 `0 z
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
# w6 C& J+ z* l" A5 b* k3 O/ S
var i = 0;
]( Q( n( N" k
document.combo_box.city.options[0]=new option('-------','');
6 l: b" z4 a# O T: P1 m8 w
for(i=0;i<temp;i++){
" f* }& ^: d/ O- b J, C) e
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
9 K9 g# s- P I( _5 H
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
- Y* p% F0 z0 P ^/ U0 E
}
5 i% k" R- M0 D+ u; {/ U* ?$ K2 \
}
) D9 x5 ~6 [' P
}
8 T% h' G" R4 V* w- ~
</script>
4 O% v! N T2 n" o+ J) R: x% |% r/ k
1 I4 D/ r# r6 Z, Y% r( a
<form name="combo_box">
$ G4 ^7 x2 U7 Z! s. D+ G& T; Q
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
8 }% {0 ?' K L/ B5 i3 ?. ]3 }" L
<tr height="24">
3 E+ h) W( C, S/ x: ?& l) k
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
1 a4 \# N: X+ P9 u' Y
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
( u# o w, k2 y7 a
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
/ M+ c* X1 p' q8 y. m
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
5 `+ }, {% T% s
</tr>
" ]8 D3 W8 M4 N& R* D) R4 O
<tr>
: y; M) k. X$ z: S2 }
<td>
9 f; B( p& J6 E# F
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
8 a* G" y/ S9 h' T
<option value="0">请选择部门 ---></option>
) T$ s: J5 V. G
<%
( x3 D) n) t0 e& b+ T6 \
string sqld="select * from tdept";
1 f! T: C1 V$ p* V5 Y( c P
stmt=conn.createstatement();
3 D8 z5 F* l/ {0 n* n4 F
rs=stmt.executequery(sqld);
$ a" z( E2 d% W. W
while(rs.next())
6 t0 H* T3 d8 e/ X
{
1 ?6 K2 \0 W! e/ }7 ?, Q
%>
8 b+ u {$ h4 z% m4 h7 l, F
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
& i \9 R; z# s. G$ ]" j1 u/ i
<%
8 v: F: j0 e$ Q7 x& E. U9 Q* p
}
5 Q0 ?6 a- e5 A- R1 Y
%>
w1 A' S& x/ m6 x2 V( H
</select>
6 A2 R' c1 d7 G1 z% f% _- ^
</td>
2 t% _1 B' C5 N$ c
<td>
+ Q+ F) C L, v5 p* i, O8 ?
<select multiple id=city style="width:150;height:200" class="bgc">
! G7 d0 _1 O" L5 A. E
</select>
0 {! N/ u3 z8 S- y% B% d" R
</td>
* {3 ^1 u/ n( U" ], R6 z
<td nowrap align="center" class="bgc">
# j7 W* M+ y3 ?
<input type="button" value="<<" class="buttons">
! ?' D8 Y" U3 Z7 N+ E! r0 j3 ]) `! X6 j
<input type="button" value=">>" class="buttons">
. D1 g, j. _7 S- l
</td>
) W0 {& N5 ]0 n% }# o
<td>
+ n7 \5 ^3 N( @4 }% N$ U2 }
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
$ \* v$ Y3 G. z1 u* q0 J3 l
</select>
( _7 h$ X5 F) ], x
</td>
$ m( c J6 i4 U6 ^3 C! q! A$ p# ?
</tr>
* V- v) X9 _1 B8 r( {2 q
<tr class="bgc">
$ s& i* t' A* G3 c7 h9 q+ C$ S
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
& N$ U( ~6 H5 ^* a. ~# D- p$ y" I
</tr>
" k7 A: ~ m! J: y) z$ Y
</table>
8 |4 E% R0 l; X: d
</form>
6 }5 R) e! j2 a- o2 X7 J+ O+ F
<script language="javascript">
( _8 F9 q6 Y* e7 k/ A
//人名移动
2 t6 W6 {: Z: e, O9 s5 m% N2 o2 l
function move(fbox, tbox) {
1 ?8 t- k! S: m, P$ N' h
var arrfbox = new array();
' j, q$ _' i6 r
var arrtbox = new array();
4 I: S$ U' j6 p! k" c3 Y2 k
var arrlookup = new array();
! {+ O" l- {, f. a# `8 H% t
var i;
2 B# \6 A, {1 L, X5 D
for (i = 0; i < tbox.options.length; i++) {
. J; b3 n# a: F
arrlookup[tbox.options
.text] = tbox.options
.value;
7 A( q6 H2 Q' [4 y
arrtbox
= tbox.options
.text;
; B% Q n# P2 b2 m. v1 f7 |" {
}
* s3 h( ~, y! M/ i" j8 ], i
var flength = 0;
" z( b7 e3 _. C: v
var tlength = arrtbox.length;
# e/ l; ]4 U j- q+ P3 y, S+ D, T
for(i = 0; i < fbox.options.length; i++) {
9 d! }* G9 p( _/ a, E" z
arrlookup[fbox.options
.text] = fbox.options
.value;
0 _ ]9 q! g) f4 S' U
if (fbox.options
.selected && fbox.options
.value != "") {
6 M7 |2 D) |9 m
arrtbox[tlength] = fbox.options
.text;
3 _! ~& ?" N4 [0 Y
tlength++;
% E$ @( b. ]/ j$ a9 G5 l
}
' u0 ]- j Z' [4 L. {" s: J! g* v2 \
else {
8 F0 @( O& b# c! ?% p
arrfbox[flength] = fbox.options
.text;
, N% ?" j0 @- u' R; Q# l% I7 R
flength++;
9 A% w; T, i) G+ f. @: a' A
}
9 z( _0 ^/ B- j8 I; d, m
}
* n6 u- t* m+ t( m+ v
arrfbox.sort();
4 _) q( j p: j! V. H/ F# j6 f L
arrtbox.sort();
6 G" m3 F9 q1 b- X( _9 ?3 z
0 B5 [$ m! K" e; R! W- V
fbox.length = 0;
) E: w: H3 Z; B5 T& F8 V
tbox.length = 0;
+ I( i* V! T# E& {( I8 F% X# t/ x" Z
var c;
. A) M8 A( x. f
for(c = 0; c < arrfbox.length; c++) {
" D# y. }0 I% }, x3 U
var no = new option();
% i) k I3 |9 R: z
no.value = arrlookup[arrfbox[c]];
2 \ X& S/ z) R# D4 v
no.text = arrfbox[c];
, r' `2 s5 U3 U4 j. Q
fbox[c] = no;
* A* p: w% i4 p6 H/ T, x2 t
}
0 k) M1 N8 R; `: Q) _& N7 c/ H7 C
for(c = 0; c < arrtbox.length; c++) {
' Z3 \6 {2 A o5 t( ?5 w
var no = new option();
6 G0 A4 i0 B3 s
no.value = arrlookup[arrtbox[c]];
8 n0 U# N# l+ w, d+ y0 U+ X( g' J
no.text = arrtbox[c];
; J: z# y3 ~% L$ o5 n1 q, k
tbox[c] = no;
: o& s4 x3 P7 | v9 S. o
}
8 W3 V# H @/ g7 O: B( f
}
8 v5 ]2 J2 H" r- b$ E! L6 m' D
</script>
5 t# X' v( w( E& T! v
</body>
' O. Q% L& Z( x9 G E
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2