标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
9 ?, }7 m: |. I) ]! J7 c3 T7 j
c pageencoding="gb2312"
4 r4 M4 R2 _% ^( v' s, a- C7 I
%>
! s2 O0 S7 e$ C# @
<style>
( y5 ^! L: q1 y9 s) b
.f9{ font-size:9pt; }
2 S, ^; W4 {% H. v! k
.bgc{ background-color:#aecaf9; color: #0033ff }
5 B/ a$ U9 m: x7 X
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
, n8 @, ?/ |& `
border-bottom: solid 1px #4e7dc1;
$ |+ t F4 U" a7 Q2 [4 Y; ?
border-left: solid 1px #aecaf9;
{1 M p* ^. w- k
border-right: solid 1px #5679bd;
$ u/ N: ?( K' [# J$ U0 n6 [: B' {
padding:1px;
/ B* _* S! I! x& B1 X
margin:0px;}
% @2 _6 T7 {9 T+ o, b
</style>
7 _- ^. M. f4 K( c& U+ J! m
<script language="javascript">
: ^+ R5 f' |* D4 E
<!--
8 G1 k v2 S! Q1 T& w" k& v3 Y' e
function rv()
" u( l- ^3 L& A7 a1 [
{
8 @9 a, E2 u9 G9 H
var val="";
) l J1 Z" W8 N% `
for(i=0;i<combo_box.list2.length;i++){
3 R, i: N! Z0 P, m
val+=","+combo_box.list2
.value;
" f! Q( A$ ~8 B, v2 z; c
}
/ R- U2 p4 {% O
if(val.charat(0)==","){
. Q s! k; b' z# `/ |) y+ h T. b
val=val.substr(1,val.length);
1 N& E+ t) d/ `7 T' }. N8 Z
}
' j5 N; r( H" e2 k& o- B
opener.form1.frecname.value=val;
3 N8 z3 Z" s/ ]7 x" X& D
self.close();
1 V* v! ?# s" B
}
2 ~5 {$ n! M+ w2 l W6 L
//-->
1 C5 }6 b" U8 D1 g5 k
</script>
0 @6 ?& b8 S3 a
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
% v- c$ j6 Q) U' J# r
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
- ?1 y: i. q& @- D9 X
<%
9 v" D* d# \+ h- Z" s8 ^# C
cdatasource ds=new cdatasource(); //数据联结bean实例
J4 X, z2 d s6 I. h
java.sql.connection conn=ds.getconnection();
$ E# `: i0 a" s
java.sql.statement stmt=null;
* `0 t- L; O! w) e$ [
java.sql.resultset rs=null;
7 S9 g; I2 b1 l% r6 [! h
cdatacheck dc=new cdatacheck();
7 I" Z! R& i0 J$ b# y& d- f
%>
: Q: Z9 ~1 }2 e4 v0 `7 V( |
<%
3 _! T" K) X: |! w' T
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";
! E! \0 y& V) F9 G4 Z( t3 u
stmt=conn.createstatement();
' L7 R& M3 L' o' V* I( K1 m
rs=stmt.executequery(sqlu);
. w" @# b4 r% k2 v, N
%>
% T9 W2 d% I O' S7 }) i1 N
<script language='javascript'>
" F2 Z, F2 H* l) v$ J- {) H
arr = new array();
7 L! M5 N7 `4 x: D
<% int temp=0;
3 u& ^* R4 V% V# ~% Q7 t W2 T% j o8 W1 o
while(rs.next())
' g- d- E2 `1 t
{
6 n H# s q3 b5 h6 }! ^
%>
4 N( ?. x) g0 O. E$ z% c B+ G( V
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
5 q1 v# L" n {# t5 z
<%
^7 D& V' u: x8 k' J7 K* X
temp = temp + 1;
+ D& Z8 Y' {5 ^
}
7 ]0 |! E& p6 E9 Y" I! D2 y
%>
1 _& n# b U: U: b: `" j
temp=<%=temp%>;
; W5 h5 X. A# b" r- I# m
function changelocation(id){
2 ~, x1 C! f# z
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
Z V! g1 D* Q4 X$ }
var i = 0;
0 |( T1 J+ `9 H
document.combo_box.city.options[0]=new option('-------','');
% ^. h* R3 C% e9 t
for(i=0;i<temp;i++){
$ l! M1 G- N( a V* z2 F* o
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
9 |9 d7 h* T1 M7 \5 K
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
, B+ T) F; H. _9 `& `* o
}
- H- o1 o0 w U- d8 J
}
) c* ]$ W4 R+ @$ [3 h5 A
}
7 [0 M+ m- j& Q7 w
</script>
' O; Y3 _$ W8 U
9 p& N1 o$ ~- b9 v0 ?+ f- V
<form name="combo_box">
, o5 |9 U6 ?9 f, b" b- i
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
# t3 U' W% w7 b& ~
<tr height="24">
8 a3 E( t9 j+ X1 l( x
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
9 y* u, d% Q( C/ X; X, _
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
8 N. _4 B) E; F* G/ ]
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
% R9 Z4 e& m" E$ P3 @; o
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
; B& ?% c' w( y( Q! b
</tr>
% m3 D, x; n$ Y! ~5 \# W
<tr>
& n9 V7 _" M: E1 X% v
<td>
/ W: k( k* C3 d- t% e
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
6 O3 S2 K3 U+ K$ y# _
<option value="0">请选择部门 ---></option>
8 X5 a [8 A8 a. R9 m! C
<%
+ X; H. Y. |) O8 ]; N$ S
string sqld="select * from tdept";
0 k: ^+ g) |$ _
stmt=conn.createstatement();
" n/ w! @$ {- e% X
rs=stmt.executequery(sqld);
- T$ h* ]( T4 o! k
while(rs.next())
/ T2 n& U; E6 H; @: t
{
* E3 k2 {; a- P% z7 o
%>
# |# ]1 I% c. f; E4 T! Y
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
' T3 }* c/ n) I
<%
: x( Y3 z" ]" I) e
}
! P9 [3 {! t9 _3 ~/ G, A$ S' Y* P
%>
, l& o* W0 d7 ^# \; ?9 C
</select>
. n& f u3 m# \, ?' i) h ~
</td>
( t3 t8 p. e' v5 u4 u
<td>
. N# `# t2 Q% ]. N! A! M. d
<select multiple id=city style="width:150;height:200" class="bgc">
) ]2 K- m4 Z( }" z' k( ^; b
</select>
: \# l% Q4 J5 L' [4 D- ^: S
</td>
0 C& j, r5 f' d5 I
<td nowrap align="center" class="bgc">
7 P1 @2 r" Y( ^( O+ M* {
<input type="button" value="<<" class="buttons">
- K0 a) {) V* l9 f
<input type="button" value=">>" class="buttons">
+ k. u7 p4 \7 Q1 @1 v
</td>
: d3 E" ~, C1 W" i* |+ V4 |7 V) H! [
<td>
' N$ V9 p6 f$ j, K( p" Z
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
6 B* E4 @% M/ e( A5 l. Q! R: V
</select>
7 g& J4 K- G* K( D! T5 s
</td>
$ h* e& V) p' h3 z: v& z* d+ z" k6 k
</tr>
8 ^3 Q" ~9 O+ }0 m5 ^$ m5 M
<tr class="bgc">
- r) }* M' F7 s1 T- t
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
. E: }! C" P( H- M# G0 W p8 K
</tr>
: b0 W' q! U# H( q
</table>
+ i( b" R; ?- K. s/ G
</form>
2 A# b5 t6 F% s; Q
<script language="javascript">
* U- g' X. _0 S3 F) ]
//人名移动
0 z9 `# s. Q+ r2 g* t( ^$ _+ q
function move(fbox, tbox) {
/ J$ K+ E6 O) [' E
var arrfbox = new array();
) H! \4 x C0 X3 H3 a6 q. W- W7 l4 d
var arrtbox = new array();
7 Q0 F: R; Y9 _
var arrlookup = new array();
; p/ P# H, d6 I/ v; v' o$ S
var i;
* H6 Q5 H3 L4 m2 r# E8 l4 Y5 p% E
for (i = 0; i < tbox.options.length; i++) {
* x' S4 ^: C. M3 |- M) r
arrlookup[tbox.options
.text] = tbox.options
.value;
! b3 n: X3 A8 K3 o( z, c
arrtbox
= tbox.options
.text;
9 e$ W( v6 r- T8 I( o9 A2 S: @
}
! M) B7 j! C2 p" N& m! r
var flength = 0;
1 N+ b; _) y& p6 g$ A r
var tlength = arrtbox.length;
' h! C3 D1 W5 ~7 l9 K
for(i = 0; i < fbox.options.length; i++) {
8 s6 _8 v; \! W* o9 t+ p
arrlookup[fbox.options
.text] = fbox.options
.value;
& [" g) F0 P0 G# U
if (fbox.options
.selected && fbox.options
.value != "") {
2 T V1 I7 A' V- e4 {( ?/ a5 k
arrtbox[tlength] = fbox.options
.text;
% m" R+ R2 |9 S) T# I, e3 r5 O4 ^
tlength++;
2 T) H% m- A% X3 q
}
\( C& f- c( }5 O! ^6 [- }7 Z
else {
' G* k" o; E& P$ }# c/ X# B% S
arrfbox[flength] = fbox.options
.text;
7 {& k) ?# ? D0 B$ T# F" U& m
flength++;
6 E: y0 G% x# `% u) W
}
3 Z1 R& O0 F9 Q8 p9 k
}
4 n& N# f: ~/ a6 n1 @; V
arrfbox.sort();
9 B: r* o! c* q ]0 s9 J7 w
arrtbox.sort();
) H# S V7 G5 J! |9 i; B( R
: D" I/ d$ d6 a4 a
fbox.length = 0;
0 _/ X& N& e8 D/ @0 e$ {
tbox.length = 0;
% G$ i7 `9 h5 @+ k; o: A7 z& c! [
var c;
! W% W; [5 J, O4 `5 s' o
for(c = 0; c < arrfbox.length; c++) {
+ E: z0 [ x$ @/ N6 B$ D
var no = new option();
; w+ x. M2 Z5 J) ?) B1 i# l6 m1 N9 T0 D; U
no.value = arrlookup[arrfbox[c]];
s# n3 ]7 A/ y+ I* n7 u9 F
no.text = arrfbox[c];
; N6 g, i1 m9 h4 e# A3 Y
fbox[c] = no;
9 }. V( x+ G" ]# P$ _& u: _
}
R! q5 W2 ]( D
for(c = 0; c < arrtbox.length; c++) {
9 O# W0 _) A& U/ T* w- e, r6 g
var no = new option();
& L' a5 m* Z e. J
no.value = arrlookup[arrtbox[c]];
: h1 H6 O; h: |5 h4 {" N3 w+ ~
no.text = arrtbox[c];
6 f& I5 A: P& o; Z _" f* k$ F
tbox[c] = no;
) ?, ?7 ?+ U! y4 k$ V6 Q
}
/ c1 [, D* e. {
}
6 m0 s# |- f" K9 b8 z
</script>
, X- X) j* {) }) s% R6 i: Z% C
</body>
/ N2 J! C4 R2 Y: f* K
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2