标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
# I& r' ]# I; Q* z3 H$ C% h4 G2 i" v1 a
c pageencoding="gb2312"
: P+ M1 p' L2 \% l2 Q3 q
%>
9 R, D& { @% M: Q' i! D; P% Y- w
<style>
: B2 N/ `) }7 A( ~+ f
.f9{ font-size:9pt; }
% i* n p/ O, W* K- M- \7 n# c
.bgc{ background-color:#aecaf9; color: #0033ff }
- n8 ~6 I- |- E3 _& x
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
4 h1 N5 e# A0 ^* o
border-bottom: solid 1px #4e7dc1;
2 B5 S( o2 ~2 X0 A9 c; t
border-left: solid 1px #aecaf9;
; Q( C4 j: {6 @+ j' z
border-right: solid 1px #5679bd;
* A) X: }& A1 S. d5 s
padding:1px;
/ q8 W V' R( u" V: T2 Z) C
margin:0px;}
* V5 A/ }0 H- F6 p% f# o3 W
</style>
3 t! G6 D4 X9 _8 h3 n( B1 T
<script language="javascript">
; q @: d7 L* x0 t( o
<!--
9 V9 a: N) |; d
function rv()
4 W$ E- d+ S+ n2 f: m
{
. s1 P0 ]3 c4 x. E2 E4 C
var val="";
( {# Y- a4 \7 [& G% ]* G0 X: V
for(i=0;i<combo_box.list2.length;i++){
* l8 d& U5 o( |3 L+ a( m
val+=","+combo_box.list2
.value;
. Q. @6 b7 ?* D
}
2 R# g n4 l& V' a/ R+ }
if(val.charat(0)==","){
; S0 t4 ^0 d' y+ x' f0 l& \( b* i
val=val.substr(1,val.length);
$ ]1 k& j' Z' n" |
}
2 `$ o& |" o: c1 H5 v0 c
opener.form1.frecname.value=val;
# c9 k+ h! Q: F M) Y5 I
self.close();
! I' q/ q$ R2 l
}
, f6 T, e# A4 n" J' Y' R3 p/ j
//-->
7 m T. t: H, A/ r% U1 P7 K
</script>
# x B' y) _% |+ o; ]: G4 S
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
* W4 C" G2 h3 [4 _/ O
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
6 C: u- n7 a# [3 Z1 L9 ~% \) \; N7 {
<%
) G' [, f" n' U' \ ~9 q9 N% n
cdatasource ds=new cdatasource(); //数据联结bean实例
. z" @1 i2 n1 P! O$ W
java.sql.connection conn=ds.getconnection();
: k3 b/ e% L) d1 l
java.sql.statement stmt=null;
7 U i5 e9 g ]8 W* R
java.sql.resultset rs=null;
& c- i# R4 U4 U; I2 B$ M
cdatacheck dc=new cdatacheck();
! \* R' s% D7 {* G e5 I b
%>
; c+ E R$ X& P. n
<%
0 m1 l, r7 L6 n/ Y: [ ^
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";
4 [1 Y# C5 q/ z& N6 P1 R3 Y
stmt=conn.createstatement();
/ l+ X; Q4 J1 N
rs=stmt.executequery(sqlu);
! D2 n3 ?7 _0 W1 V
%>
1 _# s/ K- M. C4 N8 E8 g
<script language='javascript'>
' E1 A3 a/ ~6 _* j+ G5 v7 k
arr = new array();
( \$ A' Y* e( {. z( |- T) O
<% int temp=0;
' G" ^) K8 M2 I% g
while(rs.next())
+ O( x) D$ V2 H% [
{
6 x! p7 U' i) C4 [3 L$ y# t# g
%>
5 L" O8 ^3 C% L- F# m
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
) m+ }4 l6 e! |) r0 }2 W
<%
" n }3 B9 r- h& ]
temp = temp + 1;
. R1 r: x: G$ m& f, {! O
}
( Q5 h& l/ A% u E- L1 n+ q$ f' k
%>
; o1 B0 ~( v& O6 U9 Y0 i" [
temp=<%=temp%>;
' ?- J2 C/ ?) _+ M- U& M( p; @9 Y+ {
function changelocation(id){
* z7 S* \8 A$ I
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
, L7 _( l# j; \3 k T6 R
var i = 0;
: S) \5 ^/ f; _5 o8 D
document.combo_box.city.options[0]=new option('-------','');
4 |9 y- @' R e q6 d2 `+ z1 Q
for(i=0;i<temp;i++){
4 s- d7 w! _; F+ r" u
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
" m0 p* L. T1 l: G
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
/ {# h0 q$ o. ~" `7 v
}
" c* O; I8 P8 J& v* r
}
4 g2 [- A4 m8 B+ \$ D1 K
}
. o+ Q3 }- x( h) r& Q7 O
</script>
6 |: H6 s+ x6 E9 q
* K2 f$ }4 e) j" \# R
<form name="combo_box">
8 k. b. s. `6 L1 y, V/ P; p/ R
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
0 c& o2 h, L# f! s t; {
<tr height="24">
! {& f( r& I5 o1 H
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
- E a- ^3 X4 u5 b, ?7 K& w! l
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
7 ?/ z# R: Z' S; r5 n
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
. D9 p3 [- X' y* T/ p6 |/ X0 Z+ Q! z
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
; j, V+ A, E- T# |( {
</tr>
$ O0 R# m7 n, I9 x; J2 J5 s( L
<tr>
! v- p0 L$ r1 C2 P5 r4 L$ R4 O
<td>
4 S3 d. Z; [. S6 d( p- x w
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
# D1 Y# U: t- M1 j/ A& {
<option value="0">请选择部门 ---></option>
1 c) i9 Y* _; B& X6 Z2 o
<%
. w3 Z; v1 U L; ]2 ?: b
string sqld="select * from tdept";
% t$ I/ J5 r$ q8 j
stmt=conn.createstatement();
* ?# r- a. q, e9 T' v+ T
rs=stmt.executequery(sqld);
6 l, B7 V2 {' B: ?3 }7 m7 T
while(rs.next())
2 V! Z6 ?7 f# d
{
9 e) r0 E1 T1 N% `) R& v, I9 P
%>
; s( |5 W1 J; P0 ^, [- _
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
K2 ?- a& s3 z: P) a& W5 G& u0 k. d' k
<%
5 M9 G$ g& F+ n) _5 U
}
+ ]' I5 l, ^2 K1 z* e$ r0 ~8 c9 o2 s
%>
1 K9 s' A: ?/ O( S, `
</select>
1 A: ]8 q: z* o) W2 C" F+ F- J
</td>
8 `" w. ~8 [ p V- V3 |. @
<td>
: E9 I' V, J2 X; e- _) Z* }
<select multiple id=city style="width:150;height:200" class="bgc">
3 i* C5 \0 y7 j% m% m# J
</select>
4 h9 `) U- e: R& V- j
</td>
. O) Z6 @* q7 H: |( C" R
<td nowrap align="center" class="bgc">
: T2 H8 X" C$ g. ]0 ^ a
<input type="button" value="<<" class="buttons">
* Y" ]$ z( Z, c
<input type="button" value=">>" class="buttons">
) g- [" c- b- u+ ?, |3 {/ r
</td>
5 o& S/ c: G7 w' O: L( F( D
<td>
4 }, i9 m- }, v: c
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
4 D9 q; j* \# J6 o: R U9 }) v
</select>
. G, w& F: c9 [% A0 c; R
</td>
8 ]% J- X* ~+ E$ j( Z
</tr>
0 [: E. W8 `7 b4 `" S$ c9 ~( [
<tr class="bgc">
2 @- f( i2 k6 j8 ~7 ^# r
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
+ q) R" K; i! U, L
</tr>
: R q5 I$ J% j
</table>
- f4 P( u2 h9 P1 E
</form>
" Z$ D" D' ~8 L
<script language="javascript">
( _& v% c, J( q0 u' b- N/ r
//人名移动
5 C9 [$ ~: Z \6 b/ _
function move(fbox, tbox) {
& O) B5 F$ T: {
var arrfbox = new array();
; ^2 t2 U0 i8 n1 I) L( N
var arrtbox = new array();
. O K4 h! A1 Z9 j" K
var arrlookup = new array();
) L( F# |# x" ^) V/ m8 n) D0 y
var i;
9 J: H: V/ H; M+ F
for (i = 0; i < tbox.options.length; i++) {
3 x* w% d& e3 J8 M
arrlookup[tbox.options
.text] = tbox.options
.value;
% R; |7 I" T; s# y! J1 j: ?0 b& Y
arrtbox
= tbox.options
.text;
# R- O1 k F4 i. c1 ~ Y: {8 `
}
- O6 E7 q: Y! h8 U
var flength = 0;
+ e: u4 o0 e( S2 ~
var tlength = arrtbox.length;
$ x0 k+ F: ]4 L' W/ t2 j1 [' w4 _7 E
for(i = 0; i < fbox.options.length; i++) {
' b, o8 h, x7 x0 X8 s
arrlookup[fbox.options
.text] = fbox.options
.value;
, o) }' c* i' ^. r. H9 N, ^
if (fbox.options
.selected && fbox.options
.value != "") {
( r/ a8 C* P1 j2 [4 F+ W% n1 |
arrtbox[tlength] = fbox.options
.text;
) m! i5 z, i0 Y: ]) O+ D/ A4 j
tlength++;
k' w, B% Y) _9 P
}
& l% e2 E9 _5 ^
else {
% \8 S8 `9 g7 ^9 H- P$ e- L1 r y
arrfbox[flength] = fbox.options
.text;
8 ?1 L( f. q) U; e m8 p3 |
flength++;
7 @0 A( z; z- F; j! i7 {& S
}
! ]3 `& B6 w# G3 i
}
0 |- K: r9 R) A) a! T# P P& M/ f
arrfbox.sort();
6 w$ R) H+ w6 }2 L" [
arrtbox.sort();
8 g. o) [$ l& g: L# A/ R
& L. d: o! @9 O2 g3 ]# Z
fbox.length = 0;
* E2 R' ^+ i k' x0 ]) g1 L2 V. _" q V
tbox.length = 0;
/ u! b8 l& H0 i H
var c;
/ q2 l0 n7 _; u' z9 T, O, }! ]
for(c = 0; c < arrfbox.length; c++) {
5 v% g+ C# d5 e) {
var no = new option();
+ j: p- @5 }# A: b, G1 _& ~
no.value = arrlookup[arrfbox[c]];
* w n. a! R: k* O* q! V
no.text = arrfbox[c];
+ L- q. B5 c3 `5 P% v5 t1 Z
fbox[c] = no;
4 o) P+ T2 c: a7 |
}
9 d# f7 K- c) T" W( ]* a: D
for(c = 0; c < arrtbox.length; c++) {
5 r6 U5 s! [/ v8 c) D6 c- X
var no = new option();
# `, Y/ D! q, f) l& i2 b
no.value = arrlookup[arrtbox[c]];
! @9 Y4 ?9 C5 G! I! H: m
no.text = arrtbox[c];
' @9 r9 A% s# `7 J J2 v
tbox[c] = no;
4 }0 |+ X0 `6 U) _6 S& a0 A* P
}
, V1 g) S O3 i3 R& C
}
' T9 i, ]3 Y; ^* \) y( B
</script>
- F: I5 ?: a! G; M/ o5 S
</body>
( e; O6 I0 U& y: z1 @0 b( J
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2