标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
6 {+ l$ q0 y6 G m' Q! y# h4 W! B
c pageencoding="gb2312"
4 _& M- }9 C) x$ `6 M
%>
9 t" Q9 `* |2 b! M; I
<style>
/ g6 L! q9 ^" L$ [! F
.f9{ font-size:9pt; }
& }, U3 ?' K/ o' {5 |- f
.bgc{ background-color:#aecaf9; color: #0033ff }
+ k4 A# c/ z/ M, O4 ~: _
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
% f" ~8 U% M9 \- D4 c
border-bottom: solid 1px #4e7dc1;
$ U- w2 r s9 b. @8 L' C' I
border-left: solid 1px #aecaf9;
: [1 A/ L" U9 V
border-right: solid 1px #5679bd;
8 b3 d2 G: M5 X. i
padding:1px;
( J! m2 D( Q" n: J1 s A* I
margin:0px;}
* f1 @ Q: Q; n8 Z/ @+ h
</style>
0 ^3 [1 {2 U0 {6 T' d
<script language="javascript">
% q( u- t% W& a3 b
<!--
) n" `( ?- w- e
function rv()
( y- u2 Q4 T" Q5 l% ?5 F: ~
{
* ?; L% K1 }1 ~& p3 B/ H8 t" O u/ @2 J
var val="";
$ A# o' k- z9 W( x. N( t5 y7 W
for(i=0;i<combo_box.list2.length;i++){
; E2 f( F9 h# l" a* ? C' A
val+=","+combo_box.list2
.value;
5 z$ s; y! Z5 M% k3 s/ Z
}
$ I- x! |* I4 d: a$ c8 ?
if(val.charat(0)==","){
' Y& y: @ w: |0 ]) g3 n' V
val=val.substr(1,val.length);
% E% e7 g( X5 ?
}
8 t* Z! q' ]; h9 |
opener.form1.frecname.value=val;
+ t, u, P5 F4 p% Y7 L
self.close();
/ q. G# _" B6 s! ?5 m- \
}
/ {, h% o+ ^. }, c9 E! k
//-->
7 A( P9 v( L; z, X* I* b$ a6 x: G
</script>
5 L ~3 |/ b1 S/ T7 |; g
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
0 q* d7 h Z* _
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
: A+ r& l& Y- K6 M! r" Y$ }
<%
% U/ ]& O9 b4 ?* ]! g3 {+ W5 E: n7 @
cdatasource ds=new cdatasource(); //数据联结bean实例
F* S( `7 Y M: i+ C& Z; k
java.sql.connection conn=ds.getconnection();
Y0 n1 D% O! r9 p' p
java.sql.statement stmt=null;
" v$ K' E6 N4 [. ^( o i( m
java.sql.resultset rs=null;
8 t' M1 I: O+ E& g
cdatacheck dc=new cdatacheck();
0 X- `( g9 s0 e" h9 r
%>
) ]* V$ n' e m- b9 d L
<%
3 ]$ H1 j- ?' k% P$ f% \% I* n
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";
" ]& S$ N& O; k! {
stmt=conn.createstatement();
. z5 y* O7 g/ F
rs=stmt.executequery(sqlu);
, R/ B v2 g3 y$ e# j9 s2 |- b; K
%>
, H/ u3 G/ J: m! j0 k' W7 [0 o
<script language='javascript'>
- z2 R" s2 y* j/ E! `
arr = new array();
5 _% `7 T* k4 P# l0 A. R: W
<% int temp=0;
- n+ ^7 d( J0 @" U
while(rs.next())
9 K9 G0 D+ \1 E9 ]/ L/ C
{
2 S: `, S& @: p `2 U( _& t
%>
! _5 U$ Z) I/ ?# [
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
( R9 }" y' [+ v) f' K3 @ S5 q
<%
' D \; _. U& ^* ^
temp = temp + 1;
) p9 K6 E, l9 K2 x, v7 F: f
}
& T* `$ ]. I0 X9 [: H& Z% l5 h5 `4 r. ~
%>
. j$ ?! c5 S8 F& p: P
temp=<%=temp%>;
1 B6 n& x- c+ \6 k: b v
function changelocation(id){
" o1 i. u+ p1 s/ x Y
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
% P* U' z% a! c1 c+ O3 n% g5 n( {
var i = 0;
; r' t) `$ `; ^
document.combo_box.city.options[0]=new option('-------','');
6 N. f- J, Z- h7 c8 E' z5 r' C( L# y
for(i=0;i<temp;i++){
0 ^, t# ~1 M/ w* B5 \8 c; a3 P
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
0 w5 b, e8 W; i0 _4 h9 k9 y D
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
2 L4 c7 R' B' L8 E9 D' C
}
2 M& X8 l. Q' O# d- y9 |% v
}
$ z9 V( W. e0 s
}
. q* p1 w- y" s7 L+ S) P! U
</script>
$ K% {* `- Q( `. D
9 F$ l% B# C; A1 n1 l
<form name="combo_box">
8 Y8 N- R1 Z6 n1 Z5 Q( w
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
8 Q/ k) r9 S/ j+ K: u
<tr height="24">
; O' ^7 \7 e" \7 M
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
+ {( g; K1 {/ [ R) l
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
4 v- Z; h0 Q3 o
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
; I K. Z$ f( p
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
2 t8 k; Z# _! T- z! I7 r# |
</tr>
- l D0 i3 e) Y5 \
<tr>
0 r2 ]7 M% S* r$ n/ s4 x
<td>
; g: t' j) f$ j4 M. t
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
: S6 v5 w9 m' S
<option value="0">请选择部门 ---></option>
. P$ ?/ J9 L L+ }* w1 @
<%
% R5 Q# H6 y; q- S) n# B
string sqld="select * from tdept";
$ |+ [0 s W( V+ {
stmt=conn.createstatement();
( V& L( b' y* D# O" k
rs=stmt.executequery(sqld);
3 [) Q) q% K: W8 K4 }
while(rs.next())
# j) {" Y- e0 R$ x. o* i
{
! p' F, u/ Y4 S2 F3 G$ A0 g; z
%>
; ?9 ]" p; `* U: s
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
% p$ l+ \/ i* I# R7 Q* B, t
<%
! D! N& h3 |2 x8 P4 P7 `
}
6 P8 T1 ], \8 Q% Z, E' ?; z
%>
: M# H1 h& }6 f w5 u) e {' A, F
</select>
8 S6 ~% m' v$ y( Z1 H; ]( ~
</td>
5 y* N0 U2 Y# W$ b. R
<td>
4 J# j2 C2 c$ T, E: W
<select multiple id=city style="width:150;height:200" class="bgc">
( J3 _! X5 S8 I* M3 ~) H) m0 o
</select>
/ J0 V- n$ E) i7 o( ?4 h8 R, O
</td>
/ W9 H. D9 x; Z$ j* b; @
<td nowrap align="center" class="bgc">
% |! F4 O9 I% H! e% P# S: {+ w
<input type="button" value="<<" class="buttons">
& o) g' _& N- N8 }
<input type="button" value=">>" class="buttons">
) A; G# |$ t8 f
</td>
& a/ G6 w% u1 e3 v( L& f- C
<td>
- H) B& U* B8 v4 B9 ?
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
5 G: b- x& _) z0 m- d9 P% a
</select>
0 J3 L( f% K, I5 _
</td>
. j/ v. q% T. V2 R
</tr>
5 f8 J6 c5 S# t$ m2 ^# e0 ^
<tr class="bgc">
. L1 F O! N5 N" S: y
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
9 R! T8 y, S% p5 e9 V$ Y
</tr>
& B$ K9 G! I1 E W+ P
</table>
/ I( v9 U! L/ g& u
</form>
: g: @% u3 b( {3 f, C2 f% c x
<script language="javascript">
/ b1 F, Z4 Q3 N1 ] ^5 ?
//人名移动
6 f% T: l/ ~% a
function move(fbox, tbox) {
: a0 H( p/ Q0 M, J F% W
var arrfbox = new array();
' G# S1 C4 {" O( g
var arrtbox = new array();
, k& b" G5 e# y5 r
var arrlookup = new array();
$ A% `; a( L" m$ G
var i;
& z; s' C: g! @4 B. n4 Z5 U
for (i = 0; i < tbox.options.length; i++) {
' k" k9 W b! v+ S
arrlookup[tbox.options
.text] = tbox.options
.value;
4 x- _; x0 l% `+ ^4 ` j: X
arrtbox
= tbox.options
.text;
" I; M) T4 V, G; C4 W9 {
}
- |9 x2 X) l) A1 u
var flength = 0;
4 j/ T5 p9 Y3 [ N- W: |, L
var tlength = arrtbox.length;
f9 n, s2 Y4 B% B
for(i = 0; i < fbox.options.length; i++) {
) T; N) q/ c ~0 k! F3 l
arrlookup[fbox.options
.text] = fbox.options
.value;
* }2 N) X y, r% d9 M) b
if (fbox.options
.selected && fbox.options
.value != "") {
7 r" J0 p# q7 ]4 y; w* `$ A. T5 I
arrtbox[tlength] = fbox.options
.text;
( f1 N# V1 C4 Z$ \7 k" j/ F; O
tlength++;
' k) F9 r, h5 X; ~" N
}
; \! ^, T& ]6 W5 t; b# K+ E# _
else {
# ~' z1 Y$ ^$ D
arrfbox[flength] = fbox.options
.text;
* w3 Y7 M' h* i+ a$ u8 e2 y
flength++;
" V( Z6 t7 v% W9 c0 P- i: D1 x
}
6 `% f. D7 ]/ @% u9 u. j+ g
}
- p, }4 J# e' n. |0 B$ q
arrfbox.sort();
3 T" @5 M: f/ ]# E
arrtbox.sort();
1 O/ K1 W4 s- I. W( h* H- ?) c
, X ~, _9 O( a W% Z
fbox.length = 0;
* a! V1 w9 D+ n/ h9 ?% T% G
tbox.length = 0;
$ _3 K! b9 a9 T2 `0 P
var c;
/ D% h3 D, _ Z
for(c = 0; c < arrfbox.length; c++) {
1 w8 ^& _8 w. O- J9 R
var no = new option();
% m/ T# l& r& v8 V
no.value = arrlookup[arrfbox[c]];
7 O U$ ` _/ S: b% E5 U- G4 M! W
no.text = arrfbox[c];
- [, |: _2 R3 U' U6 u U" \
fbox[c] = no;
. @" k/ Z4 B: K
}
9 m R- e0 E- I/ k6 r$ R5 l
for(c = 0; c < arrtbox.length; c++) {
( ]6 \8 i2 B1 y! {. F% [
var no = new option();
}5 |- Z, C$ }, Y9 X" h, M3 K6 Z
no.value = arrlookup[arrtbox[c]];
- E. ?. d1 ~% t6 H2 m( h
no.text = arrtbox[c];
! o- X P) X" L- r
tbox[c] = no;
9 n$ G5 J6 Q. P# y1 o
}
$ l. W0 C; N6 U' Z/ Y
}
; M2 B" _0 F/ A5 x1 D3 O, S+ d
</script>
5 I8 i4 p1 K$ {. \1 D: V
</body>
* {! i0 O0 u2 }
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2