标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
5 `( T' {( @# X. t
c pageencoding="gb2312"
: }2 q3 r# @5 Z0 Q; n& R
%>
7 b9 x6 h$ a' P \! G
<style>
/ R/ {! G/ f0 Y7 ^( s) b
.f9{ font-size:9pt; }
6 A' \) }3 \% ]1 o- ~8 e7 L' n
.bgc{ background-color:#aecaf9; color: #0033ff }
! ?3 `7 U2 h1 d
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
# q5 }' F: y$ M% ?2 g* u1 Q, }
border-bottom: solid 1px #4e7dc1;
% L# C( K( O0 Y' J4 n& K
border-left: solid 1px #aecaf9;
7 C) \8 H4 d' I/ u) V
border-right: solid 1px #5679bd;
5 A# E; v3 V. n4 N/ n: v
padding:1px;
5 v% f/ I0 l& t; R; e. ]
margin:0px;}
. q. a F) _. f$ `6 w' O
</style>
7 N# z' a( B5 T( H9 w! f3 w3 z
<script language="javascript">
1 Z% S5 t! a F( T! J) d o
<!--
1 E1 E6 H3 `- d6 F
function rv()
1 X! z3 E9 ?+ Z0 k$ S" U
{
: B5 a& f: [ K- Q3 B# U6 i2 O
var val="";
% o9 {" z1 \8 O$ G; Q3 M# q+ u
for(i=0;i<combo_box.list2.length;i++){
$ A, N! i' }; ?- s* W4 j* _& `
val+=","+combo_box.list2
.value;
/ ]0 `, A* {$ W3 M% H2 S
}
; C1 o* u/ D8 j" V! l, z |
if(val.charat(0)==","){
; e {5 Z3 I3 Y6 J* S5 Z
val=val.substr(1,val.length);
1 @1 o0 u8 d2 F& p1 N! R# M- I
}
* _2 c( S7 ]% o" Q
opener.form1.frecname.value=val;
, |% y% y7 I* j$ B# Q, m
self.close();
6 \& {% }% x- ^: W
}
' i% y q- Q9 m
//-->
& p" R* y3 u% h2 K$ Q# b
</script>
# }2 \% u* U9 Q
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
0 f% i" a$ y5 @- ^/ _
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
+ C: p5 b* ^9 N7 v5 X1 J- V! ]
<%
$ a( x9 Y; ^% {+ A9 Q* d* `
cdatasource ds=new cdatasource(); //数据联结bean实例
4 ?" O& e$ Z- c% M
java.sql.connection conn=ds.getconnection();
+ ]& ~3 _0 v. e, i% X
java.sql.statement stmt=null;
7 q) ^* V' v$ | Z |: `
java.sql.resultset rs=null;
: N: v4 v S; L. N+ Q
cdatacheck dc=new cdatacheck();
) D* u$ h7 z+ V' j5 v7 T
%>
" {) c7 o- J4 M) e& d
<%
+ _2 G2 Y0 v. [: R7 c. C2 A
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";
" i) L+ I3 ?" K# C1 E. u
stmt=conn.createstatement();
2 G, Q% _# P. Y1 q& @' h' {
rs=stmt.executequery(sqlu);
4 e6 U, }. k0 J1 Q& z
%>
5 A6 g- \/ N, N' V( N. L! d4 Y
<script language='javascript'>
* T( e, i. E# |$ B O8 a
arr = new array();
! k- W+ g& l% n! Y/ }
<% int temp=0;
) ?4 \0 {" x5 z5 o n4 V
while(rs.next())
- u D$ G1 a* R* c) Y/ F
{
p/ V( S6 Q' P: J. b
%>
, V4 [4 j- v# u! M, a# n
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
. b' v$ y i1 P: } C0 Y. b
<%
1 h1 N! Y! F8 \' A7 D/ i5 P# b, K
temp = temp + 1;
9 Q# U" u- V( e* ~% K
}
" I7 d& Q6 M+ `, v
%>
6 \9 G; g# W. Y0 E. y
temp=<%=temp%>;
6 l: C/ F- Z2 n1 h$ H
function changelocation(id){
6 k# z, Q& A D+ k+ n4 o
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
) `6 g b4 ^. I- W5 X
var i = 0;
' m; }6 j- z2 W
document.combo_box.city.options[0]=new option('-------','');
: J, Q' G0 r a* ^$ h6 D$ D/ I' a
for(i=0;i<temp;i++){
' ]. y' _. L! H& V4 H% n) w: B. o
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
( i7 s& u. x$ \
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
. N# N* N+ I4 i2 W* W' c& f
}
4 g, y2 c6 w3 G+ B! M0 u
}
( h) `5 i H6 _0 L9 p, R8 U
}
6 j6 U) T1 ~" h" _
</script>
" Y, W3 k- \3 A
0 Y# d# `+ G, p1 V
<form name="combo_box">
- d y3 I6 C+ N
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
5 z5 g7 M/ K) H" G, V* _- p6 W# l
<tr height="24">
+ e8 \6 q: d( N+ }4 H5 q
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
$ r/ g( W) m) i8 G. k( s
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
# f# x: O7 {+ G9 |; v# }2 B
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
4 [% y" M) m2 w, C& O @& |# O! D
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
. `, S; C4 ]9 p. y: Q
</tr>
+ K L* \: u! J7 P7 c) J0 m, c
<tr>
$ R0 u0 n: V. L+ F& o5 I
<td>
+ W3 T% D; A' A- r% ]
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
[6 {+ ~3 ?$ w8 u
<option value="0">请选择部门 ---></option>
m5 Z' d: M1 d+ y4 n+ e
<%
7 L' S" b3 }& v. C; d" e7 F
string sqld="select * from tdept";
- i8 A+ J& C* v. E, V7 G7 {/ Z
stmt=conn.createstatement();
0 L5 V% l" S4 l9 F8 U
rs=stmt.executequery(sqld);
) B5 g% K- g. y
while(rs.next())
- Z% h' O- N( T/ U0 ?; h6 F+ J
{
2 ]* ^& r0 D- j( a" i0 n
%>
2 x3 r; r, t/ a/ i, E- {( Y3 R
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
% `0 r n7 G6 T; \1 ^4 Q! D
<%
; y! f4 K5 O, p8 [
}
! t7 N) f7 i/ X7 ^" M! ~
%>
& C, K# c" Q! H4 w; @( U" w. M* r
</select>
4 b" F# P( s% W
</td>
4 o: \* x0 p% {' q `0 C
<td>
1 U- H3 ~ m! {- w& N
<select multiple id=city style="width:150;height:200" class="bgc">
+ q' f# S @7 A1 C6 R( d* y
</select>
, h+ F2 H5 S0 r) a$ e
</td>
$ ? u5 M9 Y% o; q
<td nowrap align="center" class="bgc">
: o5 O4 D- w- @$ C
<input type="button" value="<<" class="buttons">
# U9 F! m, j: V6 r/ U
<input type="button" value=">>" class="buttons">
- t5 ]# K: F( F5 l2 c& X
</td>
' U% v- t' V8 w! [6 S& `
<td>
u2 ~# J! x4 Y; x+ ~0 D& N
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
5 X4 }; Y: C6 } b: P9 [
</select>
8 e7 w3 Q9 G2 X# k1 ?2 [0 B
</td>
' n+ c: _0 l2 E2 z& `# z
</tr>
1 {+ e' t% n u3 l* f) Q7 V0 D6 _
<tr class="bgc">
/ T# f/ \6 l7 {2 c8 b6 {
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
3 b. Y1 W0 h& w% I% Y% {7 y+ A2 q2 C
</tr>
2 U; C2 | ?+ B& c2 A
</table>
+ Q! T- O* ?) ]8 a2 U
</form>
) {5 I1 x+ O2 O: w. B
<script language="javascript">
% x' I- I) s p, Z
//人名移动
2 U9 Z% D2 T# O4 ?$ u9 `
function move(fbox, tbox) {
/ l, ~/ `1 l& B; S
var arrfbox = new array();
9 z$ T# n0 @& F4 }; x
var arrtbox = new array();
9 U6 i( j" c) D5 k
var arrlookup = new array();
3 @' |; n- \4 V7 M% ~
var i;
, o# U; l/ N/ u5 f/ e' d" ?
for (i = 0; i < tbox.options.length; i++) {
- t4 J9 x) H6 t: p- j( Q
arrlookup[tbox.options
.text] = tbox.options
.value;
9 q b `! n1 R! a/ L
arrtbox
= tbox.options
.text;
3 p; J9 Y, x! `- |
}
3 {- m* w# R: B0 }" H6 L1 O
var flength = 0;
: V. [) x+ m3 e: H5 R% k0 t7 O
var tlength = arrtbox.length;
( p7 F6 `( }6 B, M4 D
for(i = 0; i < fbox.options.length; i++) {
( O8 K: @8 X+ F6 V# f* J( M
arrlookup[fbox.options
.text] = fbox.options
.value;
C/ z X2 K6 b" O( o# ~
if (fbox.options
.selected && fbox.options
.value != "") {
+ c" l& M( g* q8 D$ q
arrtbox[tlength] = fbox.options
.text;
* l# v7 Q- L+ I$ m( O2 j
tlength++;
) X' \- R! |" M4 |$ D3 B2 A
}
) f' m0 T" U+ F
else {
/ ?5 A# A3 e [( f6 m1 P0 c
arrfbox[flength] = fbox.options
.text;
2 d' n, `" e2 \9 @2 @! I
flength++;
" x1 T+ f! b4 `" j5 G* q
}
: i! c/ o: P& x& ?& O
}
' c4 a; n- r# G* ^3 b, S
arrfbox.sort();
. W8 w& i$ m: G2 r
arrtbox.sort();
& t& {7 |4 L2 h" }" F
* ~; N$ V! ~' h2 V
fbox.length = 0;
, U7 r* {# |0 Q) v' I8 \! a
tbox.length = 0;
1 ~1 u* d0 ?6 {$ e* D
var c;
1 y, M7 Q* J9 j- H/ A a2 F
for(c = 0; c < arrfbox.length; c++) {
7 C4 t8 Q) n0 X1 Z) x
var no = new option();
9 V% H3 g7 ~5 ]$ }. n E5 @ z1 ~
no.value = arrlookup[arrfbox[c]];
: v1 O! [8 C* D7 w
no.text = arrfbox[c];
; O* }) I `9 `2 x8 q! I
fbox[c] = no;
! Z0 X! x' e: T" H- h9 ]# M
}
0 t J7 Y+ o3 l' U
for(c = 0; c < arrtbox.length; c++) {
3 [% X5 ]" s: s) R! X3 e* q
var no = new option();
5 t# D# k5 }& a6 f2 g- {" _ U* u- Q
no.value = arrlookup[arrtbox[c]];
# u& L1 B, l# ^- c q' m5 h
no.text = arrtbox[c];
9 D2 O3 K( s) A- q9 z
tbox[c] = no;
0 z8 H" X2 a+ E3 Z; [* l0 N
}
' q9 ^7 V9 `( s1 k
}
8 O9 \8 |* \7 k. ]' ]' n
</script>
- a5 V5 |& Q3 b; ]8 B
</body>
+ W6 ?9 I; T5 E
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2