标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
' T: \' }. y6 B4 I6 Z! _% u
c pageencoding="gb2312"
3 T/ N. n2 c7 a% h& o% d- S
%>
# Y/ h1 ]$ s' ~
<style>
; [; a! x# m9 [4 j6 D
.f9{ font-size:9pt; }
) R$ `, \' w' A' m/ ]" q' Y
.bgc{ background-color:#aecaf9; color: #0033ff }
- |2 {% y3 d8 [* q, f- _; H
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
: m) ?; d8 ~7 h0 ^+ O' {' z% v0 i& k
border-bottom: solid 1px #4e7dc1;
2 ^! ?1 H, _! w* c, h1 i, q
border-left: solid 1px #aecaf9;
5 O$ @, W3 e9 J3 a7 X/ H) T) Q
border-right: solid 1px #5679bd;
9 o) K3 {+ H6 J" k" a6 C
padding:1px;
2 `6 t8 E. n! e: {! v
margin:0px;}
% w3 j+ N9 [' Y' O2 F7 e- F
</style>
* a7 n; Y0 L7 i9 R# Q
<script language="javascript">
9 O: i5 h& c/ Z
<!--
" K+ C4 x7 R1 A2 N
function rv()
4 }. C2 |0 b- [+ O
{
" [9 y/ t3 I# G; u! `; | h1 x% @
var val="";
$ |( q% P+ N( `+ N, I7 e
for(i=0;i<combo_box.list2.length;i++){
8 ^2 d6 L- F$ R0 B% W* b7 n
val+=","+combo_box.list2
.value;
8 v4 {+ o2 R* Y. P. w
}
- u3 L2 P2 W* y5 T3 ~8 q/ z) O# L
if(val.charat(0)==","){
, s" U% p ?: J) S c9 p$ d. F
val=val.substr(1,val.length);
2 [7 G3 w+ b5 X4 k! Q. x& j# b2 T, |
}
( |3 X" x) T: _- L* ?
opener.form1.frecname.value=val;
) Z- g/ j1 i1 q# A, J! Q5 H4 @
self.close();
; ~5 O4 b3 u2 |1 |- l/ I# t8 H9 C
}
" A, w! N7 s( {. |- b
//-->
# |3 g# P1 ]" w- W+ B
</script>
1 B2 u: F! N" d, y& e: g
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
- ]8 \! N5 @& [& {7 p8 z
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
5 B1 A0 e) u% x! z
<%
2 u4 l7 S2 l+ B+ ]1 c+ S3 F8 @( e& Q
cdatasource ds=new cdatasource(); //数据联结bean实例
6 }+ V R9 t5 q; k
java.sql.connection conn=ds.getconnection();
* N" k- D+ u5 I
java.sql.statement stmt=null;
0 E& P: |1 t1 P' w7 Z( H6 S
java.sql.resultset rs=null;
4 O J G4 ?( _7 f3 |5 u
cdatacheck dc=new cdatacheck();
( K" q) x8 m; }6 F, k( _
%>
6 H1 n8 a- q1 }8 L
<%
! t7 O2 z' i1 e0 Z" N4 _2 d
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";
# `' G9 b. }) T, O
stmt=conn.createstatement();
+ A6 P) r) x9 `# y' a
rs=stmt.executequery(sqlu);
+ k# O5 L' Z+ R4 Z9 D8 l: y' {) h
%>
R: H7 c2 I% ?. `7 R \0 [& h' W
<script language='javascript'>
" D" R- \, \% `3 p! Z( V
arr = new array();
. _+ n8 n w6 W
<% int temp=0;
/ y* H" p" Y( |1 M' c' a
while(rs.next())
: q+ B* l. |6 ~7 d" C; g c5 z
{
+ ~0 Z8 a9 a" j; p5 t6 \
%>
9 R6 P3 b4 N% M; X
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
7 I$ Z" ?3 s, S* F8 R& R/ s/ O$ N8 T
<%
' g5 e X" @- p/ {: z* o
temp = temp + 1;
) P* ^* w, {& n8 {; Z
}
" k! d; {/ x7 }$ h6 h. ^
%>
2 Q' X" ~3 A* e8 D
temp=<%=temp%>;
( M4 S8 a5 E) A, X4 X
function changelocation(id){
9 d% F- y- S' I" Q
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
4 t6 ?' _7 Q* Q* k/ r
var i = 0;
# f8 q# _) l0 W# r/ m5 V
document.combo_box.city.options[0]=new option('-------','');
9 m+ t7 y. u4 {% g
for(i=0;i<temp;i++){
/ Y# y' d7 a# ^/ o2 w9 p4 p0 Z
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
8 } j8 b/ y2 d( U U# B& Q
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
& z( d6 o% Z3 ?2 x8 ~; `3 l
}
& _* J: h5 e5 Z) J
}
3 B' W, c8 ^" y! I& Z6 Z: P
}
' I5 n! J5 P6 g+ W( N/ H
</script>
' ]5 Q9 }9 v8 W0 Y+ `( R7 g
1 i7 w+ v! z+ O3 \' ?
<form name="combo_box">
5 ?8 o1 v4 h' F; w( }6 N
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
8 |- S7 L( c* S2 S; I
<tr height="24">
/ R# q! h# j @- _$ q* u
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
, t2 m" ?' s, D) \4 y( F9 L+ W
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
& s+ T2 P5 z2 O, k% l( G
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
% G6 J& y k8 T" D
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
1 T: h$ V- ~7 ?. g+ x
</tr>
+ f* A% D8 f `: ~- I% i1 N
<tr>
; i7 k; R/ I. M1 N1 q& ^# Y
<td>
* j6 [' T, E4 g
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
6 M; n- q8 M/ ~ ?; p' G) r
<option value="0">请选择部门 ---></option>
9 u1 a! k4 s- U3 H/ X8 ]/ B
<%
) ~3 U* a2 o9 R0 i7 g3 R( Z* K
string sqld="select * from tdept";
+ J/ {4 w8 h# J- O
stmt=conn.createstatement();
9 v1 D2 s9 y% z% q7 f/ W) G
rs=stmt.executequery(sqld);
) C1 M6 \& A% q% ?
while(rs.next())
1 t- T8 v" G5 I" X6 t
{
- P) z( J9 [6 \! a! _) f
%>
6 {) d" W' R# F8 F7 i: N2 e8 h
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
; q9 Z& p: y+ ]. d* ^( S
<%
9 ]( `1 a% w6 G& q$ ]; [0 c
}
7 @" Y% L, d* x
%>
6 b! O5 k; \( z" `1 B* e
</select>
1 j7 z8 x2 [2 J* I) n( X/ c8 c
</td>
3 Y4 I' h9 L# i4 H* u
<td>
2 ]: S7 C: ~: G( S [
<select multiple id=city style="width:150;height:200" class="bgc">
5 n- R/ V: z, {: X2 O* m) Y
</select>
) F" d0 h8 A7 a, V3 @* V, N2 q2 m
</td>
- O0 Q) I2 S. K) K
<td nowrap align="center" class="bgc">
3 d! @/ G8 v- Y
<input type="button" value="<<" class="buttons">
/ q9 w1 @3 o) n F5 T" _2 i
<input type="button" value=">>" class="buttons">
B" p9 [; t' `1 D3 F
</td>
! Y4 X' V" M2 O r8 c, c
<td>
, E: u$ A; {% _
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
0 c. Y4 @) J) a. v. q3 u. O! a
</select>
. L; w; C9 c0 B5 {2 F0 ^! _
</td>
2 p! L, w$ o) f/ J: A
</tr>
* X9 l5 e! m$ s* l: y8 l
<tr class="bgc">
* W* _) o- L2 I
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
1 S1 p) P( k3 R* O( e9 m
</tr>
, Q( X7 ?4 l! K( u2 l' ~! s
</table>
5 L1 W+ ~% w# N5 U5 u" R8 A
</form>
/ f: G6 I: [+ z8 n, Y2 F3 y: @
<script language="javascript">
/ s2 M! i& K/ u/ H5 S8 `
//人名移动
5 |' L* b4 f! u+ M
function move(fbox, tbox) {
& y8 J! \$ ?3 H! H& R# m
var arrfbox = new array();
8 |5 D- e( D5 N' A" x8 l$ @
var arrtbox = new array();
0 J8 j+ ]6 r" O5 C: S
var arrlookup = new array();
( ~# o+ m3 A+ a; I" E' g
var i;
* J3 w" O: y, f& L; h/ H
for (i = 0; i < tbox.options.length; i++) {
, H( |9 ] u c9 K m
arrlookup[tbox.options
.text] = tbox.options
.value;
, L p; s4 n6 n9 Q) D9 { v, e
arrtbox
= tbox.options
.text;
6 O+ P0 E* a: W! Z
}
- Z9 r) d6 T0 ]1 {$ [( S: t( H
var flength = 0;
0 Z& k, \& T. I/ m5 f! y
var tlength = arrtbox.length;
, Q' I& @; n+ v0 \. {
for(i = 0; i < fbox.options.length; i++) {
# P( W3 h3 T g
arrlookup[fbox.options
.text] = fbox.options
.value;
0 `/ T- [9 \: k; ?) W) D
if (fbox.options
.selected && fbox.options
.value != "") {
) {9 n+ X3 C0 a- H+ {4 Z9 x
arrtbox[tlength] = fbox.options
.text;
n3 k( e# Q% O. T% t: w
tlength++;
6 G4 k, ?/ S F; }# w8 r: B: Q, g
}
8 W+ K7 |! V( ]
else {
* d, y/ [1 u( O. L- X9 _. d
arrfbox[flength] = fbox.options
.text;
3 w2 k0 T( Z( u! {+ W
flength++;
P' ?% u! F: Q* Z, T& U
}
' }# k& k( q1 _
}
. D3 P$ I/ z5 D7 w r- q3 s8 r
arrfbox.sort();
, I: P1 g! ]3 H4 c$ C" d
arrtbox.sort();
W2 ~! b! B* }' x
" A+ H$ X' `: P2 X; H( A
fbox.length = 0;
: q& ?& X8 x% K( b6 \0 y7 o- C
tbox.length = 0;
! s5 L5 C, g: y! Z4 X. k+ c- R9 D
var c;
& l& O0 b" A) S" c3 |8 I
for(c = 0; c < arrfbox.length; c++) {
! Q4 V8 y% X; E3 L! F& O8 O
var no = new option();
1 u, ~# Q- @3 m. X! J
no.value = arrlookup[arrfbox[c]];
C, |! C( ^/ l% H& S
no.text = arrfbox[c];
7 B9 s: K- \$ K" h
fbox[c] = no;
1 h2 H: O# Z e' O$ Q& p
}
) q/ e* [! _& H' m6 t
for(c = 0; c < arrtbox.length; c++) {
, @% |) a4 r6 r
var no = new option();
0 X# Q! Q$ @: o1 x, a2 v$ _3 M$ r
no.value = arrlookup[arrtbox[c]];
; l' {0 U+ K4 @& |
no.text = arrtbox[c];
) C0 R, _1 R% k, y' Y
tbox[c] = no;
1 N6 ^6 p0 }. E; V# I' X @- W
}
; B* F" ~- u# q6 J6 S8 C
}
+ s4 Q! s1 t4 n* S
</script>
9 S1 U# ~ i* b7 j/ b
</body>
6 F* F7 T; ]/ _) G* z
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2