标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
5 L$ x) \8 p7 ^
c pageencoding="gb2312"
# W& o* e5 E' E) v, [( ]) d
%>
$ @9 e- U6 `# w9 \+ t, h
<style>
9 z9 B6 y$ ?. `( h/ p
.f9{ font-size:9pt; }
* u9 r! C5 V+ x
.bgc{ background-color:#aecaf9; color: #0033ff }
! b1 B& \- [# w4 T
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
) @! L$ S. b$ r1 Z2 v4 Y- x- s
border-bottom: solid 1px #4e7dc1;
8 L n7 P( H2 I2 v: m. Z$ j
border-left: solid 1px #aecaf9;
( H2 L% E) K* q. x0 @, _
border-right: solid 1px #5679bd;
; U/ G5 {! H& T
padding:1px;
) D2 ~; s: e& h( l4 v5 e
margin:0px;}
8 b3 n' f1 u+ B) n1 i; G- X1 b& V
</style>
6 L* V n. Q9 o, B
<script language="javascript">
) d) W7 ?, X0 Z* [% @8 \4 b
<!--
0 i4 w- i' M9 k( o% x4 y: @4 Y
function rv()
H/ n1 d7 p7 {. G! C7 F
{
9 l o9 @9 X, K6 o. g& N
var val="";
i: r) f0 r; |$ W1 J; ^- K3 M; ~
for(i=0;i<combo_box.list2.length;i++){
7 {5 f. j# t* O/ s% u
val+=","+combo_box.list2
.value;
- U2 w$ f, }* c4 o9 N8 S* K
}
7 J# U; z( C7 m# @) G
if(val.charat(0)==","){
1 [, S( o& m- F8 ]8 H
val=val.substr(1,val.length);
; g# h) q% l/ v5 R
}
! c% k3 h* {( m
opener.form1.frecname.value=val;
0 Y8 |+ D9 a1 C
self.close();
" f/ ?* T' D; r# a# B
}
7 I3 x- F6 U+ {% ?# R" H4 s
//-->
0 e2 D! v% s0 \' {; X9 s' W% Q+ a' S
</script>
6 T! v' U- r7 Z/ [6 q
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
+ D: P- l& H1 ?! p
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
5 Y9 p( L% F& V ]% K# R9 A
<%
% e) E% Q ^5 |
cdatasource ds=new cdatasource(); //数据联结bean实例
8 u5 K9 v8 O! R% k5 R; Z
java.sql.connection conn=ds.getconnection();
- g3 d4 i2 S0 R. U" k; z, E) G
java.sql.statement stmt=null;
+ v% T# s0 w; J4 U4 E. x1 P
java.sql.resultset rs=null;
- t; `8 E: A6 O+ _' y
cdatacheck dc=new cdatacheck();
) t& o9 U. m# }
%>
) i4 ? _$ v2 ~ O4 F0 d$ ^- X+ K
<%
+ s `7 d9 y+ F/ v9 v, p& j1 ^
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";
' j2 w; W( U5 R" G; B3 I
stmt=conn.createstatement();
( p1 v8 [, _! i8 p* w0 K5 u: ^
rs=stmt.executequery(sqlu);
7 A4 k0 q& Z& _" h& T
%>
2 z$ d- f# \" ~# ]; j$ q
<script language='javascript'>
8 V1 m0 |3 T# g7 t4 r
arr = new array();
: l, f3 {9 m0 f) |; \
<% int temp=0;
" \( [. G/ ~# Z: I& Q& Y$ b) @
while(rs.next())
2 F: f' j1 T/ ~, P) r4 n+ P
{
6 j/ P3 t* _: ?
%>
& n- _* u6 r7 V& s F+ `
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
, x, U0 U4 a- r4 |: C" w. }2 X
<%
) Y* u8 f+ K; K" b. n
temp = temp + 1;
: _, ]; B T* |1 w; @! e5 H# g0 \
}
4 u j& A% M( s: Q% ^
%>
U5 z9 C( [- R: D/ [2 `. |
temp=<%=temp%>;
! w% `2 {3 R( y: y/ r, u
function changelocation(id){
( P) ^. n# \9 X* q) {+ ~& b0 l
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
$ M3 k4 x) M' ~9 D3 C f M
var i = 0;
3 V* e7 t; s+ J& a3 U' W( X) t
document.combo_box.city.options[0]=new option('-------','');
2 l. K3 t6 M( z% I; f- e2 p: T% p
for(i=0;i<temp;i++){
' D1 ?- y h# W- ~% j( K) F& Z
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
- Y, z# k* Y, v. w7 m5 s; T
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
+ K' y* W) W2 k# b
}
) l" N* t& F$ U! ^' O8 E
}
9 I! h' x) w! _6 r
}
8 R4 |; x- d" _
</script>
% V9 {( w3 W; g' S% d# ]
* _& {" M! v" @4 K) U6 Q
<form name="combo_box">
$ N8 s$ B6 S9 L* `, _4 R3 ?1 G
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
5 X9 b0 @$ _6 g/ x' C4 P9 Y2 n
<tr height="24">
+ c5 e! c8 b' L$ T0 E8 S
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
. d, M8 |+ a* a6 `6 q3 J
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
" f+ ]7 Y! p% m
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
0 _0 L3 s) i. j5 v4 n2 _4 B
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
) H% V) ]* y# G" j3 O+ O! v" g
</tr>
; G0 F6 J0 N' ]4 D' O; |/ f, G" q
<tr>
6 t3 I+ `* T* A( ^( L7 F
<td>
. n N% y- R; x0 _) x( f& I' m5 ]
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
, b2 i1 h4 s' U5 m' L/ `* U- y
<option value="0">请选择部门 ---></option>
3 l% a( }) M1 H* X* n8 U7 J) ]; m
<%
- p1 g- Y" F5 k% `6 z* _
string sqld="select * from tdept";
; x+ c, n8 b. t: f
stmt=conn.createstatement();
& d. `! y. Z8 p' r7 o. {# i
rs=stmt.executequery(sqld);
5 Z# j8 [7 P; [' P5 S% Y
while(rs.next())
' [5 B/ R. _- q8 E+ i) A8 b: ~4 ]
{
+ s/ a _, O. ~9 z% B5 O. F
%>
1 i* i# ^$ O. a' y( }5 l
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
. _* z+ ~0 [! J) E% N6 h" c1 Q; e
<%
7 P7 |+ e* M# O7 @' z8 C( C2 W
}
' R5 H r# M. U% j6 s$ u: n
%>
; l0 |9 ~6 K3 G9 U2 H" v" R# [" |* ^
</select>
! V: L3 e' o0 R0 Y' z1 y3 b! d
</td>
* B+ N) c! k/ z, j" {- }
<td>
4 n- Y# U1 a6 u* i! O A
<select multiple id=city style="width:150;height:200" class="bgc">
?' z( Z0 _' W* R; b: | V. E* M
</select>
% |7 h5 h y- N# S; S
</td>
4 P v) F- V3 X0 P: }) o1 ?6 Q
<td nowrap align="center" class="bgc">
* l" `( X0 l( d' k
<input type="button" value="<<" class="buttons">
3 E& i3 u! G5 b/ i& O) _8 k. u
<input type="button" value=">>" class="buttons">
/ P6 y M) e5 G# |5 S3 \/ J# g
</td>
% h* Z" @' N7 E! A3 |
<td>
2 _( q( S7 E% o% K$ B1 g( x1 d
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
! o: ^! m: j* C) |5 ]0 C
</select>
: J# N6 |6 C- j: ]2 \9 }4 R3 n4 I
</td>
' h+ M0 P% A( k( I% G. i7 E) j C
</tr>
0 D' i$ L8 a: j3 z2 B) l7 b
<tr class="bgc">
2 g$ ^6 l9 P8 G3 W7 y3 `
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
' [3 L. |& h2 {1 ?) b; D! b% U
</tr>
: L {2 E; O. l8 ^
</table>
) ]) S0 b+ G9 O# f
</form>
; L- V4 L; M* ^+ ^$ o9 u/ R
<script language="javascript">
5 M, e' _! C& b
//人名移动
: i4 ~ B/ @* R( ~: M+ j- J; D
function move(fbox, tbox) {
; i. E/ l9 ]" B0 g& S' M
var arrfbox = new array();
0 H; \9 }+ \! J$ L% V, F) t4 Q! s- V
var arrtbox = new array();
1 s. {: }. w3 H, }
var arrlookup = new array();
' O% T" t; m) s8 }/ D* ?/ g- D
var i;
; p" `4 z* a* W9 D
for (i = 0; i < tbox.options.length; i++) {
$ Y* V5 ]4 ]$ H: D% l1 }
arrlookup[tbox.options
.text] = tbox.options
.value;
% r& f' D9 d4 f9 d0 }
arrtbox
= tbox.options
.text;
0 V) l; `# j. O% M9 r. s
}
, m! j7 f) S. v3 e( U* ^& O
var flength = 0;
; i2 T: |! H; h* @9 c: M% b% n$ _
var tlength = arrtbox.length;
- U$ L0 G. s) q+ z
for(i = 0; i < fbox.options.length; i++) {
+ {! F9 |! t: H5 x# i
arrlookup[fbox.options
.text] = fbox.options
.value;
9 X( O& K+ j& X: Y
if (fbox.options
.selected && fbox.options
.value != "") {
" [ ?) ?- F. [2 m, R
arrtbox[tlength] = fbox.options
.text;
3 V: \6 T2 W, v; Z
tlength++;
! k! J* G8 g1 @/ R/ D
}
: O3 m1 C9 a3 m3 x- s2 j9 ? u n, [
else {
6 s( ?( M9 |! h
arrfbox[flength] = fbox.options
.text;
7 B9 A2 R3 [' n5 `5 M
flength++;
: s6 j$ W' |+ U7 a
}
/ t1 Z1 f$ s0 Z7 j0 x- f9 ^, E+ R
}
( j* z9 Y5 d) i' @* Z4 e
arrfbox.sort();
7 a& V* Q+ U5 B5 K/ t
arrtbox.sort();
' W: b7 v0 N- k ^% b' M( b
9 M B. Z" ?! {# f d3 `: ]! s& H
fbox.length = 0;
8 Y/ P# P) J2 [9 l+ w% {
tbox.length = 0;
7 k3 d3 P0 o, g
var c;
; k; Y8 B8 t+ d8 G
for(c = 0; c < arrfbox.length; c++) {
) A9 Z& R' S( ?) j- p. {! J
var no = new option();
6 e1 C* p5 Y) u! p( J5 i4 Q( y
no.value = arrlookup[arrfbox[c]];
5 g! r0 ~- D3 W1 g/ s5 v- X0 F
no.text = arrfbox[c];
1 o& J9 p' t! s* l
fbox[c] = no;
8 h8 {$ U/ b) e6 z
}
' l2 G/ Y: J8 H1 W' l1 n
for(c = 0; c < arrtbox.length; c++) {
$ _) D5 w9 h$ F ` f% E
var no = new option();
( A8 D2 l' r" B* _
no.value = arrlookup[arrtbox[c]];
5 E( }2 D" ^6 c4 Y# f. b
no.text = arrtbox[c];
, M( z, F T$ n
tbox[c] = no;
6 @1 h4 a" r# m/ c! A6 D2 W1 `& @8 m
}
$ r* i/ u- f( D9 _
}
# l& E; p. j% Y/ E
</script>
1 w- x) [/ o: X
</body>
4 t# x3 y$ n0 w- y. W" p
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2