标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
1 g( a, F7 u) y, U9 ^/ N6 j
c pageencoding="gb2312"
% Z+ j2 q* k( ^5 K
%>
1 W) A/ `! @3 F8 |
<style>
5 u8 e j: H& a* `0 b3 b
.f9{ font-size:9pt; }
0 x* @. `( r3 {$ |+ o9 R
.bgc{ background-color:#aecaf9; color: #0033ff }
2 p1 ]. C9 ?! Z
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
& w$ ~. L0 w0 u$ [' u7 z
border-bottom: solid 1px #4e7dc1;
! k' K) [4 N7 {
border-left: solid 1px #aecaf9;
3 I) f3 R$ i1 Y/ x
border-right: solid 1px #5679bd;
" u3 Z2 {4 I8 m- S# b. ]7 I1 Q- G
padding:1px;
" y1 q% L% i/ e4 W6 r3 B3 Y9 s
margin:0px;}
' l8 v, J$ G9 C* A8 O* y" `: s
</style>
6 T' k! ^1 ]& q* e7 F- n7 u2 Q. z
<script language="javascript">
% r9 \. S, W9 V
<!--
) E3 }* h2 q/ ?3 j% k# c3 R1 M
function rv()
) { B; R5 I* J) `
{
. x+ S7 k) f4 F* q7 }' T" I
var val="";
* R. ]+ V+ p/ ]8 S! _+ _, _
for(i=0;i<combo_box.list2.length;i++){
; e* p. o. W& a7 g7 ?/ i4 E! \4 \0 L0 I
val+=","+combo_box.list2
.value;
& K0 Y! b' u: l0 m
}
2 N0 V. J* ~ g1 h7 t2 R# Z! o# V
if(val.charat(0)==","){
; I/ l r- ]5 P9 X8 ^, R4 q
val=val.substr(1,val.length);
1 F% z" b8 O' V9 f9 Q
}
7 z- P5 Z* _4 n9 o# K x
opener.form1.frecname.value=val;
: y5 k( q! D4 b, z1 _+ d; \7 B
self.close();
( k2 s% g: |, s/ Y9 D! d
}
- S6 d+ T( `. I; h
//-->
# s M' h i. `2 Q+ V3 U
</script>
6 P `- q4 ]2 C+ }7 m; }
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
2 D6 m6 l3 X/ w9 J$ x
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
* i2 U& q: r- z7 X1 y( N
<%
6 s* @* B3 g6 N- P8 o) i" O, e
cdatasource ds=new cdatasource(); //数据联结bean实例
$ S+ d' L1 Y" F K& x% x6 M
java.sql.connection conn=ds.getconnection();
6 i y* J& ?/ U& ~+ K5 |
java.sql.statement stmt=null;
' D* B6 T) e7 p9 s& A. ?& F- j
java.sql.resultset rs=null;
2 ^6 ]' x' {# H) q. L8 s, Q+ m
cdatacheck dc=new cdatacheck();
! | I2 u/ h+ a! J; z
%>
. M8 N9 B) Q! a5 X$ H/ w0 I+ o q
<%
$ B( I2 }4 } O1 V6 G
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; U9 X: u$ o* n6 S
stmt=conn.createstatement();
z' @1 m$ `+ M2 S
rs=stmt.executequery(sqlu);
% E$ y5 v* i, V7 P) z
%>
$ _ L, e* s4 G2 X
<script language='javascript'>
& d* k! l# Y) E5 x9 u
arr = new array();
* @6 x# G" j2 H9 L
<% int temp=0;
: f C1 d7 G( i5 ?
while(rs.next())
# h% F, s8 y' G+ ^4 {3 K
{
5 A: @- L4 A _9 a0 h) E
%>
}) M5 c: F0 g) U
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
* S3 [1 u: q" C
<%
/ q8 ~5 i5 w8 W$ O
temp = temp + 1;
) n) L9 T& R- Y
}
5 Q( F/ e4 o6 ]/ G* f
%>
' ^% u. M; H( u$ Y8 h- a
temp=<%=temp%>;
0 h: G) J# q# N
function changelocation(id){
# X0 o8 q; F1 R/ ~1 Q
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
& @/ y% p; A3 ~& X( S s% ?$ ?
var i = 0;
( _" L# f1 Y9 w! ~; f: ~% V l
document.combo_box.city.options[0]=new option('-------','');
! F! H3 H h& K* D8 z8 ?
for(i=0;i<temp;i++){
3 m8 X9 B! u4 F7 Y" W# \# b+ E
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
# o. H) H/ A) p$ I4 T3 W2 U
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
3 B% R& ~7 Q8 C6 |( z9 h/ v9 t8 O
}
4 o( `4 D/ ^+ e( B# }; }+ k$ b( T
}
2 Y- {: Q2 n+ M* y2 {; W A3 k
}
' z8 E6 d7 G: }# l3 B, I
</script>
$ q/ u! n0 G# U+ J4 y( m( W
8 Z$ R2 E Z3 M
<form name="combo_box">
" M5 Q. M& M o5 h$ _/ Z5 C
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
9 J ]- K0 ~2 o5 M) J7 k: h
<tr height="24">
8 |$ W- z- N5 V0 X v2 ]
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
6 Q5 s8 Z1 [7 B' o, z5 s
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
8 s+ X8 m- w* a$ `" P: H; O) `# Y
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
* f" p; A1 a! \! s
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
9 S8 T( y5 V G; r8 F
</tr>
- g0 l, l* c7 h- {2 G
<tr>
: ^# h3 ?; k% O6 k+ ^
<td>
, j& k+ I: m: A+ Z7 G2 M" Y5 d _# h. `
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
; |+ S6 _: Q% e4 `
<option value="0">请选择部门 ---></option>
& [$ p7 z$ ^" x8 @
<%
( k/ h: G5 F2 l
string sqld="select * from tdept";
7 E/ @7 q0 K s. g5 R6 D
stmt=conn.createstatement();
: i+ l3 u% G# x- a
rs=stmt.executequery(sqld);
* D3 Z0 n8 i ^; n, f
while(rs.next())
: J r) {4 |( `# ~- U: b b
{
: N, b9 L# L3 Z" ~7 K" b
%>
3 P" R" Q1 A9 J: _! v4 k
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
( N) W! Q9 s. i3 J- C5 C2 b9 I
<%
2 A8 F2 C& }! S- P1 C; s' n2 `
}
& f0 f* ]2 E- b# y% D0 s
%>
4 A0 T& Y* i [/ v. }0 S k! q
</select>
% K& L/ X5 F# ] D
</td>
2 j' U9 P3 U- g& v7 w/ d6 `" r
<td>
2 c" @2 b& u6 w9 o* _2 r" p
<select multiple id=city style="width:150;height:200" class="bgc">
/ r5 M- ?( ^- w W2 i
</select>
! r* k0 T0 |" w1 ]8 u0 ^4 z
</td>
! H2 M0 a9 I: ?( P2 m
<td nowrap align="center" class="bgc">
9 L0 e; K; A @) V: z1 ?7 x
<input type="button" value="<<" class="buttons">
! n7 K# Z) s# m0 F' k) V% A
<input type="button" value=">>" class="buttons">
! |* V' s% Z( ~
</td>
& t. a2 }1 T* y& K0 Y8 ?; h# r$ x
<td>
b) C, ?* H# f5 l. C! r) T
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
4 n: }! ^. Q4 `* q
</select>
5 H3 P; D# `7 q7 t; l
</td>
# k; Y' c$ W3 D
</tr>
1 S0 @% \( W {1 `/ a
<tr class="bgc">
9 V, |, q! p5 ?# M& A
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
* r, ^: l& _9 u% @% B2 ~: U2 T6 v. j
</tr>
: E d; m- U) {7 w( ^6 Z7 Z; {; C5 v' S
</table>
6 K7 [, b6 \0 z9 O! }& e
</form>
% i5 e2 {: Y% x) S, ~' ^) e8 p! W
<script language="javascript">
9 @. ~( `9 K( k6 h
//人名移动
. U' }* b* Y1 R% W/ I, `" V
function move(fbox, tbox) {
* }3 d' @& G6 u: h
var arrfbox = new array();
! U; c9 m( w* P2 }6 _
var arrtbox = new array();
+ }# U6 I* B3 K& c7 E
var arrlookup = new array();
1 L* N+ J; C0 K" g, O {
var i;
5 P% ? t% X" J* h
for (i = 0; i < tbox.options.length; i++) {
# J' y. C: `$ {& ^% W; M
arrlookup[tbox.options
.text] = tbox.options
.value;
8 _: F" h2 J5 T0 h) N0 l3 T/ v1 J
arrtbox
= tbox.options
.text;
+ M6 Y3 p+ B3 J" W& B7 U+ J
}
, I n% |9 Z. a- \
var flength = 0;
p& T& h% D ]1 g4 a! a
var tlength = arrtbox.length;
2 K- b! K8 u5 T7 M+ q. e; c
for(i = 0; i < fbox.options.length; i++) {
' v/ H$ C' u$ ]8 L6 p0 S
arrlookup[fbox.options
.text] = fbox.options
.value;
1 d2 F F. g! Z6 ^
if (fbox.options
.selected && fbox.options
.value != "") {
; e) a) R& C4 A+ T+ P; e4 f1 H
arrtbox[tlength] = fbox.options
.text;
$ P" g0 k5 m& m j$ J% [4 O a
tlength++;
% d) h+ ^; |7 |1 }
}
1 C1 Q# T& a" y* A3 W7 `
else {
# z; |5 o# }& A
arrfbox[flength] = fbox.options
.text;
! B. i! y( {5 A: v1 O
flength++;
7 o& I3 ^3 B' e; H2 {6 L" l
}
H" r u* n6 d% P! }
}
$ {" w. v% o" G( ~& w
arrfbox.sort();
- [) a; Q; n' F* Z/ ^/ H
arrtbox.sort();
" f2 i& M* y: ] E3 F, o+ w, f$ Z
3 H; h2 r2 n- ]( O& \$ F
fbox.length = 0;
; X5 a5 f, Y ^# c' ~6 a% L! C3 x/ b
tbox.length = 0;
2 j1 ?% s7 v4 N @, i9 ^
var c;
& n% e1 e( X3 ?3 @9 T/ a
for(c = 0; c < arrfbox.length; c++) {
) |0 p: M B6 h# W4 K* H# ]9 e1 A1 s4 h
var no = new option();
; l8 @! J! X" x# Q( T! l
no.value = arrlookup[arrfbox[c]];
/ _7 `9 v# B" U& M! C2 O
no.text = arrfbox[c];
) o; ]$ h% W+ ~3 s4 \# F0 g+ o
fbox[c] = no;
) M% ]9 i1 |5 \
}
+ c% O7 F. ^) W
for(c = 0; c < arrtbox.length; c++) {
. M( `0 D4 D9 e$ H) [9 ` V
var no = new option();
8 |6 v# z; i5 Q% e2 b: T7 X; q
no.value = arrlookup[arrtbox[c]];
- t4 D2 w+ R/ m, f
no.text = arrtbox[c];
, ~6 v0 \ F8 f' O: t+ C, _
tbox[c] = no;
9 i: }* t! B5 n, p
}
6 @! Q h: ^- a( b, E, Z
}
# c8 z, A+ m3 b, l( m' j1 L) H: S
</script>
3 u# i4 p& M2 f6 e
</body>
7 o8 t1 K2 @/ ]
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2