标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
" q* [1 O* Y; s# ]% h9 U
c pageencoding="gb2312"
9 a) w: L u1 |# H t
%>
) Y! B6 @# T. G
<style>
* o: c! g" |- N- k2 J4 m
.f9{ font-size:9pt; }
z: ]% X5 j8 v6 G0 g C0 T& b! ?
.bgc{ background-color:#aecaf9; color: #0033ff }
! l7 T0 Z. s2 B2 o; x- Y
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
% `2 t4 J' O) D/ |; {/ C
border-bottom: solid 1px #4e7dc1;
0 D7 H" H3 [1 U( T3 ~: {
border-left: solid 1px #aecaf9;
3 u% q ?9 C. I* A- {
border-right: solid 1px #5679bd;
8 c$ u* n( Q' e
padding:1px;
j) h$ ^, H/ G
margin:0px;}
& f! O" G. t+ q# p. Q2 r
</style>
0 f1 h( H" J3 o8 n0 n
<script language="javascript">
8 Z2 `2 D' b; p* ?0 B: y
<!--
5 ~9 r( k6 M; ], \* }
function rv()
. o0 A% o4 V! x) [8 `) E5 T4 H
{
; m$ ]; S6 @1 y0 [/ ]& T8 e& h1 S
var val="";
! x6 X% M0 T, [; h% w2 o! c8 n
for(i=0;i<combo_box.list2.length;i++){
6 h. w0 b! k E( |1 h9 H2 }* x
val+=","+combo_box.list2
.value;
f) v$ R, Q0 J) ~, B. {) X' s
}
. V+ u* L; P, p, c
if(val.charat(0)==","){
- h9 r& g" s( Z- `
val=val.substr(1,val.length);
- J0 G. I) [4 i% D9 ?
}
- m8 ^" I$ V4 [
opener.form1.frecname.value=val;
* s2 h6 K" F: E i& H G
self.close();
m( H. h3 r! F
}
/ s. A' N# i' M: ?" g: t
//-->
" c6 o9 q9 `5 K* H! B& P- O9 R
</script>
! @) C/ k9 G* _% y: \# n( {$ E9 l$ |
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
% m7 u+ t; {& V
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
; f! O) J. |: [7 S
<%
' |3 s, A( L( j2 K. q
cdatasource ds=new cdatasource(); //数据联结bean实例
" G, N- I$ |: Q% S$ R3 L
java.sql.connection conn=ds.getconnection();
3 d# h0 T% f, s
java.sql.statement stmt=null;
' `" ?. n1 W2 {8 s
java.sql.resultset rs=null;
* A2 b% Q6 Q; I7 H! C, Z1 q5 Z5 \
cdatacheck dc=new cdatacheck();
3 c! ], `$ S% E6 Y3 w" F
%>
: h+ J) Z; Q) P
<%
" q# U( G- |& P5 L% k
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";
0 \$ d/ s; x5 C9 s& L
stmt=conn.createstatement();
: U; k- E5 A+ U# n2 r
rs=stmt.executequery(sqlu);
8 b8 A. R) Q3 A
%>
! X( x" p4 ~7 a; h/ K" F* x6 q
<script language='javascript'>
6 n3 y6 ]' u$ o0 }0 V% o" k& T0 d
arr = new array();
- g2 d0 b" L; I
<% int temp=0;
. c( o, _- g: l0 [4 [4 ~9 g A8 p
while(rs.next())
5 ~/ |- i; M/ B- X* @
{
$ g3 h! m) m9 [
%>
0 R! Q) C$ R, Y6 T5 q! J- J( q
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
. h, J9 m+ T, `) N
<%
" w) k: }8 T' h
temp = temp + 1;
2 t$ u7 J; n; ^ P
}
5 \# [ R6 B8 P* h9 E
%>
8 u7 `9 ~( Z# l# p- a4 b3 L. U
temp=<%=temp%>;
) h0 z3 R0 D. E8 s, a( _
function changelocation(id){
7 n' J! a ]) o' Y' @
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
U6 p, w' ^( }* y3 i6 u' _2 ?0 K
var i = 0;
; R# `7 `! r* Z V1 ~, `4 ?9 D) G
document.combo_box.city.options[0]=new option('-------','');
5 x- l; E% j. z" Q! N0 N3 I! |
for(i=0;i<temp;i++){
6 f& [% u3 A! h9 ~# c
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
, H; a2 B: b- u8 p6 i u9 G
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
+ m! e8 A2 L% M# t3 X) x
}
4 ?& Y V/ U* q. ?; ~
}
% P- }% H; K7 h( l5 [3 j: k
}
8 ?) e( ?. R9 Z: X3 h" t' J
</script>
0 t: U: X9 Q( W, [
9 C& o% Q( V. ?0 C
<form name="combo_box">
2 Z& }1 o" q& {* G% K
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
2 R& E: f' }. N) G) Q
<tr height="24">
R u- w$ j% Q9 \5 i1 c
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
% V% ?; G* ?5 f0 P/ ?7 Q5 x
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
9 b' p' [$ }' V, @4 L; _0 V$ p' h& |
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
1 J" a9 t2 s# j( Y- o# W2 B0 N+ K
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
9 E# b& S. @$ \. k5 X
</tr>
$ h' w& `9 u& {$ e; G
<tr>
" Z& {1 z2 C- b- g
<td>
* z9 T" w/ @! O* L/ C; m( z, x! F7 W
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
; t9 F6 o6 h, k$ ^% D y
<option value="0">请选择部门 ---></option>
9 p& S: {2 e# z
<%
% q! J% b& H# f/ P
string sqld="select * from tdept";
( w3 F4 R* C8 J+ V2 P0 t: x
stmt=conn.createstatement();
% _, q" k. ? \2 J+ Z5 X% u; {" G
rs=stmt.executequery(sqld);
3 Z% z# @( H8 _& k3 Y6 K! x3 d' ~
while(rs.next())
; b$ M# }) {% q3 v) r
{
9 \0 M- Y0 M% f# X. |
%>
6 M: g3 {6 `) Z9 \
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
" b9 }+ T* P0 R" H+ U/ L, ^+ P+ t8 a
<%
3 g' W4 }+ F- F+ ~( Q6 `* [
}
) k5 Y2 R/ @/ p1 _6 i6 t
%>
) H! g0 O; F3 \" b" q
</select>
3 M @1 y% A8 j0 h
</td>
: ~ \) m" e5 G
<td>
6 T9 X m' L) i& P
<select multiple id=city style="width:150;height:200" class="bgc">
) `! t& P7 [4 H" G6 |- n, P
</select>
. h! B1 {) [( |, l# o
</td>
N: }) ?' \; o3 e @
<td nowrap align="center" class="bgc">
5 D7 F/ G9 Z6 D# F
<input type="button" value="<<" class="buttons">
% O+ R- H! o9 j8 d' G# b, R7 c
<input type="button" value=">>" class="buttons">
' r5 a5 l$ N# _3 I% a' O2 f
</td>
7 U. v" ~" {4 H2 ]1 X$ f* z
<td>
! Q$ L* T8 h1 r5 u
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
; q, c, Z$ J+ S: ~; A( L
</select>
; b, A: @) Z" b7 L# y1 y
</td>
8 H( U" v- g) W, I/ m4 e
</tr>
# e6 i" W. W8 P) `8 B! j8 O- [
<tr class="bgc">
a8 t ~2 [. d) T v
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
( u/ N7 ^1 C6 m( J
</tr>
% @& Y e2 T9 B% ~! G' R0 E
</table>
0 {! F8 y) g; ]3 G; J7 \6 R
</form>
- K, B. e6 I8 c2 p$ l( v; s, V
<script language="javascript">
8 r# i! a- C# p
//人名移动
& U; w9 m+ R$ ?: b& S
function move(fbox, tbox) {
& N; U; r; S, [+ p1 ]
var arrfbox = new array();
( r5 f" T- }6 H' B
var arrtbox = new array();
; E" h! a: @' _" ^) q$ i
var arrlookup = new array();
3 U# N3 \+ L9 Q. d1 s
var i;
" B; E" D6 j. o! h! f, {2 \ i" t
for (i = 0; i < tbox.options.length; i++) {
7 g V# J) @$ x$ `1 {% V2 S6 i
arrlookup[tbox.options
.text] = tbox.options
.value;
9 v5 F: J% E, a
arrtbox
= tbox.options
.text;
( w* @3 r* A+ u7 s/ y# x
}
9 L& z! O+ q6 W' e
var flength = 0;
, B0 `; O! n. W& T0 M
var tlength = arrtbox.length;
- a9 D; u ~) R8 O! s( k( M- Z
for(i = 0; i < fbox.options.length; i++) {
0 L0 G) q I& d
arrlookup[fbox.options
.text] = fbox.options
.value;
. l2 N9 B+ Y$ t# N `6 C
if (fbox.options
.selected && fbox.options
.value != "") {
6 h6 M8 k, H1 M+ W2 \& q
arrtbox[tlength] = fbox.options
.text;
- j5 W2 _/ T7 \$ q
tlength++;
; Z; X0 { }6 H m
}
9 C# Z: x Y8 \( @
else {
" p. M: b3 z9 a' W* W- Z
arrfbox[flength] = fbox.options
.text;
% t' Z9 Y! e% d+ ^. Z) i/ p0 y
flength++;
+ R- [+ L; \7 d9 G8 X
}
$ U/ {; o' e$ B% b3 J# b ]7 j
}
8 Z$ }- i9 [1 U
arrfbox.sort();
3 o5 `& `" f. _7 G; N( F
arrtbox.sort();
& l' L/ o/ d7 ^" ]. j& e! w6 H
( M* N# e- q/ c+ c
fbox.length = 0;
5 M6 U1 l S& {" D' Z1 M& H& \
tbox.length = 0;
n X2 z, s& W& H' T+ k8 K5 M
var c;
9 z8 w4 U) h( e5 T
for(c = 0; c < arrfbox.length; c++) {
) }/ e) D' h( t6 e; m
var no = new option();
3 ^( y5 Y( B5 s& o) D
no.value = arrlookup[arrfbox[c]];
/ l- X" \' j* Y4 j5 O
no.text = arrfbox[c];
) F1 U+ a( B) \) C _0 o. Q; c
fbox[c] = no;
! O( j! v4 r' o' n
}
( u# ]2 w; n) j6 ?2 {8 ?' `( C
for(c = 0; c < arrtbox.length; c++) {
( U( B4 \$ Z: U, t
var no = new option();
% @1 k, g M* j% w7 a0 ]/ }
no.value = arrlookup[arrtbox[c]];
2 Q/ E2 ?+ x q# z& d! G
no.text = arrtbox[c];
, b! Y# }/ ]$ J0 e
tbox[c] = no;
& I0 t( G1 z+ B9 G8 Y
}
2 J% g: Z8 m- D! j7 E" Z
}
" j4 g' d) J0 p0 @* {6 H- P4 T7 Q
</script>
. T; J9 V- g7 b& m* H
</body>
3 q8 P: N4 L4 \, D B
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2