标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
( `, Y# r3 x3 L2 w* C( o
c pageencoding="gb2312"
/ r+ N2 y8 i+ d
%>
' D0 Z) e; _8 _ ^) ^: S5 r% o
<style>
( D# @3 c$ m* M: a) Z' M
.f9{ font-size:9pt; }
6 Z" u; T) x' @- V8 S4 A2 h
.bgc{ background-color:#aecaf9; color: #0033ff }
& X$ Y# b$ v1 D; y$ R+ D
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
6 p$ Q4 `, V( t2 E* c/ `# F
border-bottom: solid 1px #4e7dc1;
8 @9 V# O; C3 _/ L
border-left: solid 1px #aecaf9;
+ e- k: |% B# F9 t0 }& i0 q+ t, K
border-right: solid 1px #5679bd;
6 Z0 t A" V, P7 N8 X6 d% J
padding:1px;
|+ D8 Y5 V+ e
margin:0px;}
# G1 J( z: {. p. h' q
</style>
! Q& p% d+ }" `& l0 Q3 t
<script language="javascript">
: O0 Q( K" Z" {+ I& X' s& W
<!--
% u( p. F! g7 B1 Y' r
function rv()
; A! q! h+ n5 g( G5 Q$ U
{
: @# W7 l6 ?& e& E3 @9 x$ J6 _
var val="";
; k* _& V5 z# k+ @5 _
for(i=0;i<combo_box.list2.length;i++){
( B/ J* d2 }8 P( m4 W# B3 F
val+=","+combo_box.list2
.value;
8 p$ u7 a* q' L* N4 p, s' ^8 V
}
8 I/ h, D$ X/ _9 B! C
if(val.charat(0)==","){
/ R. e. N7 Z. G) Y% x% D9 J
val=val.substr(1,val.length);
0 { c1 S% ^6 e2 v3 ]6 }
}
4 u* R. p2 Q$ {( A7 P1 A
opener.form1.frecname.value=val;
# c' i7 t% M/ p: \; V
self.close();
8 _" e& Q7 q. V/ a3 D/ _3 g5 m
}
. z- w' S7 ]+ T6 n7 j7 G/ R
//-->
7 q2 E9 s1 N- I' ~, P
</script>
/ ]8 K% C% `' l: x1 Z
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
( [. Q3 u* T, m- |( q
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
K* l% S7 B5 U4 I
<%
2 i- e# Q9 P$ M. l& p O
cdatasource ds=new cdatasource(); //数据联结bean实例
$ P, X! B/ V$ m+ n
java.sql.connection conn=ds.getconnection();
# S: u" \- t: U7 k) }7 X2 V" |
java.sql.statement stmt=null;
, q* B, |# \% K& a* f
java.sql.resultset rs=null;
1 } y& V z# J
cdatacheck dc=new cdatacheck();
" K3 i6 e9 i/ r- r
%>
. Z( y8 x0 y7 t" g
<%
( `; n$ m$ @; b/ 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";
, [, \6 v3 Z; q9 ~ h. V
stmt=conn.createstatement();
: u2 Z* U+ f! y& Q- L; p h
rs=stmt.executequery(sqlu);
% a6 ~. R6 j) Q% S5 h w
%>
, @2 U7 G/ n% A* y
<script language='javascript'>
; E7 L% @ Y/ }$ ~" F1 P4 u* _
arr = new array();
: z d% `7 u% x1 T+ k$ i. c
<% int temp=0;
V& t( M" |1 D, J9 x
while(rs.next())
7 A# W1 } h4 e& l
{
9 Z" Y: m6 `/ ^/ G3 H
%>
6 C* y9 A! q, s H# W
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
! l/ k5 q9 m+ s3 Z* n4 L3 M
<%
) k9 @- E( b* ^4 Z
temp = temp + 1;
' ?: v+ i8 |# X+ c, h+ c
}
; ?* ?% S, s. J5 b' ]( Y7 o
%>
' p7 b: D/ y( r% b' ]# K* g0 p
temp=<%=temp%>;
6 Q) `) }4 C' D7 c. E
function changelocation(id){
9 a* h5 U& X( R9 |6 p5 Z: ]5 ~
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
% a+ K t6 t2 T
var i = 0;
# R! ~( p* |' B% w% r& P
document.combo_box.city.options[0]=new option('-------','');
( V; v; t# X( K# e$ _& ?
for(i=0;i<temp;i++){
- q( w3 r* f+ @) Y, S; U
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
- b2 G4 M& b1 l$ ]* c A
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
! K0 Z: r8 _% e5 l' P
}
+ p9 S$ p) u; c4 G7 V5 T
}
# m( q$ l0 q- F
}
- z1 R& ?( p' } o
</script>
& |8 i- H0 E$ ?* r* b
$ u0 W$ l- I4 }' Q; f$ K- y
<form name="combo_box">
5 G) @2 k% y& h" k. N
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
9 j; D# I* S! Q4 ?& b" k
<tr height="24">
( K" O( o. Y) |: M" v
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
6 f( ^0 Y- D" a
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
. u8 |5 }# _ u- z& l; f
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
) }& c# r; P, s
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
, D, O# K$ {) C& f4 w
</tr>
; y# ~+ @2 x- k
<tr>
% }- w( ]# g3 o* {+ K8 m2 g
<td>
/ ?8 v4 [1 }3 S- z
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
( N! |; S1 T8 s: Y
<option value="0">请选择部门 ---></option>
: l. O, Y5 f+ _% F0 E& T
<%
, T+ w& ^; b8 U* l. Q) Z! D
string sqld="select * from tdept";
: [: ~! u+ w6 q j* H
stmt=conn.createstatement();
" |/ S. k1 p; i6 c! l' h! B
rs=stmt.executequery(sqld);
) e; B* |( K' Z3 V- G9 K% w$ j6 A
while(rs.next())
5 e& y! S4 {% D' S2 u% c9 }4 M
{
% F% H0 u& ^6 v1 y7 F8 v
%>
5 b; n0 v: @0 F0 \' z
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
2 |' @% w9 S. X7 p
<%
F% b1 c/ {3 W. X+ T' I
}
5 t) Z" K7 Y1 [' x. i$ O
%>
' G: Y& h7 F$ f, N! `
</select>
& h. l% ~ c" S6 I$ k) C1 r
</td>
: A: v9 Z2 ^9 C" h) _6 i5 I
<td>
$ y1 l, a( l' G3 R' e
<select multiple id=city style="width:150;height:200" class="bgc">
# l0 d6 y% r: }# E$ I
</select>
! l, h" P: \+ ]' M# R5 p$ Q1 M9 ^
</td>
" N1 W. {4 s' b! v& ~0 t- Z
<td nowrap align="center" class="bgc">
% }4 b8 T: \' t* t) @4 [4 u9 n
<input type="button" value="<<" class="buttons">
A# i0 I( C* c, [, V2 m
<input type="button" value=">>" class="buttons">
, T9 {5 V3 c! ^1 {0 `9 w" _
</td>
6 X9 G1 }) _5 ~
<td>
2 e( Y8 z2 q/ H, O6 \
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
" p; \" [; Q/ s
</select>
. v3 a4 D1 M$ E6 C! |3 o
</td>
?" c& \" y/ G1 v( q5 j% Q
</tr>
, v) T8 J' y: K( l! r# G6 [
<tr class="bgc">
/ ]0 r3 X; ]' S- s9 T
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
, r0 p) Y8 y1 o: P
</tr>
* A' @+ S2 l# }* c
</table>
- D3 O; a$ E! M8 ~1 \4 e
</form>
8 {9 x \/ t4 ^+ T" f% |3 v0 |
<script language="javascript">
2 c% P, B: l0 c
//人名移动
; ?. c4 L; E5 L* h
function move(fbox, tbox) {
8 H' O' r/ a& c) w2 s! E4 m6 Q
var arrfbox = new array();
4 b" s2 O! J' p9 v3 R( I2 M# J
var arrtbox = new array();
1 b; @; X) h) K2 s. q
var arrlookup = new array();
_2 M* g6 p, L5 e
var i;
7 f. Y& W% M" B* i2 n
for (i = 0; i < tbox.options.length; i++) {
/ c# u- s2 u+ \1 }) i
arrlookup[tbox.options
.text] = tbox.options
.value;
7 @5 ^7 Z" ~7 q. a0 o7 s
arrtbox
= tbox.options
.text;
3 e6 n& K1 l* _* D1 c) \6 V7 }
}
9 D) F8 h0 R" ^2 J9 D2 I- `
var flength = 0;
! x$ }, r+ y5 [9 M) q* M2 f
var tlength = arrtbox.length;
- Q5 M9 L6 O' `
for(i = 0; i < fbox.options.length; i++) {
" i% ~8 P. [8 e
arrlookup[fbox.options
.text] = fbox.options
.value;
1 Z7 X$ V2 k' K
if (fbox.options
.selected && fbox.options
.value != "") {
, X, e7 S, G0 q; T8 R9 p! B
arrtbox[tlength] = fbox.options
.text;
+ e4 s3 I0 ?1 Q
tlength++;
) P" W9 j0 h! I7 X; B6 N
}
% d r a2 `) V. g8 Q3 q
else {
, q! p9 a7 `9 ?9 ?
arrfbox[flength] = fbox.options
.text;
& ~- q" G7 e/ h, M# L
flength++;
/ m9 V! F) l/ E
}
8 O$ m# y% x2 g9 z! E# d
}
$ y9 |) l4 Y7 T! Y! U. {: C
arrfbox.sort();
3 B: F. s: _8 a# E5 e
arrtbox.sort();
; {4 ]9 q' h! S: C: {' K% E* l+ K! M
& G* Q( ^$ {( x3 |7 X& H
fbox.length = 0;
+ H* ?3 p7 Y7 ~0 c- `/ h. f
tbox.length = 0;
- E# a$ _% `9 L/ _' K
var c;
6 W5 O, N: ?! a. D0 Z. l {1 x# S
for(c = 0; c < arrfbox.length; c++) {
# Z2 r: G+ E& L
var no = new option();
! o! r( W" Y& O* V$ l) h- t
no.value = arrlookup[arrfbox[c]];
' R* \$ v7 Z+ @
no.text = arrfbox[c];
6 r% n* V1 L" h. K# \5 `6 h; {
fbox[c] = no;
0 t8 f Q) Q; ^, @/ @4 s& {+ C
}
* {+ u/ a# z+ Q1 w! F! A: L* i
for(c = 0; c < arrtbox.length; c++) {
7 Y0 Z! n' i. \- P* a2 N+ g8 K
var no = new option();
0 S4 ]6 q- q% N" Q7 G7 F
no.value = arrlookup[arrtbox[c]];
/ I% Y, ^% f, g8 r; P
no.text = arrtbox[c];
3 c) N7 x2 y* z# L& f! J
tbox[c] = no;
& q# D5 K. j/ w
}
+ z% n% S$ g& r
}
s- P3 R2 S/ Z% E: t" R6 r
</script>
" O; A& z% E0 ?% t7 r+ z& D
</body>
: ]. b! t3 M, x: _+ h) t2 y
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2