标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
$ C! ?6 C4 E, E+ U B$ t M
c pageencoding="gb2312"
w+ p5 o" R4 C- m8 P
%>
% o: O. q4 v' B7 H p
<style>
8 X/ u6 G0 N! I7 x# {
.f9{ font-size:9pt; }
6 @& r, f0 J0 y& p/ _# I( e/ \
.bgc{ background-color:#aecaf9; color: #0033ff }
/ t% q0 k" h4 Y- A/ t( G, k. ~# E
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
4 O% O7 o& e5 Z. d$ b2 s& o& J
border-bottom: solid 1px #4e7dc1;
$ S( ` x8 m& W% q
border-left: solid 1px #aecaf9;
( y9 Y# g. i% t. d
border-right: solid 1px #5679bd;
- S' u8 u3 V8 Q
padding:1px;
! \/ \$ v* h+ B' _) [
margin:0px;}
5 e4 }. \( t5 N6 g( i" X1 O3 f
</style>
) z( l) T7 _) B
<script language="javascript">
0 ]1 C. T+ t+ U$ y: z* m3 a2 k
<!--
M A# b& L( k0 c$ C! B
function rv()
* @- m7 @/ b A& F
{
% P; R+ e* s. T6 N& h/ p2 b
var val="";
, z! p* Z8 W3 C7 e
for(i=0;i<combo_box.list2.length;i++){
" ~- ]" v- A. I$ B7 i4 l, x7 V3 f
val+=","+combo_box.list2
.value;
2 [% w& \1 y- v' q- i
}
! n7 h+ c# [6 \ I, c
if(val.charat(0)==","){
+ N" E) v. y$ O" e
val=val.substr(1,val.length);
* T7 |% }9 L: e# {4 U% I! M
}
+ M+ x6 |; g" ^3 D- L9 U" V! Q. _
opener.form1.frecname.value=val;
/ z! Z: b" P" s! b: g1 d
self.close();
) @- {2 S, q5 X0 I
}
1 I& P: F* H% D! F! G
//-->
7 X1 V. K) O4 g9 p# z' @8 S
</script>
0 G% f! U$ T; [3 T, S" M5 Y- V/ _" m8 M
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
* `+ d5 d/ q0 k4 J* p
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
0 o2 C: d' P% i3 L! |0 b% \0 t& z
<%
1 {4 D7 _ S$ L9 r, `! B5 i5 v |
cdatasource ds=new cdatasource(); //数据联结bean实例
/ m8 U5 @5 I& M/ _2 X0 P
java.sql.connection conn=ds.getconnection();
$ Y/ b- J2 j, p7 C J
java.sql.statement stmt=null;
2 T- N k& h' X( P+ t5 P0 ~4 f
java.sql.resultset rs=null;
3 W: ~6 O8 ?; t' I
cdatacheck dc=new cdatacheck();
, n0 h G5 R( v- |# E5 D7 R5 o4 u
%>
2 ]- V4 _4 d0 r& O
<%
3 \, W6 ^$ B2 l! y
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";
# ] `) i5 F0 X' O2 W/ c7 h U* A1 R
stmt=conn.createstatement();
9 `( o7 [6 O: b) h k) X( m% z
rs=stmt.executequery(sqlu);
! M& n, ]* [2 V% D) b
%>
; J0 m N1 v, S8 V% M. E) H7 w- V. h
<script language='javascript'>
M4 ] a! @- t/ j1 B
arr = new array();
0 P! h* v& Q c1 X& ?( e
<% int temp=0;
0 n+ X5 S! B; U A* y
while(rs.next())
. o% t' Q @+ J/ _
{
% P6 ]9 c1 _: ] Y* L
%>
. j" Y" R; s! ]1 B
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
# \: `; M- l8 b0 X4 D% K1 ^
<%
5 m9 a' y f2 O3 _1 @
temp = temp + 1;
% J! }. V$ e2 Q& S8 O2 \5 e
}
2 v# m0 T+ T6 b5 e5 m& C; w* F
%>
0 ?2 [( G. C8 p. d4 e* Q5 {1 @
temp=<%=temp%>;
; f/ o+ r- o/ @
function changelocation(id){
# x; A& K1 C. H0 q7 O( U
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
9 H! [( R% H( A5 }+ R) t
var i = 0;
0 n# B( ?3 r0 A
document.combo_box.city.options[0]=new option('-------','');
' j: `6 A/ B4 C5 N5 z/ z
for(i=0;i<temp;i++){
1 u9 S) p0 l- |
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
! f5 n( [; ]" ]; i
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
& a: B) t* |" {( f& h# j9 i/ v
}
4 g4 V b4 {7 U5 V! u
}
# V+ Q4 F+ r* R# |! _. {' Y" s
}
+ L2 d% ^' o' j3 X
</script>
) j- x2 x. O" i5 f' s
( q& p6 q$ s* {$ e4 S8 C
<form name="combo_box">
) v' D K' C- W$ f0 J/ |" M
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
/ e- m+ J6 _, v1 m( H5 j1 |
<tr height="24">
4 _. n( l$ {* z# h0 \7 U' q
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
+ Z8 {+ g) v9 w4 q
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
. F' E: L! x9 v3 H& N9 M
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
; l& J/ C _% x' a& T% h
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
0 C2 ^4 S( y- c9 Y; F# K* ~
</tr>
( u( m7 U* J7 a- P
<tr>
* o; l+ w# l1 Y
<td>
, j2 l8 ^6 R5 T; r! S- {
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
* J( d8 T! B. h5 z$ x3 r2 V
<option value="0">请选择部门 ---></option>
: f5 d% h" J. @! b* ^1 p \! u
<%
# H( g) o$ H4 L+ T) v3 T8 E
string sqld="select * from tdept";
' d$ U. w$ g( f, a
stmt=conn.createstatement();
2 m% Y+ C, x7 j
rs=stmt.executequery(sqld);
' M4 I; t4 s+ E% }
while(rs.next())
& z5 \: v# n5 j& s i
{
+ n4 C% c5 W& `# U/ v. k& g* S. H" ?3 R
%>
- x& }/ ?* [; i8 D t! P, ~
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
2 c L0 m- d9 @; t; i3 A( {
<%
9 l1 x! }; I3 K$ W2 L- H9 u
}
! Y( Y$ m# m4 e ~! _+ b% I+ L2 L* ]% C
%>
|! A7 M9 x3 j! @ V- ]/ e& k
</select>
b; c5 F; f4 ]& u9 O5 d5 `. K" _* ]
</td>
: C( T" g2 h/ |
<td>
: f4 r/ s/ L: o/ i N4 O
<select multiple id=city style="width:150;height:200" class="bgc">
; f0 e4 P$ S% x5 B1 V1 z
</select>
" b2 E& ?/ Y5 y* i+ q; n: F, A) V
</td>
" Y: u/ d; T: z7 w- d2 o; m
<td nowrap align="center" class="bgc">
9 L' a# c+ |" |+ L5 U
<input type="button" value="<<" class="buttons">
3 [# i; P9 Z" I( |/ T" T' G; e
<input type="button" value=">>" class="buttons">
4 ?9 w8 d7 S# l
</td>
7 S& I- g, m$ r) u8 v8 m
<td>
% [% p' H! o- ^7 ]: @0 W. e3 W
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
! e( s# E4 Z" Y+ m4 m u
</select>
4 T) d+ G A% U" K1 i* m
</td>
6 y$ ?7 R& |# {5 r# O9 ~2 x
</tr>
, N" S1 \! U4 L# F2 O; x4 Y0 e6 C
<tr class="bgc">
0 N" W- p# j: A, C" b3 v
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
9 f: h V5 P8 v* ]/ ?4 {( u6 d2 U
</tr>
1 W' A3 Q# @" n% q
</table>
+ h% t t, d% E- F( ]+ r$ ~
</form>
0 K1 q. A4 ?4 T Z1 C3 l
<script language="javascript">
0 M0 w* Q7 ]; `6 x0 [: B0 n2 O6 S
//人名移动
( R# n" Q6 z# T: h( Y7 }) g
function move(fbox, tbox) {
9 Z& ?/ f7 D1 r, K
var arrfbox = new array();
* a8 {: M' X5 a/ z( ]
var arrtbox = new array();
# L/ V- O+ i v8 d0 p# {
var arrlookup = new array();
/ e# ~% I- q+ ~& I5 A7 E
var i;
: Z% J/ { o s0 y% s
for (i = 0; i < tbox.options.length; i++) {
6 Q( a2 s) w3 H* e
arrlookup[tbox.options
.text] = tbox.options
.value;
4 O9 S. x, `/ t4 B, K. }
arrtbox
= tbox.options
.text;
0 n1 u8 G2 A3 N6 O: I
}
- G" _3 n7 B3 |% b
var flength = 0;
/ F: T4 ]) m( w4 s6 K
var tlength = arrtbox.length;
6 }/ n/ f' Z& q) _! L- a( W
for(i = 0; i < fbox.options.length; i++) {
8 A8 E. {& \$ Y1 l1 Q
arrlookup[fbox.options
.text] = fbox.options
.value;
- ^: T% S! V3 X, ^7 Z% `
if (fbox.options
.selected && fbox.options
.value != "") {
' n4 s7 _; E( l% k6 F8 X4 g. w, p
arrtbox[tlength] = fbox.options
.text;
6 M6 i4 t5 w) u% ~; O3 |0 G
tlength++;
6 R5 ]) x. L; F* `2 n# @- ~! i4 D$ v
}
0 k+ t( P/ \3 F" ^% L. i
else {
$ s- A& x8 H( [; p* ]2 K0 {8 m, p
arrfbox[flength] = fbox.options
.text;
0 \6 I) \/ _) T& c% o) H
flength++;
3 Y* B% B4 P( \/ L; c! m& T
}
5 @% L* h+ o9 J& p; m; }) b: r
}
' _& u7 l6 i {. s' f4 E4 q
arrfbox.sort();
( [2 r6 M! ~" [# c4 I/ a, @7 k
arrtbox.sort();
' F* g5 u. g! d% Q
' G% w0 l3 x, S
fbox.length = 0;
* I- S+ f% u( k' [
tbox.length = 0;
4 Z8 H/ ?' i/ Z9 Q5 _- X/ @1 X7 r
var c;
9 ~1 y- @. f8 h9 x) l! L
for(c = 0; c < arrfbox.length; c++) {
. c( T& O; B( W4 J3 f+ }: U
var no = new option();
' Q! f; M$ `# S, b
no.value = arrlookup[arrfbox[c]];
4 B8 T# w2 h. Q# R
no.text = arrfbox[c];
! D) t- U: t1 Z1 z1 `4 _
fbox[c] = no;
$ O- o* n8 l8 U" m" j3 {/ M
}
' `& Y! T1 P- u% d I6 D
for(c = 0; c < arrtbox.length; c++) {
& d N" I6 I3 \8 w c' {1 o: y
var no = new option();
+ g$ m9 ?( ] j% f* p( h9 }8 m
no.value = arrlookup[arrtbox[c]];
/ {7 N/ ?( n9 }2 t; l
no.text = arrtbox[c];
# _1 f- p: f. S8 h K
tbox[c] = no;
8 `" K a7 @' ]8 V% z
}
. r3 h5 a5 B* R2 l
}
% s* S* G$ S+ I( U$ M6 O
</script>
: K5 g% @' g u9 e9 K
</body>
# Z C- l5 a5 A5 x
欢迎光临 捌玖网络工作室 (http://www.89w.org/)
Powered by Discuz! 7.2