标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
" |) A+ L6 g6 {% P! i
c pageencoding="gb2312"
& g# S, a( {; e9 j
%>
0 {2 b: r% E- p' g
<style>
. \5 C! e F& \6 a
.f9{ font-size:9pt; }
6 f2 W( W+ H2 |* Z6 N9 T
.bgc{ background-color:#aecaf9; color: #0033ff }
7 i" o1 C% Q& @! A+ K
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
3 O; \) K7 ?; L5 z1 Y! v" K
border-bottom: solid 1px #4e7dc1;
9 b0 j2 c5 p( }
border-left: solid 1px #aecaf9;
4 C; S3 j0 ?# s) W) ]+ ^% U
border-right: solid 1px #5679bd;
' T. h9 {* Q; o: w0 z% m
padding:1px;
# Y+ o3 P* W* w$ t% k
margin:0px;}
. E/ a0 X R6 ^( h1 V1 L# Q/ O
</style>
& b; D5 Q8 l: h5 J) Z& x+ d2 `
<script language="javascript">
: R, ] P! F8 H t
<!--
3 D0 ?& h! N3 w$ X$ W% {8 _
function rv()
. x- E) u2 j) F- E1 \0 N
{
+ `( S( g% Q8 e4 G! _, }3 |
var val="";
) E1 Q; P, ?& I, P& S
for(i=0;i<combo_box.list2.length;i++){
/ K/ [8 Q6 ^1 C) `3 @- V9 }
val+=","+combo_box.list2
.value;
7 Q; a: ^1 }1 g' \
}
& x# V; O A. X" x5 w
if(val.charat(0)==","){
! I T1 t+ C0 c7 W, k! L
val=val.substr(1,val.length);
! V v1 L: ?- E2 C' S* u2 Q
}
8 Z. |# ?' ?! ^
opener.form1.frecname.value=val;
2 ]3 U4 [7 k) I1 L8 r# R% }% ]
self.close();
, e& G+ J( b. z) m) ]
}
# V! i. u4 y, k. v
//-->
, z& A. z/ @& ?- x
</script>
. p; Q9 q4 Y- L$ l
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
9 c4 W. y0 X, r: o% s
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
O: W I6 |/ X1 F% ?
<%
: Q+ D& `& i- l& ^4 ^+ c! c+ Q' }
cdatasource ds=new cdatasource(); //数据联结bean实例
. p- f' h1 ~1 a
java.sql.connection conn=ds.getconnection();
+ A4 e; z8 V4 Z
java.sql.statement stmt=null;
2 \$ d7 I: j6 \, K e& k
java.sql.resultset rs=null;
! v* q F5 K6 W3 J8 Y
cdatacheck dc=new cdatacheck();
: _; O0 |; ?) W5 E
%>
9 a( [0 W6 ]3 Y9 h
<%
# c( a9 c9 p l3 h/ r- @
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";
8 e1 d0 N( x L; g: b
stmt=conn.createstatement();
8 W" s& o* U2 z+ L1 ?" J |0 f5 U
rs=stmt.executequery(sqlu);
) l" L7 Y8 T9 h6 a8 {- V
%>
' N* L1 B5 H/ d4 l: v& j
<script language='javascript'>
7 x2 i7 o7 t/ f# D
arr = new array();
8 Q/ \, k8 V |" b; H" t2 H
<% int temp=0;
$ B% y) F" {! [! \
while(rs.next())
, x% `; G& L9 t1 J. e
{
! h0 D9 n7 @. W6 X
%>
. Q7 Q8 X2 j; J
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
]7 x: S$ i% B. U# W" \
<%
I( y. a p# P3 L! ], f" ~* n
temp = temp + 1;
& D: g. r. [& z; e) {
}
0 y0 K" p9 w+ n7 b2 }5 t* p
%>
7 |2 s' _: D" p$ t( d
temp=<%=temp%>;
& r" h D: a% S/ h1 Y) h
function changelocation(id){
& U0 O, u/ d$ ]& X4 a" Z
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
/ ~( Q5 X& @7 Y3 ~* t$ ]
var i = 0;
b w( A6 r C% d# n
document.combo_box.city.options[0]=new option('-------','');
; u4 S* [6 P3 D; }' s
for(i=0;i<temp;i++){
4 U( `( {3 O: w5 w
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
: x G d# F/ G& l: c' _
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
1 W1 y% Y* F# p: k( P8 ^; M! Y2 A
}
A. \, t6 p8 \% @
}
* l( a3 |$ @# e9 ?4 a% H; }
}
. n4 n( }+ J: }1 @ \
</script>
8 B- G/ ]+ t8 b5 }9 c
7 T7 \; z& H8 p9 x# `( ]2 h6 T. @
<form name="combo_box">
; b( ]4 o0 H9 i# S# P
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
% H* x. I1 Z& e. B9 X
<tr height="24">
8 ` h! @$ q1 A) x- r
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
8 t: d8 v- J) V+ f1 H
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
; G7 v" K/ Z7 w: ]. u- q
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
3 M9 y2 @* ~. p+ N
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
( ]1 }0 g8 P4 D' h. ]
</tr>
/ ~6 L7 l H' f$ h' E
<tr>
D0 ?0 \8 [( p- J
<td>
. b: g( c/ v# {7 \5 m1 U( K P
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
' M0 f/ o5 |' v% W6 p
<option value="0">请选择部门 ---></option>
|8 k; D, }9 }2 `
<%
, C8 V( q. T1 i% ?, z8 m) B
string sqld="select * from tdept";
0 J6 ]& \" @* A+ |
stmt=conn.createstatement();
4 K$ |4 y$ [! J6 D
rs=stmt.executequery(sqld);
0 N' W0 e: [, Y4 C' D, _6 s
while(rs.next())
1 r; S, x) G9 B, H6 }2 H6 ^
{
8 ~4 c& M; n" N1 ^/ |/ C; C
%>
' _2 m* L: L) i" C2 d
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
9 E; p5 q! r! B
<%
9 q+ T* ?( X$ \ A$ W# L/ B
}
* O0 }( ?0 {5 A. ~5 q' U
%>
5 x. K" M) {0 a5 L+ I
</select>
" d' p7 v; D$ D1 F
</td>
0 G3 o- a6 G9 ]3 Q, P" F7 r
<td>
" l' W% l( }* A3 g. @8 v
<select multiple id=city style="width:150;height:200" class="bgc">
+ h: d& E& z& m. j4 o/ e
</select>
, u# O1 T, t# f) J
</td>
9 w& y3 n2 }. P2 j; [9 t* W& J& ?
<td nowrap align="center" class="bgc">
; w" w* b ^& ^
<input type="button" value="<<" class="buttons">
- Z2 R( N, c7 U1 E6 ~4 v% h+ i' l5 N A
<input type="button" value=">>" class="buttons">
. g5 b u" ~* h; B
</td>
: R3 s ~; A% |
<td>
7 ^) O, R6 Q/ [$ ]/ {( `9 h3 _$ t2 j
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
* T8 t$ a+ Z- k3 _
</select>
- d! W- B6 t2 Q, [' Y. ?/ x+ ^- K
</td>
7 \ @, F, m2 J2 \" O$ z0 g- P
</tr>
# j o6 M% I% Z/ Q" |
<tr class="bgc">
. g8 \6 X2 a; W) b( q; a
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
9 d; ~& G% Q C# e' }
</tr>
% k. Z1 B% d; f$ i
</table>
4 J9 C$ O& u/ a2 s; m% P/ I
</form>
3 R9 w/ v8 L/ b4 x, k
<script language="javascript">
5 K& t% Y! P. n: Q' u, V$ ?
//人名移动
$ v9 [9 V( [* ]4 J! U' n8 o6 `) X
function move(fbox, tbox) {
* e3 k9 l0 v# s; \* S* S1 E
var arrfbox = new array();
7 m% m8 h5 Y) L) H6 a% ^8 w. t
var arrtbox = new array();
! Q& }, f b' f! U% G& Q7 r- G) _
var arrlookup = new array();
. {; x2 J& U% ~/ m0 _
var i;
* X& G6 ^1 D4 P' z1 U
for (i = 0; i < tbox.options.length; i++) {
+ q' x- }! W6 {4 {9 t& z
arrlookup[tbox.options
.text] = tbox.options
.value;
1 U. h* m |2 J$ x
arrtbox
= tbox.options
.text;
% a8 C2 I: I6 c$ r" G# k4 m* _+ e. ]
}
- a7 B) S* E2 b/ g" t Y
var flength = 0;
9 ]$ e: ^/ F. {/ q( X' w
var tlength = arrtbox.length;
+ ~. b; m Z+ S
for(i = 0; i < fbox.options.length; i++) {
1 f0 ]3 k2 d& }% w$ W3 ?8 w
arrlookup[fbox.options
.text] = fbox.options
.value;
% }# `, O4 d. ]; f
if (fbox.options
.selected && fbox.options
.value != "") {
# m* w. k1 F2 p" t1 \* w+ Y7 }/ ?
arrtbox[tlength] = fbox.options
.text;
4 m6 f4 d1 Y+ R, a/ g
tlength++;
- Z3 i7 f5 T% ?* q2 i( {
}
" P* ?/ i" B8 p5 |( N8 y
else {
; m1 Z& Y( M; P* B, |
arrfbox[flength] = fbox.options
.text;
% |2 f5 h/ N; O7 T. q+ o. c
flength++;
; s @! l# @* K
}
( j/ ^$ O6 V# k+ I
}
2 G/ f0 y+ R+ m/ f
arrfbox.sort();
3 j" h/ O' {6 x3 W
arrtbox.sort();
) b2 z3 b9 L0 r/ ^4 }, x
. K8 w* k/ z5 E7 i; W* R
fbox.length = 0;
8 ]% }/ d, |( g
tbox.length = 0;
. A" o1 `0 n; q% a' k1 [! K8 b
var c;
* ~' B$ T) i- ~! j/ k3 {3 |
for(c = 0; c < arrfbox.length; c++) {
: E/ U. U" h# g8 F4 ~, {
var no = new option();
8 t0 G1 L/ S1 c5 c$ b
no.value = arrlookup[arrfbox[c]];
# s( ]- T. ~$ ^5 q* c
no.text = arrfbox[c];
& A7 c/ U/ O6 ] @) X$ `5 d
fbox[c] = no;
0 q. M' g m7 R+ Y7 w
}
' \, I- C8 v1 V0 Y$ Q
for(c = 0; c < arrtbox.length; c++) {
6 F( P8 b/ |6 Y# k* V
var no = new option();
% A8 J0 Y& }2 V b. ~+ |
no.value = arrlookup[arrtbox[c]];
, Z! A w5 u* h. m2 V2 ^9 [9 {0 K
no.text = arrtbox[c];
$ f( O. j; q C7 u- K4 E
tbox[c] = no;
3 D. |5 X8 C3 }2 ?+ B1 e
}
& ?) W: O4 a6 e0 Y2 P
}
6 b0 L% d/ h8 U ^
</script>
* l; h# H) C- A, V6 }' w s
</body>
3 f$ h* S+ y4 m
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2