标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
7 R8 D% V( Y" ~% P* n! h$ L
c pageencoding="gb2312"
' u) |& Z/ u4 i: @% h: E9 S
%>
% ]/ g1 L! e, H% I5 o9 I* |
<style>
+ F9 `1 i. e7 i8 x" D
.f9{ font-size:9pt; }
1 Y! b0 A+ q3 ` I
.bgc{ background-color:#aecaf9; color: #0033ff }
& L4 k; e( D2 o) ?
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
# ^3 I' k; O j/ y9 C" ?
border-bottom: solid 1px #4e7dc1;
8 z! I9 x! M4 w1 R/ M5 v
border-left: solid 1px #aecaf9;
. |- V. C0 p7 I- n' O5 \
border-right: solid 1px #5679bd;
. s* C+ y' H! s, {6 ^( _
padding:1px;
( K! P; t @" H9 u" U; ]; r, B" g
margin:0px;}
" l( [2 u" [; K8 G" {1 b. q
</style>
7 [/ ?5 Y) y Q) A% ~3 K1 p
<script language="javascript">
1 N6 \) ^ `, k/ f% y k8 P
<!--
( `2 V) L8 _; v F& M* y
function rv()
1 w: ?- Q o! s2 H. r! s. x
{
/ P# F1 Y: H" k# M
var val="";
! r9 ]) D5 x* _: E& _5 U- r# w
for(i=0;i<combo_box.list2.length;i++){
# h" J8 f1 w6 l7 j. d' P
val+=","+combo_box.list2
.value;
5 B2 a" s* q3 B0 F8 H
}
& [5 q$ S: N- W) {4 q
if(val.charat(0)==","){
# s4 [3 ~/ b8 a2 X+ r/ n# |, ~
val=val.substr(1,val.length);
" j* R! r M. l! t2 ~/ _6 I
}
5 C! U+ F3 x/ v( `
opener.form1.frecname.value=val;
* k+ Q* u* m e- _/ `9 l9 @ e
self.close();
; i4 T1 b: f" m$ C. \! h
}
e' [5 u, z; Z, S( G
//-->
3 P6 B( N: Y$ g* U, P F' Y
</script>
1 u8 l* X, L4 n Z* S& H! o
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
1 F/ g7 Q2 N0 F3 T
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
8 @; _3 N* _+ o# [! _0 r& q
<%
* C& ^7 A3 a" {% [$ ^& f5 l
cdatasource ds=new cdatasource(); //数据联结bean实例
l* f0 Y$ ~& h2 q
java.sql.connection conn=ds.getconnection();
$ \; j( d/ d9 U. S
java.sql.statement stmt=null;
$ A1 x. {8 V+ }$ u- S/ X- X. |" x0 |1 T
java.sql.resultset rs=null;
- {! y8 q% E$ F1 A; a
cdatacheck dc=new cdatacheck();
7 I' z! Z8 t9 u7 f
%>
, _& ?3 ] s+ c$ J6 S9 Y4 s z3 {
<%
0 `7 O% T. P+ k
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";
/ m, c3 J$ S o# E& Z. B& ~3 |
stmt=conn.createstatement();
1 w( @' d" z! C' M6 w
rs=stmt.executequery(sqlu);
; w5 t3 a9 j" k
%>
, d `+ l8 o: w4 H; v2 {0 o
<script language='javascript'>
( N+ G7 j* E8 G# a4 a2 a( K5 J1 A! [
arr = new array();
3 Q, q R3 v) ?. m! F
<% int temp=0;
* f( S r) B p$ j l/ t+ q! T
while(rs.next())
0 Z# j. F; y; j; I' q
{
7 N; ` d6 b/ j0 s' V' Z
%>
& }/ M+ d0 k9 f' y, k- p; e
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
+ o9 x7 z- P' [+ I
<%
. |0 S! R5 E f, O4 r6 X
temp = temp + 1;
5 @; N( d; T& W; Y5 f Y
}
& q8 P7 y: w2 _( M- m1 S
%>
+ K1 F: x/ q" ]
temp=<%=temp%>;
: A# [/ K {, ?
function changelocation(id){
! {7 t/ k+ |$ c' X, \7 s9 C: d
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
8 E3 r/ C0 y, f% L6 S+ z
var i = 0;
% s8 R$ M0 C0 C8 g; G5 R5 x, h v
document.combo_box.city.options[0]=new option('-------','');
2 n0 {7 H8 J+ x0 F( r% K" k! D
for(i=0;i<temp;i++){
+ F g& Q' O, I
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
% m# {, A, P9 _+ v
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
5 P. [" p& u/ r E; `
}
# d6 p+ _8 J9 t* L+ a: J* m
}
$ b4 @3 u3 x# p7 F0 p
}
' m5 m( }; s# G+ n3 I2 j: A% r3 z
</script>
, f, `% @2 x* ?) O0 P
+ e' ]0 _- q' D I5 ]
<form name="combo_box">
/ q- r! a9 {! c7 l# C, q
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
" x' h& T7 c/ D. ]# s( g
<tr height="24">
( L* d/ t( |# k- U9 m9 u. V
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
% Z2 @& O; f4 X0 Y! {! H
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
% v$ V, ?/ k4 d# p7 Q
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
) p* J5 m5 y9 d; `: y. B
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
+ c9 P3 T% L8 }( c" \6 B- f* Y
</tr>
% M7 a$ A E+ U ]) m+ G
<tr>
1 P _3 w8 g z' i8 G8 ^
<td>
" w3 T9 y# v8 ]( O! X/ g
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
5 C* Q! w( j7 h. G( ]* k9 X2 j
<option value="0">请选择部门 ---></option>
$ `1 D) `. c9 H& r" R- T9 B1 ]& z' L
<%
0 S* W/ I; v$ Q) A: I* M
string sqld="select * from tdept";
4 n0 S( n; _* ~# O1 E
stmt=conn.createstatement();
+ C" O; Q6 U$ @! |) F
rs=stmt.executequery(sqld);
w9 v/ j3 f/ g9 v( a. A# s" S
while(rs.next())
9 l' E6 Z, v6 N
{
) m+ @5 Z' a, u6 _- W K6 ?
%>
- R% k- a" q1 X% o3 b! C3 V L
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
: P9 d( p% n# Y! H7 n
<%
: r3 e1 n, o5 G3 r1 l5 m
}
) {8 L6 I6 e& R4 |0 {$ i _
%>
9 c: b! l! N* z3 |7 P
</select>
( U, v3 N& H7 E6 a. U
</td>
& [- S; D9 N% }; R' T9 Z
<td>
% K% J: }3 d' B; f6 \2 y
<select multiple id=city style="width:150;height:200" class="bgc">
9 s* O' J* R! ~7 _# M. u r1 I
</select>
\; f# q: G2 n: q2 f/ O
</td>
- v1 b1 f( I$ o S) }. r
<td nowrap align="center" class="bgc">
6 L( @' { |% _% O4 K/ S1 m4 P
<input type="button" value="<<" class="buttons">
9 M+ J$ H: z+ F4 Q/ b
<input type="button" value=">>" class="buttons">
$ T& ^4 A, r/ j" |" u9 W+ `
</td>
0 w3 h: T! @9 J
<td>
) C* i$ v3 t7 ^4 n' z
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
' f y* M' ?) Z1 t1 q
</select>
& |1 h6 E: z J: c- F: }3 K7 }
</td>
, _4 K, H/ Q, s; U6 z) J
</tr>
! P2 @& ~% [' Q
<tr class="bgc">
5 f7 A( i `" A* j5 v) Q! ^! s5 z# w
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
* g% E" P# ?6 X& q: I0 M4 H. E% ?
</tr>
. j( k& k. O+ r+ w2 a7 q
</table>
" y# U& g/ I% \( X
</form>
" O* Q {) f2 m5 L8 a( M `
<script language="javascript">
2 ^7 ^2 `; V5 K
//人名移动
- t; Q2 u7 e6 ~0 ?& y) i! ^
function move(fbox, tbox) {
0 T: r" e$ D! _% I+ E$ }) C/ \
var arrfbox = new array();
. ~% k7 l m I+ A- Q7 f+ s
var arrtbox = new array();
. t9 T+ @8 X9 b8 @0 W8 X
var arrlookup = new array();
8 G& P$ ~* G4 d5 g
var i;
' N; m& Y, }2 U4 }6 `
for (i = 0; i < tbox.options.length; i++) {
* k: N* L$ |1 ^( Y! V/ M' E
arrlookup[tbox.options
.text] = tbox.options
.value;
. e! f8 C0 L! G3 K" {
arrtbox
= tbox.options
.text;
# H6 L8 S* I% L# y* F$ i- H
}
* ^' M1 A, a8 x% a3 }
var flength = 0;
j: ^* q6 b, u% \, B; }
var tlength = arrtbox.length;
9 F, }. j H" E0 p% x/ b- m' ]
for(i = 0; i < fbox.options.length; i++) {
! M3 |0 d3 A( w1 }& P/ e1 p
arrlookup[fbox.options
.text] = fbox.options
.value;
2 t1 c! D" K5 ^. N: A/ a- b, F
if (fbox.options
.selected && fbox.options
.value != "") {
) y: T' w% P# C- g: U6 q$ `0 [
arrtbox[tlength] = fbox.options
.text;
7 H9 `8 n; j+ J+ ^ F1 K
tlength++;
% m0 ?' w$ A# w2 ?. ^; J$ O
}
. y* }/ r4 t0 S3 a
else {
& j; y& j! Q* F; f2 q6 _
arrfbox[flength] = fbox.options
.text;
9 s' w, T# P; r
flength++;
4 z; E! I& G Y) }+ K
}
7 i& {# I" c7 a( S7 b
}
1 C7 ~; F8 U2 D- j0 A% I
arrfbox.sort();
. T1 R w4 [; B; q+ B
arrtbox.sort();
% P/ Q' R" w5 q' g$ h$ u! D
8 |- \7 _& y( Y! ]
fbox.length = 0;
2 Z; m7 e1 K) [( {/ E
tbox.length = 0;
6 m' w$ E" H( n( G% U
var c;
3 X$ @0 H8 ?/ f i7 E
for(c = 0; c < arrfbox.length; c++) {
& ~' u/ |9 i5 h( t% i1 k) R
var no = new option();
! y! w# O, O- F
no.value = arrlookup[arrfbox[c]];
5 k7 l& h: `3 t& m
no.text = arrfbox[c];
% C1 `7 S3 S2 ] w
fbox[c] = no;
0 R8 J, w1 ?" m% a+ e/ w
}
: M2 [; p/ h' m+ @ x. G
for(c = 0; c < arrtbox.length; c++) {
7 q4 o7 z% V6 U; H/ a
var no = new option();
4 R& _/ `3 L2 C; g
no.value = arrlookup[arrtbox[c]];
/ E6 M0 k* _$ F" ]' ]2 a
no.text = arrtbox[c];
$ y" L7 V! }0 a8 Y! z
tbox[c] = no;
7 v, [8 y! g8 z
}
- }/ a' C$ \1 r( V
}
. Y* j, P+ \% M( @! R( t' `
</script>
% p% X+ U0 ]9 l6 d9 C
</body>
* s0 ?* A: i/ B
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2