标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
% Q& i5 `0 ~; V5 N" f0 P
c pageencoding="gb2312"
* z, X4 F2 Q& h7 @+ D! O! ~; x
%>
( \, u' o- A# @7 i- H. H
<style>
" n( y5 s" |7 }0 W# j; n
.f9{ font-size:9pt; }
' x- t2 U$ ^. Z% @: [
.bgc{ background-color:#aecaf9; color: #0033ff }
0 M" L9 {0 p* Q
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
) Y9 X1 O) b8 S
border-bottom: solid 1px #4e7dc1;
+ V- _+ t) J- b$ D" Q) L% U; Q
border-left: solid 1px #aecaf9;
+ `* A: T. e7 H5 v
border-right: solid 1px #5679bd;
4 h s5 M) }0 V% w5 w6 ]
padding:1px;
) e' @: f8 p3 n% @, T$ } Z
margin:0px;}
! O( g- d# H+ w8 U
</style>
1 N: w2 A# a. o! e; _
<script language="javascript">
# d2 _% O; X( `# L+ G" O
<!--
* D; _9 D# P5 n: a) j- Y5 B
function rv()
( r; Z* l& y) c/ b) p% |* P: G1 v8 E
{
g+ N; x3 K& k- r, k+ G( r) `2 t
var val="";
' a( v, w& Y& u% _3 Q; e
for(i=0;i<combo_box.list2.length;i++){
) Z% K$ j) f/ V% y4 S
val+=","+combo_box.list2
.value;
4 n- y% r. G) {& a
}
0 c" W- H+ X% V: l" B# D- B% @
if(val.charat(0)==","){
( x8 g. ^3 L3 d \% l, H" ]" w
val=val.substr(1,val.length);
+ p/ n# @9 w0 j/ v; T7 I6 Q
}
: T& `, P( y2 `+ J7 N
opener.form1.frecname.value=val;
& @) v& b( L0 v
self.close();
4 ?4 B8 ^$ H8 I9 e: C9 M' B
}
. }. ]# }4 F5 |; v, Z
//-->
9 R! O6 q/ R7 B
</script>
5 `/ Y7 L- N+ u% `( b1 Z+ C
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
5 H9 S5 b5 N D$ g3 w) {2 Z
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
2 i6 m# b* w6 t
<%
9 ]8 h# Z. O/ Z- ?
cdatasource ds=new cdatasource(); //数据联结bean实例
8 }. e& p, W; t U' f. U9 Y
java.sql.connection conn=ds.getconnection();
1 f" A: M; O8 s* E0 B& \: i
java.sql.statement stmt=null;
) _. M: s: m2 E) V H! W. Q& r
java.sql.resultset rs=null;
% N9 `3 Z" r3 H
cdatacheck dc=new cdatacheck();
7 b3 ~9 |$ e+ g9 @
%>
( q! u% H/ C" A1 U6 b
<%
. Q# F% d" H& ?" y# R9 |* ]
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";
1 L! M: [. a3 J7 Q$ Z& S7 V3 N' k" G4 C
stmt=conn.createstatement();
: K6 a4 k& A0 l z: _
rs=stmt.executequery(sqlu);
8 @! J% I" j% Z# k& X+ C$ v
%>
/ `3 @: M: u7 ?
<script language='javascript'>
; q, @6 f1 z' O/ a
arr = new array();
$ O) {5 h$ J, N+ @8 t* Q
<% int temp=0;
3 N/ N$ `" X( S. }, P6 p3 h1 `' W
while(rs.next())
3 u5 K% q( E$ M9 g8 ?8 M' Y
{
; _1 c5 F2 b1 }% O, @- E& \
%>
2 N4 u3 Z" A! W8 v, c
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
3 B7 s G# ~7 V
<%
. Q" W R6 G7 f& F6 [
temp = temp + 1;
% L+ K9 }) i& \6 H0 t) I$ O
}
6 V- p: v2 }- T% `! B: [
%>
: A) {# v& ^ |+ M' N
temp=<%=temp%>;
" D. v" w; F# m# p6 ?% ?( t+ d f
function changelocation(id){
( e8 `! b+ O( e7 T& P1 X1 a7 k
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
" t" b2 p: H3 r- I
var i = 0;
( D4 t) B9 {8 Y7 u4 t" t# l; b: i
document.combo_box.city.options[0]=new option('-------','');
7 V4 \' W% Z* _! C% X9 v0 p$ s' k
for(i=0;i<temp;i++){
! z- u4 F- R; A% g5 N! q7 H2 H
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
: u3 T4 p% `% m* y0 H. i0 z
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
9 N' h5 o4 w, J
}
) E$ B1 r, ^5 ?, H1 _6 u
}
5 k! i6 [ Z( L' ]) b) l5 r
}
: v7 |, R7 T$ _" \
</script>
; ]! t# ^2 `, E) K. F! J
0 I6 Q1 Y& Y: g( G0 H' @- q) `
<form name="combo_box">
2 r* x: h3 E3 f
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
N/ k/ T0 l; t) I3 f8 U& M
<tr height="24">
, M4 B8 \' k3 e4 a" t* p3 V2 t
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
$ O7 d& m( L4 r3 R
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
8 c4 S/ ~$ I- x8 j$ |2 z
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
. J7 V; D0 W( a2 O* C$ y& M
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
& S2 f( S7 D! ~, K& X' M( Z. W
</tr>
9 G0 \7 f g; k' o! H
<tr>
# s# Z& }' S3 [$ A$ _0 w! t" f
<td>
% G+ A' O ]0 D5 J
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
1 e% ^5 n; @6 R2 _! y
<option value="0">请选择部门 ---></option>
1 v, ? Q' V' {- C$ i! P5 Y
<%
" F7 b# ^4 i8 w' s0 C
string sqld="select * from tdept";
2 ~9 V$ l5 _# g. }: U
stmt=conn.createstatement();
6 I8 ]1 M& {+ O6 C* h- h
rs=stmt.executequery(sqld);
0 a$ u. D2 y+ M; C3 x: ?& C7 v5 g1 u
while(rs.next())
$ Y) H/ C1 j9 l0 p+ ?4 ]. C
{
$ G7 N( o; b+ K/ v5 H- i
%>
+ i" d6 g) I( t7 z! Q
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
1 H) I8 E- [% ]9 y# h6 r: v
<%
# X+ a1 P) p3 W: A1 ~3 ? V; H
}
2 o, R$ k6 H: P& D) H
%>
/ `- t; l" v5 h' k$ `
</select>
/ B0 S- s8 P; c5 j5 g
</td>
^% c# t0 \2 V) }# a d
<td>
$ f& i4 G4 b7 s2 i e
<select multiple id=city style="width:150;height:200" class="bgc">
, o! L. c! y3 P
</select>
$ r! c% p N0 y6 |" N, L6 Q: n
</td>
) n8 K2 v8 H- {# d/ ] |
<td nowrap align="center" class="bgc">
& T" ?& D4 t3 M- E
<input type="button" value="<<" class="buttons">
' r. W4 q7 q, g$ p. M
<input type="button" value=">>" class="buttons">
) l) W, e: _" B) H2 F" f
</td>
; f; F: T- B4 w v N: E4 n* \
<td>
; V2 y5 ?" K8 }2 B
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
5 v9 ^4 H7 N Z/ v: S0 L7 F
</select>
w: F3 R% N0 j6 Z. v3 ~4 |+ }
</td>
, v* u: z' [) l" g3 Q, n
</tr>
: Y( y9 G8 t& }: w
<tr class="bgc">
" z2 d" a5 Q" }
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
, d9 H# }% P3 c3 f6 S% \6 l* }
</tr>
, g4 {, D# P& A+ P( w, M
</table>
8 \ n; ^7 t0 y: [& ~
</form>
! l- K1 ]3 D& W3 p( g
<script language="javascript">
, H' F4 ]' v# A9 |3 v" I( m
//人名移动
1 w- C5 M( }$ z+ W9 Y' Q
function move(fbox, tbox) {
; M( _: X4 b- u
var arrfbox = new array();
4 w+ s% y5 m# @! t% ^
var arrtbox = new array();
2 ^6 \5 c" R* W; P5 C8 Z- ?4 C
var arrlookup = new array();
3 |2 E) H( b4 b P
var i;
/ p4 O% C+ M u4 b
for (i = 0; i < tbox.options.length; i++) {
( `) B3 d- M8 ] `9 G& k$ ], o
arrlookup[tbox.options
.text] = tbox.options
.value;
9 n! [) e, v0 o# M
arrtbox
= tbox.options
.text;
6 }5 r/ h2 q, K: h8 g
}
W* f; Z0 o- U/ ^
var flength = 0;
' T0 K7 X* C! O. J/ a7 M
var tlength = arrtbox.length;
0 F& Y/ m! q* F" q
for(i = 0; i < fbox.options.length; i++) {
" O& l& _! n0 E {2 y
arrlookup[fbox.options
.text] = fbox.options
.value;
& i& `; }) H$ H; e
if (fbox.options
.selected && fbox.options
.value != "") {
' c2 r' p# Q( M
arrtbox[tlength] = fbox.options
.text;
8 ]- K1 k% A7 p6 z( u8 J, L3 h
tlength++;
2 S4 ~- F+ R6 f
}
3 \" ~( I& ?" d1 s! h1 T' Z7 o& D
else {
7 ?) e1 o% f' l0 J; U6 Z
arrfbox[flength] = fbox.options
.text;
! d$ {% k7 L5 I- A# c0 H1 \3 }
flength++;
% L- ?& Y" Q3 K
}
( X- ^1 W# w! ?$ J3 `
}
6 k7 N# y% S" [2 ^' @ x r
arrfbox.sort();
% b0 ~. q1 X; e G: A- E
arrtbox.sort();
0 W- A$ T# e' w& ^+ C2 ?( }$ {# A& {
p- g0 w! I8 N. K0 B
fbox.length = 0;
o% m' L" [0 d, v5 i. l A3 r
tbox.length = 0;
6 D9 B9 ?) v1 E4 S |- g; P% A6 N
var c;
. b E6 ~) F1 U; _4 l" d4 n; t2 o
for(c = 0; c < arrfbox.length; c++) {
1 z3 `# ~$ O* {# O
var no = new option();
; a; ^/ ~/ {/ W7 q! O
no.value = arrlookup[arrfbox[c]];
: J" y( W$ T, h8 O( R/ P
no.text = arrfbox[c];
9 G, L* r8 z9 A
fbox[c] = no;
# `% `; U* L. m. d; M. q
}
5 {. Q, S% G& w
for(c = 0; c < arrtbox.length; c++) {
# ]7 i8 x% f. a! G* z
var no = new option();
, Y, Y5 |1 a; \; ]
no.value = arrlookup[arrtbox[c]];
0 H6 h+ V, A6 |" E" V
no.text = arrtbox[c];
: s9 Q% }/ a8 e
tbox[c] = no;
7 r5 ~* w, d& N% W& d2 ]
}
$ }7 {4 v {- P9 P
}
3 w0 [" y6 s2 s9 z* l+ i0 Z
</script>
. K. G2 b# v6 _' a2 }' y# l
</body>
: g9 L2 c$ |) X: [- v- V
欢迎光临 捌玖网络工作室 (http://www.89w.org/)
Powered by Discuz! 7.2