标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
: M' N& W1 A5 ~( b: N e
c pageencoding="gb2312"
$ d+ b0 W' B* q/ E5 J
%>
* {& P/ ?$ ~& G
<style>
5 C$ d, k/ Q% W+ n5 J0 ?* Q8 t
.f9{ font-size:9pt; }
6 K3 ?, ~; R) w M# Y0 B
.bgc{ background-color:#aecaf9; color: #0033ff }
9 N2 \- c! M4 K( q9 _, |
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
, ]- D# [# I' }: ~6 T& r
border-bottom: solid 1px #4e7dc1;
+ ?+ A) s# h9 K+ v
border-left: solid 1px #aecaf9;
+ V) i. n. T, J
border-right: solid 1px #5679bd;
" j5 z& q2 o8 ^0 V5 o. v* U
padding:1px;
6 D7 i' J, O8 u
margin:0px;}
" s* n& l! i' O6 S% ~( C% f5 D
</style>
* [! h9 Y q( _5 L$ t3 k& m
<script language="javascript">
7 E. |! e0 u3 ~, a( ]2 {2 x- x
<!--
( D( b+ D# j: K' X- T
function rv()
1 n" u. P. E5 [" ?, T
{
1 J: o3 \$ T1 a. v9 q$ x. z
var val="";
/ J* G$ x i# v; Y" N R; M
for(i=0;i<combo_box.list2.length;i++){
, }" B% Z2 x& p! T( i$ y
val+=","+combo_box.list2
.value;
( k% B: k2 `# q: Y
}
: x% M, l% w' t9 ]; \) t5 G- u$ i
if(val.charat(0)==","){
. r% T! }7 c" {* @: [
val=val.substr(1,val.length);
# _- s" ]' P) W, m4 u3 C
}
- Y9 L8 F# q2 W6 {
opener.form1.frecname.value=val;
9 L( S, D1 D9 H7 o
self.close();
) N( x; h6 M( A6 h1 l. D; v3 W$ E
}
+ X# d! ?3 c1 R8 `) g5 Q( L
//-->
/ m% Z; h6 K& D! f' z: @
</script>
r% p' L* g# A! k$ I
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
4 l8 S. e+ r9 ^; U8 l8 Z2 j. ?7 m
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
3 T. S& E) l; p; O9 I9 L
<%
$ y$ r' z2 \* f" S" f
cdatasource ds=new cdatasource(); //数据联结bean实例
2 E+ [ F2 L0 i; h
java.sql.connection conn=ds.getconnection();
E' X9 R5 D9 D' o! M
java.sql.statement stmt=null;
' V) _6 G, `& B, }7 F+ p0 r
java.sql.resultset rs=null;
4 [, `6 K$ @! f2 ^/ a3 ]; D1 J
cdatacheck dc=new cdatacheck();
8 E7 y( \$ b( N" S( F& ?: o# y g$ y
%>
! ?' {, A, K1 X+ s5 d% }( ^
<%
2 S U) C9 ~# B: W1 P4 Z" j- ?
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 F+ e1 u5 e z, P
stmt=conn.createstatement();
) Q( B5 a% x, {
rs=stmt.executequery(sqlu);
4 l. s6 a1 D: M
%>
6 S8 F0 r9 v( ?1 ~* x. s
<script language='javascript'>
: S+ H( F m7 w" w$ z3 q/ Y" x
arr = new array();
$ U) j) P3 p2 K5 Y. m1 l+ ?, C( s4 {
<% int temp=0;
! L4 r6 T4 b4 t9 v: k5 x- t* x' [
while(rs.next())
" x5 A0 a( h: h# v/ I
{
9 o* e- h+ @/ E8 i- ]9 X
%>
* c' L# ^% H4 R6 H
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
# s# F5 t1 w8 g0 f. q: Q
<%
# [- o ^! \+ w$ y5 a& ~7 f
temp = temp + 1;
! P4 m8 B- T4 R. O
}
# S. D8 d0 `0 N- x9 C% n
%>
/ A* J$ d! i, {9 v" o! ^( a
temp=<%=temp%>;
* L! v9 n( P0 t: S7 n$ G+ D5 r1 c
function changelocation(id){
0 [9 F) W+ f5 }% ?/ C3 _
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
! W; Y6 T# e& X# b3 b" Q( F; Q
var i = 0;
9 U: W' h9 Z4 e1 B
document.combo_box.city.options[0]=new option('-------','');
8 N; k0 V! f) L4 v3 ]8 e$ w5 O
for(i=0;i<temp;i++){
9 _0 ^1 N5 y' a) ~
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
+ o3 O/ R+ n5 n, l) F7 G
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
8 d Y. \( Q+ f, q; F
}
/ ^0 Q& A3 o2 _' `! P6 |# r I) h
}
9 X4 O) n" w2 _0 Q
}
8 V/ M# G4 k [
</script>
2 y: C% f1 F: I7 @
/ b- ~8 l! A+ g. ~, ~
<form name="combo_box">
: L, b7 I; g) j/ Q( F4 y
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
" t# ?$ a5 w: |- L) _' P! b
<tr height="24">
3 [2 X" e, L. k' N1 b$ ~
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
% [5 g: i0 ^3 G, W E- x7 q
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
: S$ d# h" c: Q ^8 j$ A0 H
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
" Q/ J' V6 Y) S
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
7 A% x* D* u, r1 S7 H% _1 S) T
</tr>
0 n! q1 A% y6 @9 g( d
<tr>
o- y! M- o# R0 ~; Q% P6 \
<td>
1 {& B! U3 N+ {9 ]7 M( r/ ~5 i: L
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
; D5 {2 {+ m8 ^
<option value="0">请选择部门 ---></option>
) I1 Y# W# n0 o0 C& v2 ]9 r, X
<%
7 v# P3 R0 V2 G+ L
string sqld="select * from tdept";
4 c0 L( [0 i& D5 y2 P& ^
stmt=conn.createstatement();
$ f2 R7 X) _6 P! o
rs=stmt.executequery(sqld);
) A, k- E9 q" J$ m8 v) r
while(rs.next())
8 n: ?8 k8 C& h' w
{
+ H" r5 r7 @1 F" n6 }
%>
) b g- v( m0 | x9 Y" E8 B: ]4 U
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
$ N2 n {8 W; b) r9 L
<%
- M+ s5 A! ]5 N/ R+ E% {
}
- b1 Y, Z( p3 l, H6 k
%>
" Y% u6 H$ L3 w( |- J
</select>
3 O( R2 J% t1 S6 o( w
</td>
5 A7 ^% c4 k1 T
<td>
$ Y2 `/ e2 f( e2 F6 Q
<select multiple id=city style="width:150;height:200" class="bgc">
1 H+ A/ g3 o9 F7 C8 t
</select>
( ?! G a2 F: I8 l9 h
</td>
. K; k7 F3 ]3 g7 C. d
<td nowrap align="center" class="bgc">
- M# \" B/ p$ k3 _
<input type="button" value="<<" class="buttons">
9 ]7 y, P5 d0 i' Q; ?6 d* M5 z
<input type="button" value=">>" class="buttons">
- [ E2 r6 j$ K% `6 \. m! S5 h
</td>
0 d; v9 E, d4 i: \! j
<td>
4 l" L0 G ]# ]( \8 g8 z
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
* ~; f1 _4 C2 S* P' N L4 I q$ U
</select>
- T; n' R) C4 B! s: N
</td>
; \& f6 B2 E2 |" ]
</tr>
8 p1 X* l3 F: m! E: \: n( ?# c
<tr class="bgc">
; @! w" u% d( m6 m* B" o3 g; ?7 e5 h
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
: R! H* N& f# G$ Y7 M
</tr>
2 ]( S2 A% p+ P3 g. v) B% c5 j
</table>
' X }: c: Q- z& k2 m+ }* z P/ w
</form>
) E3 B7 N9 u+ @3 [
<script language="javascript">
7 N% ^3 B3 \. o
//人名移动
/ u! K* }2 o2 ~: b
function move(fbox, tbox) {
- f7 x8 |" |1 a9 W
var arrfbox = new array();
: m: h7 M& M) [ b8 }6 {
var arrtbox = new array();
( R+ W Q5 I% E# H
var arrlookup = new array();
0 u. ^6 s% x! F% a
var i;
5 }. _! B! H& X8 {. v: b7 a
for (i = 0; i < tbox.options.length; i++) {
( j3 y+ v* D" |% J+ O
arrlookup[tbox.options
.text] = tbox.options
.value;
! m4 p& |0 y8 x0 V' T
arrtbox
= tbox.options
.text;
! Z- S/ ~& S% u- p0 p
}
! H1 u6 Q6 F9 X5 T
var flength = 0;
8 T. f( T' i$ V* z+ W: \
var tlength = arrtbox.length;
; P6 t# Y' l- b" S
for(i = 0; i < fbox.options.length; i++) {
4 [; `) }+ p- t1 G0 I
arrlookup[fbox.options
.text] = fbox.options
.value;
& Z( `/ X; M6 w: a s
if (fbox.options
.selected && fbox.options
.value != "") {
, S1 v& L+ P9 Z6 Y! h
arrtbox[tlength] = fbox.options
.text;
' e4 l" z6 @$ A' x3 E
tlength++;
! f9 R g3 b5 d$ z7 ^( U4 n
}
$ z+ Z. @' M3 a, T
else {
! R k4 P; f, X9 a" a6 j$ d( l
arrfbox[flength] = fbox.options
.text;
, o2 f4 m6 w" d
flength++;
& S0 {7 {$ @0 R' j" r. c6 p
}
$ Y+ T& e+ a/ i
}
; l4 i2 \+ K" X2 |
arrfbox.sort();
e% o2 }% ~- O2 F4 [2 o
arrtbox.sort();
' M% d4 y2 \) e0 y: ?
3 k2 J$ {! e- y0 x
fbox.length = 0;
+ \+ a+ C% w, |$ r* B& f
tbox.length = 0;
0 K" w3 M/ e* g" [7 i9 W5 g# M+ O' S
var c;
8 Y2 P2 l. p! _
for(c = 0; c < arrfbox.length; c++) {
; ?/ G$ v' b; f6 `2 b% X5 { p
var no = new option();
6 ^; i+ Q! U! P; a2 P! w. L: a
no.value = arrlookup[arrfbox[c]];
: |9 |4 u$ ]* u- j V1 u8 P: `
no.text = arrfbox[c];
! _5 ` o' U7 M- X/ o' J
fbox[c] = no;
# A: x8 t" h( s
}
- l( v4 R4 r4 |- K8 I1 G. W
for(c = 0; c < arrtbox.length; c++) {
" ?. j# a9 T( O2 N+ A# u
var no = new option();
9 l1 ?, {' K4 S+ h
no.value = arrlookup[arrtbox[c]];
1 v" J7 ]( Q+ O, T- R& x, \/ c
no.text = arrtbox[c];
# i' N$ p+ ^/ e# t
tbox[c] = no;
! O; |& h7 `4 z( R9 i4 L% v8 a
}
! ~6 T7 _$ d& S5 q: f8 |3 `; h9 H
}
; ~. g8 d# f5 @
</script>
! P1 K9 Y) c! s& E3 r
</body>
% ]% |- s' L" W9 Y, k N
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2