标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
. m# w. L% @( \6 c# R
c pageencoding="gb2312"
+ O7 y* \& o6 g& I
%>
, n1 I$ d; `$ T1 j+ @
<style>
& b' W: `6 C1 o' Y& H
.f9{ font-size:9pt; }
) m7 V% U8 _: r8 C& l7 |5 I
.bgc{ background-color:#aecaf9; color: #0033ff }
% ~7 y& E1 u* N& V+ e7 f
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
% ?2 }8 X, z* r- h4 J
border-bottom: solid 1px #4e7dc1;
3 w6 v/ ]5 c/ E' f1 X' F* R
border-left: solid 1px #aecaf9;
) r5 F5 v( W2 |* E4 w' [# z
border-right: solid 1px #5679bd;
2 P, ?6 f3 w) H4 l) I0 m A
padding:1px;
6 J/ H! W( D B, D
margin:0px;}
! x3 e& i& f4 ]- Y
</style>
" R6 ]7 @) y4 \- @. x) Y
<script language="javascript">
2 k9 c1 e; b$ D& u# ~
<!--
9 M" f" ] H/ M; c: d
function rv()
2 j5 N8 T- U. q ?6 g: E1 }
{
2 I5 W0 i# D7 H, z
var val="";
( I2 q; a4 V8 j" D/ B8 }
for(i=0;i<combo_box.list2.length;i++){
4 M3 O) }; O4 R* {3 |
val+=","+combo_box.list2
.value;
: n2 \; T& g2 L$ C
}
# P Q, @+ V5 n
if(val.charat(0)==","){
/ u7 L* H& H9 }" p
val=val.substr(1,val.length);
2 Z% v! ~5 ^6 q+ w/ A+ i
}
1 |2 J4 w! T x" t. [
opener.form1.frecname.value=val;
7 n! Z1 X8 Z' x# K
self.close();
7 z% k7 g( A: o* J; W
}
) L& q3 r( p9 x: W- R. }
//-->
9 b0 N+ m& l# ]0 r3 g8 U4 b
</script>
% a& V( M# v; T5 }9 z. K( G
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
) ~) U: H5 f& E2 z) y
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
( _* V7 \, B, P5 y4 F$ V$ q
<%
* s9 Z3 _# C' Z3 v5 y; U& |; q
cdatasource ds=new cdatasource(); //数据联结bean实例
8 F8 y# i7 K" M/ }, d5 L
java.sql.connection conn=ds.getconnection();
$ l% h/ i& ]* l# C+ F
java.sql.statement stmt=null;
* x2 ]' c7 ]7 ]7 B! V; ~
java.sql.resultset rs=null;
, A n' ]/ s4 n7 e. s
cdatacheck dc=new cdatacheck();
- K7 e1 I) w5 T
%>
/ D2 A3 G0 V5 e4 \$ q
<%
( R/ o, M) x+ D/ n) r" n/ b
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";
. e! C& u0 n+ b8 I
stmt=conn.createstatement();
1 e3 _% C. U h l4 e
rs=stmt.executequery(sqlu);
% ]4 F Z3 K, l- M3 O6 t
%>
4 i! L7 b, y+ z' h
<script language='javascript'>
7 U$ h0 e6 `& Z7 T2 ]3 _
arr = new array();
; E9 }. C! f8 n7 r+ o. H
<% int temp=0;
2 Q% N4 `8 w4 h0 f6 N2 D
while(rs.next())
3 Y$ C. _% L0 K
{
/ { i. r+ l4 f. g" ?
%>
1 S4 w) J$ r1 k) z. ~$ O
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
2 x P# l. L9 z! D. ]1 t2 I
<%
. D8 ]6 H* s* B( D3 T h
temp = temp + 1;
6 o. {. W- h. U& D% [, W+ j
}
# h7 `; m+ L# q7 i* k. W
%>
& R7 `* G( r+ R- i
temp=<%=temp%>;
) p7 z1 F( A& b! N' B
function changelocation(id){
' X% n* W) d& u5 C$ X" L
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
! H y3 B$ S Q- k @+ O) B
var i = 0;
" C2 Y0 Y! z$ P1 I
document.combo_box.city.options[0]=new option('-------','');
7 h! p3 V+ a9 t8 O: L% X& U0 F
for(i=0;i<temp;i++){
/ e& ?4 W: ? \5 }" h0 Q: }' `
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
* g! t' \& O' E( t/ i% l# k
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
. K4 H; C3 c c. A) S, Y) U
}
7 E( m4 P8 M' w* C& x
}
. _5 Y% G) k6 q% j( }* M
}
! B- S7 T5 o' r5 W. B) {/ T* Q( ^
</script>
8 }$ R5 g0 S. x1 e2 {( |! T
. ?1 x4 h% Z7 d9 H1 a Q( h
<form name="combo_box">
: M0 j' d) {. Q
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
! t0 q+ D# B3 `
<tr height="24">
5 W, Q' g9 y) T
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
& K0 }6 T+ p+ O1 \4 v0 I8 [1 }
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
0 P* S2 K3 D p' I8 _6 @# y
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
6 G7 C, P3 P8 B3 k3 \$ D
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
7 u' W0 r6 I! Q' Q, x
</tr>
* n8 G; Z% J+ G
<tr>
" k/ G9 ^$ |$ _5 B# ~. ~6 J) ?
<td>
3 L% d' q( W8 T- v$ N
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
6 P# @+ v) m p& `6 A1 t0 H. V
<option value="0">请选择部门 ---></option>
% o r6 x' R9 ~6 h, f ?, r
<%
+ u/ a; _- F3 j1 J
string sqld="select * from tdept";
% ~) @% C# l. K
stmt=conn.createstatement();
& g' {$ p# |, Q9 t6 w
rs=stmt.executequery(sqld);
9 |2 Y1 X2 I( |0 n2 C' j# ^; G) R( I' |
while(rs.next())
# V* ~$ ]3 c9 ~- q% x7 u
{
. e8 J, {2 b/ s) |3 C
%>
0 p" ?* G7 ?- n/ f+ c
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
7 f8 T( F% @% _9 r+ ?9 f, M
<%
) }. M, G$ K" E' |) j( N
}
% |" O, F! _3 z3 Y* \2 [3 F1 Y
%>
% n: m7 Q- D+ Q4 w0 N: d
</select>
% K( V, r% }7 M- |" d
</td>
0 n% K8 g6 _' c# }. _, Z
<td>
6 D% ^( d' f! e. A5 u- m, _0 M9 h
<select multiple id=city style="width:150;height:200" class="bgc">
U' X X5 G3 w% N
</select>
3 s: t( [; S/ H3 t5 q
</td>
$ l* h7 m9 B$ H% U! ?6 U0 u
<td nowrap align="center" class="bgc">
$ g" U' A* r1 f, P o( s) t' ]
<input type="button" value="<<" class="buttons">
. Y v, C; C3 @& k3 u! S% q
<input type="button" value=">>" class="buttons">
U. k! s3 b+ j. Q# N4 K0 \
</td>
- x! R" ~1 B' _9 t R
<td>
0 e9 G% C" T8 D' `1 o6 i
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
7 |2 v0 r. V1 g# @
</select>
/ a! f+ D( E6 s" U6 ?
</td>
+ N. N, N" Y+ L: S
</tr>
5 Y* v! g# T1 w' {9 @' g& z4 X
<tr class="bgc">
2 i- F6 x0 H n; }. J
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
; c2 }5 J0 E/ s$ N2 f. e( ?
</tr>
% y& U6 N% W, s- o# B) d
</table>
, p& C* t8 P; X2 Z5 r% w( q' g. Y1 }
</form>
! ]) s; l9 W1 Z2 H g
<script language="javascript">
" C4 g. }; i/ D5 ?, x. I
//人名移动
6 @! q5 q8 `& `0 I3 N9 p" o# S
function move(fbox, tbox) {
3 q# V4 u( m: x/ J# k# F6 I
var arrfbox = new array();
" E" P$ v _3 z0 g# R
var arrtbox = new array();
8 ?2 \$ u0 C8 W9 v, i+ a
var arrlookup = new array();
( P* ?8 k9 c9 y9 H+ H4 a
var i;
- g+ Y7 z& S8 d, p* I
for (i = 0; i < tbox.options.length; i++) {
4 {3 L. d/ H$ E* X. O( d7 q0 A
arrlookup[tbox.options
.text] = tbox.options
.value;
- ~* @0 x Z7 j; Z
arrtbox
= tbox.options
.text;
/ a* W: R4 l+ a& v
}
0 ^: Q( ~( t9 Z# p
var flength = 0;
9 ^# @% ?8 O9 F$ T7 @" @
var tlength = arrtbox.length;
$ K- t( U! k0 H. P+ |' I5 D
for(i = 0; i < fbox.options.length; i++) {
2 L+ M3 n- y% d
arrlookup[fbox.options
.text] = fbox.options
.value;
! r5 u& N5 `. n. S7 }
if (fbox.options
.selected && fbox.options
.value != "") {
" |- X G) i" o2 d( V+ u' ~
arrtbox[tlength] = fbox.options
.text;
& ?" e. _. t1 ?. f
tlength++;
8 n; G. C+ w' U5 T4 m+ q$ G% O) G
}
: }# }" \+ |' D5 h8 \1 E5 V
else {
) T P7 |0 F0 x& T
arrfbox[flength] = fbox.options
.text;
; X% K1 r) |9 f: D
flength++;
! C9 _* O, Y! \6 @4 U
}
; |) u! N( n' _
}
! ?8 Z" b. G$ o* s0 r
arrfbox.sort();
3 L8 A, e6 V/ }% T. d- X
arrtbox.sort();
X- b9 y8 O3 S/ G, Q
7 X' x" A: u3 e5 g
fbox.length = 0;
5 l1 Q( ~& o- w+ V! [* M3 Q1 z
tbox.length = 0;
# H# g# L. J& @1 t* A
var c;
* j! |! t) l' @9 x: U4 P4 ^
for(c = 0; c < arrfbox.length; c++) {
( X+ t1 |2 P4 m, o3 w
var no = new option();
, Q0 s L1 J4 s9 [- _/ ?
no.value = arrlookup[arrfbox[c]];
3 e; |0 V7 e# |
no.text = arrfbox[c];
( a, K% u, }2 s0 B& j
fbox[c] = no;
6 p. j- k/ z1 e8 `3 d# N9 x( D
}
* w0 L; C4 `& e5 R
for(c = 0; c < arrtbox.length; c++) {
9 ^5 P* D+ n" s1 S
var no = new option();
5 ^: p7 i, a. y j5 G- E, f) R
no.value = arrlookup[arrtbox[c]];
* K2 T4 k2 J! o7 k1 r, e; [8 _
no.text = arrtbox[c];
& _/ K2 p, ?7 _3 n5 t! S, v" ^
tbox[c] = no;
1 x V* E0 ]3 { u. c. W
}
0 k; L% _) _3 e; A3 H
}
/ I1 [- L0 m- `! G% l) B
</script>
7 Q0 v$ |+ i i6 q% `* F/ v) f- Y
</body>
8 O$ r2 I. i; x$ \4 j! X
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2