标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
; d! z1 N7 D" m; \9 C
c pageencoding="gb2312"
: N* U, X+ a8 e& X
%>
) m# @* l/ ?0 A( p5 P6 l3 T
<style>
* O9 W. k8 y1 d4 N. V
.f9{ font-size:9pt; }
- U4 K# z% B" r4 ~
.bgc{ background-color:#aecaf9; color: #0033ff }
" T& x. w1 T! |8 [1 i& `: l& B
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
$ A* d2 O% `/ _% Y! U8 d6 h& {
border-bottom: solid 1px #4e7dc1;
) ], e$ k' n' }5 R ]0 S4 n6 }& ^! B$ `, g
border-left: solid 1px #aecaf9;
/ o; L& `) r0 c
border-right: solid 1px #5679bd;
1 J2 u B/ h: c" {8 F
padding:1px;
) P1 @0 a6 n, c5 B( Z4 V' g
margin:0px;}
: s9 v. B2 \# \4 D, M6 W6 m% \
</style>
' c8 e, Z: U$ H i1 F5 t
<script language="javascript">
2 h. ?# C( K& [. i
<!--
8 r5 A) ^/ V* o, e) L' k7 J0 b% z
function rv()
O+ B+ O6 ]) V. Y- P( y
{
, v8 j/ B* I0 b S" z
var val="";
. R1 m0 S1 S$ m8 v2 X- V9 E1 s
for(i=0;i<combo_box.list2.length;i++){
% y: N5 O$ _' g7 I% D1 U" V, o
val+=","+combo_box.list2
.value;
8 \9 T3 u1 m! A
}
. c( j$ N& e8 y7 C, o+ O2 |5 h1 N1 E
if(val.charat(0)==","){
* T$ R5 C, X$ o9 |+ K# s7 R6 f
val=val.substr(1,val.length);
6 l+ ^7 o- T" F- ?- X3 ]
}
' i- ~3 H1 `3 b8 x5 V8 w
opener.form1.frecname.value=val;
! O% O# l4 @6 a3 F" v6 j2 ]/ O
self.close();
' e C+ I* h; N
}
+ F3 s/ L9 @0 O
//-->
- n( \6 S3 V( [( E& r, ?4 i- T
</script>
. X7 j9 D) Z# K, P$ K9 ^
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
/ ^8 l5 S# x' l% N V
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
8 ]& {3 R+ f7 z- u+ q
<%
& L( D6 I7 i4 a3 x, F& ~
cdatasource ds=new cdatasource(); //数据联结bean实例
' b4 r6 S- F3 n! ?8 H# n, O
java.sql.connection conn=ds.getconnection();
; n# R( u3 `. Z0 I3 z$ w8 B
java.sql.statement stmt=null;
7 L0 k/ k$ m, m. E8 S+ n
java.sql.resultset rs=null;
8 C R6 {: \6 T# a3 q. P4 R5 Z- ^
cdatacheck dc=new cdatacheck();
: i1 w) d( o0 V6 p) c9 V1 A
%>
" n" r$ m @- P: r+ y
<%
' M$ @% y: c7 \- i, R6 ?
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";
. u9 v# X' y. K
stmt=conn.createstatement();
& L: l1 D# X- }7 R& x0 ?
rs=stmt.executequery(sqlu);
2 o! G. F" ]+ i; O" n$ ~! ]6 ?
%>
3 b& P) M, D8 Z7 A& Q- J
<script language='javascript'>
7 ~1 f; v9 _3 x$ R) k" u7 |' v' ]
arr = new array();
' I( m, K5 n& O8 m9 n& d* O
<% int temp=0;
9 ~3 Z# A; o# `) k
while(rs.next())
) f6 q# s2 R. J5 e- V2 `
{
& h/ |. w% d$ {/ v: M9 a9 ^
%>
8 x5 M2 s9 k) R
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
" E( x( o: J2 _! Q
<%
" P* s* Y, [* X2 `1 R
temp = temp + 1;
$ R/ C% F$ u" w) p
}
" c& F( B+ `' D& [
%>
; U7 l' a0 U4 t, z4 ^! |
temp=<%=temp%>;
. r3 Z6 z! Z/ M4 q0 F* D# }3 z
function changelocation(id){
4 c8 x0 v2 D& o) J W! Y
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
, R4 \/ Q; W9 \4 X& a
var i = 0;
( C; H/ r- h0 M. \" ]8 Q
document.combo_box.city.options[0]=new option('-------','');
. S0 W% b. x. V \+ U0 ~
for(i=0;i<temp;i++){
/ p9 D, O/ N( ?4 ?0 y
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
& s1 w4 b& F! G/ E
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
: W0 |+ J ]& `8 f( l
}
9 `. A; [. A7 \ Y5 R% L' ~! `
}
8 e- F( @3 P' r# X+ b/ T
}
$ z) W k' R0 _9 }6 y/ Q
</script>
- V. T/ y" t# Z6 i7 _8 T
- O: m' [1 T8 ?2 M& |% i9 |3 j* W
<form name="combo_box">
$ C6 B; F6 Q) J1 i9 p
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
. {5 h# o0 W# S1 W" R5 L* v( T5 w
<tr height="24">
8 z+ i- u! v7 ^ C
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
- Q+ ~4 {- M+ \# h" A1 J3 v+ J9 c
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
7 x( Q3 N% g A8 C/ l' @
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
8 g% q" i3 o. J" l6 ]# }3 u
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
# I6 ]9 @5 r6 V: `
</tr>
- c/ x" i4 v7 w4 {: C7 s
<tr>
& E( _% I( ~8 X/ L
<td>
) Z. F+ ]4 |3 |
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
* C. ]- Z2 E# |
<option value="0">请选择部门 ---></option>
* }2 _6 e4 B3 o) e
<%
2 W/ s- G7 _1 u
string sqld="select * from tdept";
$ c4 e4 Z' L; Y; B6 w
stmt=conn.createstatement();
) h0 Q1 ]# Y/ P6 A% ^) Z- u, _
rs=stmt.executequery(sqld);
4 T) n: ^% y) S/ Z/ z6 D4 ?
while(rs.next())
' l$ e2 p) K9 @) R
{
* J( i: b+ q5 T- K+ _
%>
/ Q% k" | x; x' N% l, G
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
7 Z/ v0 O# O$ n! `! m* p- |
<%
9 m8 E8 c/ E( A5 u9 ]
}
( z% T3 t/ u4 n3 m4 S7 q u
%>
7 z9 E7 x* j9 n( f, j
</select>
( V' Z5 |: l6 c1 ]- w1 K+ P
</td>
/ m( v1 O+ k( S( M1 W, `* }
<td>
0 ]( Q: d8 G3 B, r2 y2 [% F6 P
<select multiple id=city style="width:150;height:200" class="bgc">
6 t5 y, {" D+ M( B+ u: P" O J i
</select>
# {7 W0 ?5 u, \4 J0 @8 D
</td>
: O6 U: x( l4 y5 M& y* W" ?& \
<td nowrap align="center" class="bgc">
' w- K& F+ X& r6 m r. l
<input type="button" value="<<" class="buttons">
7 z) T, `, v7 J9 S( `5 x5 o. S
<input type="button" value=">>" class="buttons">
; n9 j) p8 v: ]7 O: k, y$ q! @
</td>
4 R6 R- z. F- W1 Y* M4 z/ m# c7 A
<td>
+ @& p+ K. x$ G; h3 O
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
7 h: N& o: x( \; T7 M% S# \. ]$ r
</select>
+ P, `+ r, @4 Y. O2 X7 v
</td>
3 O& n7 R* X7 R+ s
</tr>
" Z7 C$ ^+ s/ E2 r8 z$ Z3 l- {. E7 y
<tr class="bgc">
& q1 O6 T- ` c
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
" H1 _# R4 F* V9 |: p
</tr>
9 X/ d$ W. M+ `! O# T! X6 _8 l
</table>
* a9 \( R6 P) G
</form>
/ s. @0 L R, o" U0 S
<script language="javascript">
6 ~ U4 a( O4 q9 @) Y. [' m
//人名移动
s7 y, |" X: H' h' X' k$ i
function move(fbox, tbox) {
" v, K$ c/ n) z* |% U
var arrfbox = new array();
) _+ ]4 L4 |, [5 z7 B$ ]. @* P1 t
var arrtbox = new array();
r" f/ }% v7 A0 K* _$ @
var arrlookup = new array();
j+ v( Q8 B* K- _- z
var i;
$ M, r' e) D: N1 d( a: u9 k [
for (i = 0; i < tbox.options.length; i++) {
) o, r" n% }, d5 y) l
arrlookup[tbox.options
.text] = tbox.options
.value;
; j* Q! a0 o# o0 I8 h; ]: t# S' x9 Q
arrtbox
= tbox.options
.text;
. z0 f5 E6 o/ T1 b
}
5 z3 \6 q$ f {
var flength = 0;
* v) R) v) }+ r' [) X( \! Y
var tlength = arrtbox.length;
4 \9 ^5 V& I* `5 a3 J3 T6 Y& Q7 X
for(i = 0; i < fbox.options.length; i++) {
& ?& Y, u3 z4 d( _2 J/ d# s
arrlookup[fbox.options
.text] = fbox.options
.value;
( Y& S; z9 I B
if (fbox.options
.selected && fbox.options
.value != "") {
9 S* M0 l. q4 R4 q: U& R W
arrtbox[tlength] = fbox.options
.text;
! s0 A8 o8 E; W( e
tlength++;
% ?" x4 i/ }! d9 M3 M, p
}
' U) g' u* X+ ~1 ]& V
else {
7 l; K1 d5 [! k$ |5 T; `/ _' V H$ |
arrfbox[flength] = fbox.options
.text;
0 T1 A4 { v) f* u: T
flength++;
+ A( Z& o2 C @5 P! a
}
# C5 x. L% F m+ R5 ^' n
}
1 W0 a5 E% X# ^' X$ x3 {
arrfbox.sort();
) r/ A5 s& A" i2 W9 o! e3 r/ ?, o1 }1 n
arrtbox.sort();
2 N* ~! `4 P. O. o- M' m
$ Z( F' N/ |: Q% B' n* E: o
fbox.length = 0;
3 p2 _+ h& N8 V* V, p% c
tbox.length = 0;
& X5 i6 }" j5 y7 S
var c;
3 z6 Z( ^0 G/ I ~' B3 @. X
for(c = 0; c < arrfbox.length; c++) {
3 E: C3 W1 Y' I
var no = new option();
- o9 a% r( K6 O
no.value = arrlookup[arrfbox[c]];
! {1 W2 u6 _0 c$ j( m* i1 C+ ^
no.text = arrfbox[c];
8 z" Q' q% q: M2 H
fbox[c] = no;
' F W. G) j/ R! C
}
! C# d- g0 p4 v
for(c = 0; c < arrtbox.length; c++) {
8 G# N8 e) I1 o: z2 P# L
var no = new option();
1 G4 a S" k, O' M* x# F
no.value = arrlookup[arrtbox[c]];
- l, \2 P9 X# m3 J0 e8 C! x- B
no.text = arrtbox[c];
5 i: o" i/ |9 M0 ~6 |4 h
tbox[c] = no;
8 U" w6 _' Y* X2 L
}
; p( g2 I7 y: ?
}
, W; ]* {, _# k9 f8 n+ R
</script>
. ?9 f* D b, y
</body>
4 Y% @8 y0 F$ w
欢迎光临 捌玖网络工作室 (http://www.89w.org/)
Powered by Discuz! 7.2