标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
- w9 o9 G9 {: ?$ Q9 k
c pageencoding="gb2312"
1 R7 ]. h) B$ c, _. v5 L! U& A
%>
) c2 P- u5 }6 P" q
<style>
: j# K0 a) {- x
.f9{ font-size:9pt; }
0 y9 o4 R" G K3 U
.bgc{ background-color:#aecaf9; color: #0033ff }
, X0 [# K( F4 I- U' w5 D* y' n; I/ V
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
& {" f0 }) O. \
border-bottom: solid 1px #4e7dc1;
$ V$ {+ R6 }& o3 j& c1 F
border-left: solid 1px #aecaf9;
I( P* }. { h N
border-right: solid 1px #5679bd;
/ Z' n6 O& s- e6 Y I& j" f
padding:1px;
* f S. d2 w: Q$ p+ o7 B
margin:0px;}
! M9 W: J0 I2 Z, X+ t
</style>
. D. F( i2 Y* w" Q
<script language="javascript">
$ `+ u; @2 @* ~/ U
<!--
5 [4 K. i4 s O2 }) Z! F
function rv()
2 a2 H- o" G' X( [, @/ h
{
- U# s/ F4 ^2 D( L7 ]9 h
var val="";
6 |! p( @8 _3 `8 @0 t6 N4 J) ~" K) S) c
for(i=0;i<combo_box.list2.length;i++){
- Y6 z% @, ]# y9 S! s" e+ w* l
val+=","+combo_box.list2
.value;
+ M ?, i9 ?& `0 N6 `7 C3 ^
}
! l/ ]* a6 ^- f, x, `9 D' E* S' t# q7 }
if(val.charat(0)==","){
% X+ a+ e2 } Z; [- U. R) l% i9 u
val=val.substr(1,val.length);
; W4 ~9 ~/ I, r- O" b
}
, D" ?5 \9 \# w+ M6 x" t
opener.form1.frecname.value=val;
! T2 Q7 o o( z( |( _
self.close();
6 H8 R" R9 `; m1 g
}
0 u' q" [5 l2 A8 ]2 b0 I3 @0 z" D/ U
//-->
7 c7 ~; g( l9 g/ E5 x# z
</script>
% N# H/ _0 {1 P" Y0 x8 X
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
" y6 w. O ~4 p! {) `; L
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
6 Q2 S: ~( ]3 c2 m. L+ s
<%
3 N$ r R" X# J
cdatasource ds=new cdatasource(); //数据联结bean实例
- Z0 N* p2 u1 p
java.sql.connection conn=ds.getconnection();
1 n3 f3 B+ O3 \! x1 T) X
java.sql.statement stmt=null;
1 o5 F: C) L. r- _8 K: R
java.sql.resultset rs=null;
) C" S0 E2 t5 _7 b. y( D3 E/ T
cdatacheck dc=new cdatacheck();
* W6 H4 P" c# j3 |. n) }/ x/ B
%>
6 n8 `2 l4 b6 k5 o3 N* F4 O; R6 }( ?; {
<%
) I4 t/ L, \+ T3 c
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";
* ^ V# o* t+ f7 g @
stmt=conn.createstatement();
: m5 L. ~1 F! A1 ]% V
rs=stmt.executequery(sqlu);
1 }' N4 J4 R7 X! O
%>
3 F2 I9 ?& X" Q' ]7 |
<script language='javascript'>
) v7 |- x, f6 P6 u7 B) S
arr = new array();
) R; p) ~! o1 ^) x& M: L7 U( t7 z
<% int temp=0;
) o4 b0 k& J3 D" _
while(rs.next())
7 ~7 R7 n3 z" ?8 V4 ~0 U- M5 b
{
! q1 J( Q3 }" n1 P# w
%>
% M4 x9 H/ a4 j
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
- M- R- G3 Q" A' Y& Z/ p% n
<%
5 K, P# h' J# C3 m5 t
temp = temp + 1;
" u% o2 z5 F. \5 j- g
}
6 q+ j% \" S5 _2 A
%>
% P# @4 v* Y4 I( Y$ ~! U, G' j
temp=<%=temp%>;
7 a/ n( ~) k! G0 F
function changelocation(id){
7 |. [& x8 ~: t5 ]6 w& o( R' @
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
$ y8 T8 Q- p9 h7 [. k
var i = 0;
# r, U6 i! z& V0 X$ X
document.combo_box.city.options[0]=new option('-------','');
3 Y- P: F8 |; ?+ @- b' W5 S: y9 d
for(i=0;i<temp;i++){
- s1 ?. ]) {' G- M! D5 \7 O4 u
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
5 C: x6 f3 Q- z' R
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
; u _' g6 s5 F" g: k5 |+ `% c' S9 y
}
( T' u+ o* @0 o$ K1 y4 B
}
! u5 |2 n/ U& C' r9 \
}
% B4 X) ]3 q& p- s8 b3 I+ z
</script>
8 K: x- Z0 l; y0 x
7 i5 T, V) C( Q9 D
<form name="combo_box">
& N* n; ^$ `; x. H7 `8 Q
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
- L8 k y7 [5 V0 Q1 J0 Z/ y A* b' m
<tr height="24">
1 q( F7 E* n v4 n
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
; R' ?0 M/ o9 b6 b; s/ q
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
) x& g; h. `8 u7 E: j6 a5 g
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
$ J8 b( U3 L* L/ {) q2 N
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
5 L5 K, ^' U$ j. _- v. Y4 J3 I, S
</tr>
+ }# }% L9 @9 B% D6 V
<tr>
; }& k3 G8 M# B! ^+ t3 H
<td>
- E( L, e/ g3 @* o. h) h' t
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
4 o; g- O* P; y, V) e" [: L0 M3 ?
<option value="0">请选择部门 ---></option>
3 k& E1 f" q* X
<%
1 e" E& H! k& a0 S
string sqld="select * from tdept";
. C. y. j2 N' V7 W
stmt=conn.createstatement();
" y" E5 y$ Z' ` R- [
rs=stmt.executequery(sqld);
2 F* m+ a/ W3 P' z) S4 Q- v2 p
while(rs.next())
4 S" E8 ~4 G7 @7 D% d! U
{
# q/ t& H C: o! _1 _/ j
%>
$ f. ?7 R6 \3 T8 M
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
3 @+ }" ^- {, J+ o
<%
6 q& [0 K1 @3 r7 Q; D! U# F! N; g
}
7 B" a' }/ M. o. r
%>
; U& N# I* A Z3 x; S7 Q" ~9 @
</select>
" D( A) \4 O7 K A
</td>
: b6 v% a" Z$ Z$ z: o$ k
<td>
v, ]! x$ C/ f( M3 a4 z5 ~- z. b! H
<select multiple id=city style="width:150;height:200" class="bgc">
1 h! z1 j1 }/ c( {# q1 a4 |
</select>
8 W c3 v: {2 m; @; ^2 ^, b: ~
</td>
: C2 p0 l1 ~8 }4 y6 h5 q* b
<td nowrap align="center" class="bgc">
: Z6 J# E, N3 Q1 P l
<input type="button" value="<<" class="buttons">
7 r' U6 M. b2 F, `) o
<input type="button" value=">>" class="buttons">
5 Y0 C! f- R/ K" V6 T
</td>
( M/ z1 Z" Q: m, N3 X
<td>
) n+ c, {8 b; Y& r' }
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
7 E' L, r; | x$ @" I) {/ I: u
</select>
. [; |0 e' {. n, g: m: E$ ~
</td>
& E4 I% F9 e: w- V V
</tr>
( F4 h5 E& O8 T/ ?7 C
<tr class="bgc">
4 |' G) ^; Y7 G; S! W) I& s7 Y
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
/ D. C4 F2 P' C, J4 m- i
</tr>
! \9 a9 T( L- R) k5 _( T& x
</table>
8 f- J) u6 {' j+ O
</form>
7 @; @8 L- h( W
<script language="javascript">
( d1 r$ D2 h' N9 v
//人名移动
: M% z4 ]- R# P( H* v
function move(fbox, tbox) {
* p7 ?, L- s2 @: \* y; t% r: O
var arrfbox = new array();
* @4 W& v0 \9 V
var arrtbox = new array();
$ q$ e* ^. s' g' m
var arrlookup = new array();
) p O" b4 I4 w% F( j2 ?1 j% b0 A
var i;
+ h* m/ |8 _/ a" f
for (i = 0; i < tbox.options.length; i++) {
O O& W2 ]% V. M( O; F
arrlookup[tbox.options
.text] = tbox.options
.value;
" [* v5 S+ k5 A/ h
arrtbox
= tbox.options
.text;
9 Q; l/ U# \$ _1 ]" w1 O
}
+ M5 c' S8 ` j8 u: p; s$ g; |* |' \
var flength = 0;
7 ^5 S: ]$ Z, C3 f3 M
var tlength = arrtbox.length;
4 z4 I8 V9 Z4 U' x1 o
for(i = 0; i < fbox.options.length; i++) {
" a! Q6 D* K/ e( ^* v7 r7 ~* `% ?
arrlookup[fbox.options
.text] = fbox.options
.value;
/ M6 ?: Y; y# i6 i
if (fbox.options
.selected && fbox.options
.value != "") {
" R4 W( ]- f& c4 m5 |2 U! ?
arrtbox[tlength] = fbox.options
.text;
. r. H6 n h% O' b0 ]: M. r. `6 P
tlength++;
* b5 P" i6 g8 A
}
% [4 Y/ I( L2 n
else {
- q: j: s9 z1 _6 B3 C
arrfbox[flength] = fbox.options
.text;
1 p( p; ]0 B0 Y' W
flength++;
% ~' s6 H% n0 z& H F* T
}
7 L0 `: G4 Z2 Q W f3 o; [
}
/ B4 R2 M% q- B2 X- H
arrfbox.sort();
: M/ z+ w8 u6 k
arrtbox.sort();
: c4 k$ @$ u' C2 \; ~# i
|3 y! {. C6 [5 R' v/ Z/ q
fbox.length = 0;
# L. m3 ~' A0 z% L4 [
tbox.length = 0;
! ]; x! y/ T' P# b% `6 w+ ?
var c;
& ?* d x: _/ \) _/ L. a3 w0 J
for(c = 0; c < arrfbox.length; c++) {
2 ?& l5 k- u5 Z' B3 s8 m
var no = new option();
: D) n* Y Z7 T: Z& ?
no.value = arrlookup[arrfbox[c]];
( P0 V5 y2 ?$ P1 j$ Y( j3 K
no.text = arrfbox[c];
4 j& G' \, G; a3 a0 b2 P. j
fbox[c] = no;
J. f4 F. e1 [' o3 `8 r
}
. o& [6 w$ a3 f5 K, H
for(c = 0; c < arrtbox.length; c++) {
1 ]4 w) E- {! |- |6 D/ t
var no = new option();
4 L0 Z( p, K3 @) x. |
no.value = arrlookup[arrtbox[c]];
7 t O3 w: C: V [% n, z
no.text = arrtbox[c];
( ]7 C4 t* ~ ]' b
tbox[c] = no;
; |$ E6 c: D8 L, a8 H
}
/ o; f8 K# A' g; N' I, Y$ s
}
2 ]4 `8 T4 q/ b/ j+ ?9 k
</script>
5 H4 J) [0 l7 k) b7 R9 W. p
</body>
( G4 G6 S8 b* B- Y
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2