返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"3 x$ q" Z' b  B! N* v
         c pageencoding="gb2312"' ]# b7 Z+ S! ~0 C- K
%>3 J6 ?+ u" W+ V8 j" h( l
<style>( l7 }0 Q1 r+ \  Z9 @
.f9{ font-size:9pt; }' t6 q) N* G, r- \
.bgc{ background-color:#aecaf9; color: #0033ff }
( G) D3 J2 Y" p9 Z! y( _% }.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
  m8 m0 [; \7 `" |" t  border-bottom: solid 1px #4e7dc1;
# p1 }' i0 [8 l$ T  border-left: solid 1px #aecaf9;
% q3 |, @( b6 a4 i1 o  border-right: solid 1px #5679bd;0 `2 T/ _, c& I4 Y8 M4 P( ]3 C, \
  padding:1px;6 n" t. L3 O& |
  margin:0px;}) W6 I& Y! V) F
</style>* Q; U3 ^: c- Z4 ]. n
<script language="javascript">1 V, n! O  u" g
<!--% d- w* Z! F3 B+ ?- ^
function rv()  F  u. Y) C$ F2 Q: _' v
{" s/ l$ y4 B  a- y$ Z( }
  var val="";5 z3 t& N- }+ H6 P- r
  for(i=0;i<combo_box.list2.length;i++){# c4 c* D) K; T5 }$ }
   val+=","+combo_box.list2.value;  m" f2 A. ~4 J* B3 e$ C
  }1 g, Q0 c0 ^3 ~$ p
  if(val.charat(0)==","){
4 Y/ v. a! `: Z- X9 N7 X: f* _9 E   val=val.substr(1,val.length);% F' G: v7 |/ c* T0 _+ v6 `
  }( o' P+ `$ {# J7 F3 r
  opener.form1.frecname.value=val;1 t7 E- s/ {' s
  self.close();
0 {7 T1 y  e- s. V$ z5 H! ?: ^9 ~5 s; p}3 V/ p5 d5 \6 k* m% T. R
//-->
& h) N3 u/ O4 D  ]</script>: h) [# q6 c' H0 @0 T
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">' Z* x0 M3 u. u- L6 k6 F
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
: y4 U! j$ x+ I. g, _) N9 p+ `<%
. P7 u- i$ b6 [9 b+ u& D  cdatasource ds=new cdatasource();  //数据联结bean实例. R6 c% Q( O* L9 a. w7 r# I
  java.sql.connection conn=ds.getconnection();
) F* D3 m8 R) P% z2 U* O9 P, J  java.sql.statement stmt=null;; F% [; F1 S' K, f  O4 T/ C
  java.sql.resultset rs=null;
! M. z; w1 `+ N$ g8 B  cdatacheck dc=new cdatacheck();" P3 X' |% a7 B1 x
%># M2 s" e9 g5 v5 H7 d
<%
. }/ b+ X, q" N: v8 A5 Zstring 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";  b+ T7 b/ p; a% k% @0 ^! M' w$ j& X
stmt=conn.createstatement();5 x3 e! h4 v# s2 O
rs=stmt.executequery(sqlu);3 m6 L3 z/ ~# K9 v3 R: [" S
%>$ d* R7 q) Z# l4 i) L/ T) o1 K
<script language='javascript'>$ v$ P; ]5 ^# ~% {4 j" I* O
arr = new array();* P& U6 H1 R5 |
<%  int temp=0;5 q( _0 W( s8 S! i0 f
while(rs.next())
5 B9 O, ]# R" w5 K' O3 E  R/ D{- l5 e$ q, M6 F6 l! i  A9 R" \
%>0 j6 |9 {" ~; W9 I' G  Z
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
; w8 P* r( j( `8 d: ^! H<%1 c* X/ P; R! A8 n# H; r
temp = temp + 1;
9 S  X. C  M& }1 ]4 B/ h8 n}
0 l7 p/ K& c, H9 V+ p& G%>" g' w8 M: K9 M5 G# x
temp=<%=temp%>;7 E( z1 ^% K% T! H9 N: O) k  X) T
function changelocation(id){ , W; h7 t4 R# N) L' _
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
# o2 h5 X+ n: ^var i = 0;
6 B! \3 `  W( F6 q9 G. adocument.combo_box.city.options[0]=new option('-------','');
! J' N: v" a! j. _* [) `for(i=0;i<temp;i++){ 5 j+ ]: M, R/ k  r
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 3 R7 o0 n7 _2 t4 w& V/ Q! Y
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
$ B1 T$ A& g* A0 q1 g2 Q* w}
" g" C  X" T6 L. j( M& U7 n( d4 @} 7 U* h3 p/ W( |1 r
}
3 A5 s8 K$ a; X- J. N5 I, z- J0 J</script>4 W* s% K! l& T

! t  _6 P# Q; d% V2 g<form name="combo_box">  n" V4 Q* N- L; g. V) y5 S
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">' z# W2 d: I: Y. b7 j* [
  <tr height="24">
- z8 @. E& }2 N3 n' E5 [    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
; N$ ?: i6 X, p    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
, v0 @. U0 b. v+ R    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>% O4 `/ Y1 z# q% R5 F
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
9 \, k: P7 P( t. I  </tr>
4 V; c; x& \( \$ L  <tr>
9 ^0 W$ W5 ~( z. D8 U1 t    <td>8 ?1 J; G4 t. B3 _1 i  r4 k3 k
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
1 {6 E( L/ p2 \6 X  <option value="0">请选择部门 ---></option>
& j% K& P' o8 |, N$ a+ f+ T<%: K# m; e- V# P. u) Z' q5 m. e
    string sqld="select * from tdept";1 y$ ?4 ~. U+ P" {5 N
stmt=conn.createstatement();
" m5 S4 w! l( X5 E+ z  H4 Krs=stmt.executequery(sqld);
4 V1 V. ~$ c$ kwhile(rs.next())7 P& _: P# o5 y$ [+ G0 m
{
" i3 R" u( M; L; q; L%>
) k6 L! T- R7 W2 Z  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>8 B1 K) v* O" ^6 K/ w
<%: I. m# @( ]. j; z2 }# c
}6 ~# D  d0 k$ y* N
%>
: p; z4 b0 t! G7 y  </select>
+ F! F  ]8 D/ @) |; D. P3 E. X$ `</td>+ V" C4 k$ O, m; m- ]# J% f
    <td>1 R. m$ ^$ P- T6 G8 R3 ~* W1 |# O3 O/ z
  <select multiple id=city style="width:150;height:200" class="bgc">' D$ D& j; |, `
  </select>& V" j/ [/ e* v' o5 E
</td>
' x% \/ E" a( e    <td nowrap align="center" class="bgc">4 w& _( G& `. U
  <input type="button"  value="<<" class="buttons">. E% q% G. w- y
  <input type="button"  value=">>" class="buttons">* l5 D: r# Z; q; U6 z
</td>
7 x- P% ?( [0 @  b4 V' p    <td>; [" s8 ~/ U2 c7 j1 }! n) M5 B
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">6 ?" Y2 O0 `' s" W" r0 e: E# J' K: s
  </select>6 z4 g( I7 z' u0 |) n; a4 z
</td>
) p" ^3 h( d7 `$ _  </tr>) }* ]; X8 i$ e4 X" n" H
    <tr class="bgc"> " x4 ^# K+ o8 q  W* W  |; K
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>, o: j0 u9 R/ p" H, A, y: C
  </tr>
; R  E; D2 h- `" c+ W; z1 [</table>" L- p0 W5 S2 m
</form>6 r* o" H, i2 b) F
<script language="javascript">5 m% t* v3 ~# L' L! x. W
//人名移动* U/ P- n# B. D( S  _+ E
function move(fbox, tbox) {
% W7 y% p: V# q) _+ z2 xvar arrfbox = new array();
& n. z' ^1 i4 U8 Vvar arrtbox = new array();% `( L" J  }* f* M" B0 t( }1 }
var arrlookup = new array();6 l5 C" g4 d8 `6 z0 s( I1 h& r+ E
var i;0 t" O# i. h6 w0 `0 ^
for (i = 0; i < tbox.options.length; i++) {( T8 O9 a& x5 g! K" p
arrlookup[tbox.options.text] = tbox.options.value;
1 b! v5 y6 \8 F4 @arrtbox = tbox.options.text;
" c" _+ {# H  v6 q8 I2 r1 E}
; E' P; o3 i! L( t, Nvar flength = 0;9 l0 d. j0 A& L2 T1 {7 q) e
var tlength = arrtbox.length;
. h- J9 b( r' t% {for(i = 0; i < fbox.options.length; i++) {
" i' _$ W9 [4 t$ f' Harrlookup[fbox.options.text] = fbox.options.value;1 X) ^: T6 C  }
if (fbox.options.selected && fbox.options.value != "") {6 L. `/ T: G+ {& ]$ }+ W0 V& _: o
arrtbox[tlength] = fbox.options.text;7 o2 F" M! L6 J0 y; M: f# u
tlength++;
* q; k; m9 u2 D}
/ h3 j+ e+ d! M! ^" ~# yelse {
% U6 P7 @9 Z( x7 i" O0 O- K. F1 v. h$ Tarrfbox[flength] = fbox.options.text;/ K$ J( U( N1 @" N
flength++;( K8 X2 S7 g) \" L, s4 l
   }
4 }% T  C! {. h( i  L}
( n; t4 O, h+ O/ Earrfbox.sort();
/ u4 f: D' F. Q( aarrtbox.sort();
  l. G8 }: t( j) O' ^
: }+ O) u* K; ]8 bfbox.length = 0;" J! i7 A1 y9 f, k! p
tbox.length = 0;) J! u+ w1 u+ M" K4 }
var c;6 r* s: t9 X$ O3 X1 C2 N6 ]
for(c = 0; c < arrfbox.length; c++) {
+ ^) d: B' Q7 Jvar no = new option();
! \7 J! i4 F4 bno.value = arrlookup[arrfbox[c]];; l" L6 ?* \3 Q: z- o6 t& \
no.text = arrfbox[c];+ o( I+ z8 `& h2 a
fbox[c] = no;4 p9 E, ^# b! v# l, L/ g% o2 |: @
}' P) q2 O9 S' T0 }( m2 Y
for(c = 0; c < arrtbox.length; c++) {
2 b" L0 i' D9 E& y, Z2 uvar no = new option();
8 m" ^, t- z! n3 P+ i- hno.value = arrlookup[arrtbox[c]];4 e- m$ w. K# G# Z" H, F" z4 t
no.text = arrtbox[c];
. X7 n$ ^+ [$ K: N+ H* V( w1 i, H0 Ctbox[c] = no;7 Y0 A$ P( I, V' ]. m3 s2 |- r- Q) [
   }& n/ ^8 }( I# l5 j
}, D, T- w- l0 ^2 k
</script>
- w- \* C! K8 \% \+ v; m( z, M, R</body>
) u3 g; a- L( H, j: Y3 ?

返回列表
【捌玖网络】已经运行: