标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
( S9 D' Q: }' P* P7 b3 v
c pageencoding="gb2312"
$ y2 ?( o0 N$ P! p6 s! Z) Q |
%>
% M6 l4 X: U4 S* [" K( j6 b
<style>
7 U& J3 I# G& Z1 ~
.f9{ font-size:9pt; }
$ j0 [, i+ t9 A2 [2 |% ?! r' P
.bgc{ background-color:#aecaf9; color: #0033ff }
3 r- B* S5 `$ H4 |, [2 J
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
1 i5 f% m5 H+ I8 j! g6 r R4 S" f
border-bottom: solid 1px #4e7dc1;
$ z# Z: h6 u: Q, j, q' S! t
border-left: solid 1px #aecaf9;
4 _% M" b3 l3 _5 q
border-right: solid 1px #5679bd;
( j* C. F% i- V; [! R6 M% D
padding:1px;
) N/ i- E! L, @& j
margin:0px;}
: r' X5 [& m3 I* }' h# W
</style>
) C& f; c$ \7 _& {
<script language="javascript">
w E* W- U9 m9 {6 S, Q8 ?5 t
<!--
$ s; k$ b+ L+ M+ G
function rv()
7 T2 w: C. y* O
{
2 g5 [9 b6 F4 k
var val="";
0 v0 z6 t' D) |6 I% m
for(i=0;i<combo_box.list2.length;i++){
9 F; j) Z* ]0 j
val+=","+combo_box.list2
.value;
" C: ?" k2 g7 t0 q
}
& m$ m) Z- ]% ~
if(val.charat(0)==","){
# {; O1 w) W$ @3 M
val=val.substr(1,val.length);
; D% A7 n( Z9 I' E S/ I+ X- k
}
2 h$ @, [5 s8 v
opener.form1.frecname.value=val;
- \1 I3 r0 U" V# o5 A
self.close();
( C- Q& E4 m7 r3 J# }4 }- t
}
: x! Q6 N* a* O+ Q! F2 Q; U% R
//-->
3 F4 B7 v! B1 X( I
</script>
- J# i7 t. _% _. U4 D
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
2 N% [2 i) R8 J4 O( b) M3 @ _
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
. d5 |6 ^( M5 s0 ]$ K
<%
" U8 b' C, ^( E7 V7 w
cdatasource ds=new cdatasource(); //数据联结bean实例
4 t9 e2 H: A6 k
java.sql.connection conn=ds.getconnection();
7 P. S% j1 D- r9 D9 v
java.sql.statement stmt=null;
! L" n. C0 d, C# t
java.sql.resultset rs=null;
6 U, Z& e; x* N9 }% A
cdatacheck dc=new cdatacheck();
2 ]; G, Z$ T u: d1 N9 \' |
%>
5 f0 j$ {: _' D# M* F# N
<%
) F" g, G5 s* s" ?1 S% L
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";
* Z" J/ p7 S# r4 t# I3 G
stmt=conn.createstatement();
/ d+ I7 {% n* D( {5 d
rs=stmt.executequery(sqlu);
6 F k) F/ u4 S! B
%>
1 z' H% P* S; T4 X" _7 {
<script language='javascript'>
2 N4 p# `5 W- e) D' L
arr = new array();
$ p) ]; y# R" `' y( X
<% int temp=0;
1 [1 V1 E) w% ]3 T
while(rs.next())
# J5 m- N M) J
{
( t8 x7 Z& g( a" }, e. f' V5 \
%>
$ J0 S( E7 z# p5 u7 Z, [$ f
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
5 B0 ^+ P* ~0 T4 M, {, W R# z
<%
x& p# T8 F2 K- n) S( v
temp = temp + 1;
" Y/ _" v- m6 R# G5 f6 a
}
1 [( W% V4 ? X) T
%>
4 j' u1 R8 ^# \
temp=<%=temp%>;
4 P. _5 s6 E2 A' x& u2 H1 t3 J
function changelocation(id){
6 \" W9 ?% a2 B" J0 P, S" N! d
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
1 S' ]! u; M, {, I( l
var i = 0;
+ k9 O- V9 F* b* X, `* H
document.combo_box.city.options[0]=new option('-------','');
( M7 U% o) l6 G R2 M
for(i=0;i<temp;i++){
, y, c" y7 H9 I
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
Y! H+ I6 f; `4 p- F9 h
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
: a9 x- U- i7 L8 f! q. R, ?2 x
}
( M, I8 p7 B. S6 a4 F2 e+ j. f
}
! f% R+ ^9 i/ R/ e/ V/ c) `
}
8 }* v" r% v7 \- a/ _
</script>
$ u. Z3 g% R' ^& M+ ?: D
) D3 N6 ]( K) s% t! f6 |; V
<form name="combo_box">
7 k3 x1 u& k9 e! l/ u
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
( K0 a7 R/ ~7 G2 b( |' Y
<tr height="24">
- Y7 {" z5 H( B$ F
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
' C! @4 |& v8 }) d: K1 P& }) z3 ]
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
5 m$ q8 I# l! \ K- }3 ~
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
' G/ ?& Q8 C, H# s5 W+ F
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
" q- n: o; B3 P, Y8 D1 t8 J9 J
</tr>
8 O4 N2 a! ]; g x* g
<tr>
9 Y9 O( }* o# ?9 ]3 T9 _8 \% j
<td>
1 k$ [ i' |% ^* @8 U1 @& o
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
" e4 @, x- {! |
<option value="0">请选择部门 ---></option>
! x: a0 h: H0 j: u4 z; N
<%
, o5 ^, j3 i+ y$ U
string sqld="select * from tdept";
% N6 G0 `6 A2 h' ^! m n6 b
stmt=conn.createstatement();
' x# U! I! P9 K; D
rs=stmt.executequery(sqld);
) ~2 E/ ]# J0 J8 u+ x4 T$ X
while(rs.next())
, Q' J) Y9 ]6 f! Y) u3 ]
{
P/ o9 V7 {: b0 b5 A7 O' p
%>
. r" _+ b. G$ d4 h. M+ Q
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
8 g7 t+ H2 x3 `8 C( o# f: E8 g$ |
<%
( Y0 r3 @. S$ t. r7 h( Q3 m
}
6 [" N9 m U% e a
%>
$ |- a" i+ S. N( I2 V6 E
</select>
8 a: B% q) h' f' s# D# c, h& X
</td>
4 p+ U4 B- O' e6 g) Y1 D
<td>
) o% }+ b) t, F( u& C! E3 r3 `
<select multiple id=city style="width:150;height:200" class="bgc">
7 \" M" ? f" {& S' y8 T
</select>
$ Q- R1 W4 C9 I, B
</td>
, C! K; ~6 V& Q( j1 H
<td nowrap align="center" class="bgc">
! l3 l7 }6 v) }& ^4 t
<input type="button" value="<<" class="buttons">
! Z2 r% c$ }6 Q4 O& s
<input type="button" value=">>" class="buttons">
+ Z4 a8 x( R/ s) e
</td>
7 A' U9 }3 d5 X- T6 l4 q
<td>
# C% R, ^* U/ I2 u+ d) A7 L3 e3 r
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
7 i. t" {& U! Q- p' S0 V
</select>
6 \1 k& _) E5 |
</td>
4 r, T: t; l- F3 v4 V
</tr>
0 x$ m( b, d* q9 u2 v, Y& K2 h
<tr class="bgc">
* e- v0 F5 P. r! G; Z
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
) k- x* u9 s5 a9 F
</tr>
, `) w& e2 E$ }/ q7 b8 g6 \6 g/ I( b5 F
</table>
! B- Q) R( z5 [1 W& _' a7 g
</form>
; c Z9 w% y: m4 @
<script language="javascript">
/ N& R8 r; }, M8 i1 u) Z$ f6 x
//人名移动
* N0 A/ M+ s, X
function move(fbox, tbox) {
' y5 ~% s) _, [
var arrfbox = new array();
" v3 n! ?* t6 }" d) m m
var arrtbox = new array();
6 H9 }& _) S% S v! y
var arrlookup = new array();
6 F+ r# {# }$ ^5 t" n U4 b/ x
var i;
8 Y8 W: ^: {* w
for (i = 0; i < tbox.options.length; i++) {
1 A0 k, _3 f3 q; U3 p1 n/ `
arrlookup[tbox.options
.text] = tbox.options
.value;
# m: D2 o9 Q1 T ?0 t
arrtbox
= tbox.options
.text;
2 X7 ~5 n3 u% v+ U1 v1 x) d4 b% v
}
! }% l% R) t/ X: ]+ ?, g9 t
var flength = 0;
% S- b; w7 K7 G/ z" X
var tlength = arrtbox.length;
/ h: L2 m! e3 |, N$ Q+ `; y
for(i = 0; i < fbox.options.length; i++) {
2 p: B2 f, a0 Y& g7 c6 S
arrlookup[fbox.options
.text] = fbox.options
.value;
2 j% U3 j6 O7 y8 E# }0 k
if (fbox.options
.selected && fbox.options
.value != "") {
9 b6 D& @6 ?! |" p6 u- s) t
arrtbox[tlength] = fbox.options
.text;
( n. P( s% G$ \9 W$ \% s! V
tlength++;
7 V# N, [- A' p7 g
}
6 ?0 W$ @+ O/ _( s, G
else {
1 [4 D! O. O% t9 F' f
arrfbox[flength] = fbox.options
.text;
' E1 H$ k2 j5 f4 j/ w: u
flength++;
4 j5 A2 j8 Y( ] c0 [" p
}
& N/ O/ _' d1 r3 @0 G. h+ N3 D
}
$ @& H+ K& X% I" O* b9 Y1 V( V
arrfbox.sort();
4 x- x l4 } O0 y4 }
arrtbox.sort();
( ~6 j& Y& K6 w7 v3 h' S
' e# n d. Y$ Z5 N4 b6 V$ w6 h
fbox.length = 0;
T% w+ w8 V2 w0 s) f/ y
tbox.length = 0;
( P3 Z. U- |% K: a9 D( T2 h
var c;
! R% w. o2 c- i3 i8 J
for(c = 0; c < arrfbox.length; c++) {
5 \/ `" @+ B, O6 h3 z
var no = new option();
& I9 h# t j4 u8 f' [: q) T3 K" F
no.value = arrlookup[arrfbox[c]];
; U. P2 U) U; S# ?( ^
no.text = arrfbox[c];
9 s, U( A4 O5 h7 } j
fbox[c] = no;
, z( P# f) H6 s; m& Q& p
}
' U9 C& c, ?5 l/ t6 P& Q7 }" @# ^6 z
for(c = 0; c < arrtbox.length; c++) {
3 J! b7 \) P4 S5 J
var no = new option();
' w* I/ }& `1 y5 `8 U; c3 U
no.value = arrlookup[arrtbox[c]];
/ V" J7 `% e$ \9 F, v2 R
no.text = arrtbox[c];
2 }6 d8 H0 O( g; q0 A" Y {8 C1 y
tbox[c] = no;
7 T* T& I# Q6 I( Q6 J% J
}
" g% o/ {# j, a X$ ]+ [
}
; I2 t: U; Y# {% V$ a" W( F
</script>
& m' w9 w; `/ u
</body>
- w X! n E( c3 b$ q' O% }
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2