获得本站免费赞助空间请点这里
返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"3 X4 ~2 m$ b" c" `
         c pageencoding="gb2312"' I* C' F: I' ?8 \/ \  G2 t
%>
1 H7 ~% H* V: p# {! ^9 L) ~<style>
; w' |  J2 r9 @, Z, t( l3 E.f9{ font-size:9pt; }
: i8 M, Y5 u( ].bgc{ background-color:#aecaf9; color: #0033ff }1 T' r, ~- Q4 U. U3 I; t7 j$ r
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
6 P0 n4 y: K2 M, \  border-bottom: solid 1px #4e7dc1;( O$ k$ ?: S2 A( z
  border-left: solid 1px #aecaf9;
% L$ k* U: h7 Y4 v% z% j  border-right: solid 1px #5679bd;4 ]/ i: M* O! a8 h/ D
  padding:1px;
* J: o3 i8 v. a' H% \% R# L8 u. b" G  margin:0px;}
& [7 K2 X0 V$ e0 I6 q  m</style>* G. z3 w4 i. m0 b3 ?
<script language="javascript">" M* t6 U7 r% ^7 q" y
<!--: X: N2 m* T; N. D$ P- S5 [  M- j
function rv()3 K+ O' g3 S; N1 J9 F. X/ `2 Y, f% D
{9 J# h8 a# ]# t# ?+ v$ {2 C
  var val="";
5 Q: c% Z" _0 e/ a  for(i=0;i<combo_box.list2.length;i++){
7 J0 \+ J* D) s& c2 v   val+=","+combo_box.list2.value;
( n& t: G. z% j+ M% K( G# j1 h' ~  }  Y$ ~" a! E! X4 l
  if(val.charat(0)==","){, H6 v  |+ G6 d8 J' F% o9 g8 C
   val=val.substr(1,val.length);
  I! A# Z9 \  M2 |) j  }+ ^" j/ P4 G3 O% h6 L. A
  opener.form1.frecname.value=val;8 p2 E- G- R9 |9 z, ~" `& H
  self.close();
& n' z6 t! p) h& }}
  @9 a, f* G& c( R! u/ i. y% E//-->: J) ~  G8 U0 Q0 c5 |9 O* U# B. u
</script>
+ Q4 T: o# {: l! p! z<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">+ d; w8 B" e1 t0 U7 Q6 P
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
, ?5 ^0 W! U, h# T<%& U* b" _' K0 k( d
  cdatasource ds=new cdatasource();  //数据联结bean实例
, d# X3 U9 t$ }  java.sql.connection conn=ds.getconnection();- o( V2 D6 b# z2 a' T0 ]( p3 q
  java.sql.statement stmt=null;
3 W( {9 N' S% A- C, F  java.sql.resultset rs=null;- }: Y; k' ?# `5 S$ f. T2 X
  cdatacheck dc=new cdatacheck();. e4 n$ [0 x7 S5 p
%>
; {% F$ L# ?% e; M% i% [& Q<%
1 s+ p) S4 Q) 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";. M) v1 V6 p! j3 L% m0 c
stmt=conn.createstatement();' Y+ y1 N; O; a# r3 E, c: R
rs=stmt.executequery(sqlu);, b/ ?( d  ?/ S" o& }' v, p8 \
%>; T( R/ L+ `1 n. c9 ~( B
<script language='javascript'>9 J" j5 r& b& Y4 u$ u3 L& R
arr = new array();
$ x$ F- J6 b/ j# Z; l<%  int temp=0;
* F% A/ Q  }+ J0 }1 owhile(rs.next())8 p6 ~$ v( `7 H4 R3 S8 d! B/ v  j
{
+ l0 k7 N: [( ~  T9 Z6 D8 F8 X/ L%>
# }2 X# q& b5 F5 a# m8 zarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");' Q, p, D% m/ t
<%
) X' x6 ]% ?1 z5 e: L. t7 Qtemp = temp + 1;! [+ C* z' M# o' g( Y+ @4 m; X$ P- m
}
/ M9 m2 M' B0 C/ r& r4 D3 C  B%>$ L* ?& W% F* c$ M% P- A
temp=<%=temp%>;6 P6 m7 n  a! B5 p, z1 b# l% {) y
function changelocation(id){ ! V. q6 f! i: C
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
2 a8 J3 i7 z0 P" ]: Dvar i = 0;
/ j3 k7 v) W, x+ Ydocument.combo_box.city.options[0]=new option('-------',''); ) P0 j+ B# v" _0 i' b* k; Z
for(i=0;i<temp;i++){
& p. E. Q& a) R4 o. E# rif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
: a$ h% W+ s2 `$ N9 h, v+ ndocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
4 ?. B/ Q0 G, _: D; M} ; M; ]9 h7 ~2 W& t( \
} + O2 Y5 x4 B/ ~+ q" w1 V/ q
}
( }4 Z3 c& _! K; I' T</script>4 M/ k1 F$ x- @1 y1 S$ n: r0 U
3 \( {) s( U' z# ~
<form name="combo_box">
. [9 Z! s8 _5 L% E5 `7 M<table border="0" cellspacing="0" cellpadding="0" height="210" width="59"># |/ z, J9 N2 f; S8 X1 s0 b4 g
  <tr height="24">
7 D- {- u8 p, Y( z    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
* f3 l( S, j& q2 a9 e$ s    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
. \& R9 c. M4 P% z; C$ S; N    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
# Z$ C7 X# s( [0 u& q    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>( X- `9 \  T: U# P& l
  </tr>
- b. W. Y, F. [+ m& O2 D9 l  <tr>
, U( a& s- ^8 a9 B( K) N0 d    <td>
4 f. K5 K) C- h  i0 H7 S; f& e) ]  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
: R5 t" `  [' y  <option value="0">请选择部门 ---></option>% K" }8 [" B3 b* r: h0 s$ B
<%( \0 E  e# F3 G6 Q/ L# s6 Z
    string sqld="select * from tdept";. J% R8 i: s- O- p& i3 j3 w8 T2 y
stmt=conn.createstatement();
0 d& W3 f+ z4 i% R4 {rs=stmt.executequery(sqld);
4 t4 T: f8 S! s7 o! Mwhile(rs.next()); J: o* f4 N  u
{9 C+ s$ j& _# P5 J# r! [$ {
%>
" n4 ?+ Y9 [3 M; e, j' [7 r5 Y  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
0 q. q; R/ X7 K: o0 `$ X% N<%- I5 T3 `! ]0 \5 j* z9 l/ A7 C
}
; u  t) ]0 x, W6 k- k) `6 ]. s7 S%> - p. [) Z# f2 A0 p1 [4 ?  A7 M
  </select>
! W& y# D% C7 M/ V9 f6 V0 [; ^</td>4 X% o4 p4 B( m& }3 n, x' e' D
    <td>4 e$ e) O! k, D
  <select multiple id=city style="width:150;height:200" class="bgc">
% v" ]" o, G7 L+ q# J2 t  </select>+ U# C( Z5 s0 x$ ?# X/ ]
</td>
. j) l$ B% o- P: V$ Y; t0 g. W" N    <td nowrap align="center" class="bgc">  `5 J" _2 m4 l+ l* Y! z* h
  <input type="button"  value="<<" class="buttons">
7 Y5 W7 r; ~" C% S0 m  <input type="button"  value=">>" class="buttons">
" Q& m& O" s8 ]( U6 t; k9 c5 k* p& R" J</td>
, s$ d* p. i' j9 v    <td>4 ]5 A, q2 u5 J3 H2 G
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
: C/ n; u- @! S% H  </select>3 a2 @& G1 {6 [. m! i$ a3 \
</td>7 w; }+ }8 {$ M" E' D/ b# Q, {7 g$ z
  </tr>2 l+ ^% b+ b6 s$ M* M# N
    <tr class="bgc">
- s7 s+ v1 Z' v, ^" L    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
2 x6 U$ G4 \# v  </tr>" x5 F# ?0 y9 p# b2 ?" p  ?
</table>
8 t, n  @, P- x2 [</form>
8 U" m% ~& }+ R' i* m! n0 X+ G<script language="javascript">' j+ q* G( @# n# L6 C
//人名移动
# u/ y3 x* X3 k/ r4 xfunction move(fbox, tbox) {6 j3 ^) a) z+ o
var arrfbox = new array();
- o6 w( u2 A7 X/ Z. E/ Kvar arrtbox = new array();; p$ r6 H" L  j
var arrlookup = new array();( J' Z. P0 v# v1 q: I; F
var i;; L0 m, V! R5 W. G* V
for (i = 0; i < tbox.options.length; i++) {' G3 B; b/ B& O  E
arrlookup[tbox.options.text] = tbox.options.value;
1 _- o( C! H, g5 d8 C1 f% _arrtbox = tbox.options.text;) w& V/ T* g  D* @
}
' s5 Q0 G& \& ]- ]! H: Tvar flength = 0;+ {3 ^) ^0 f/ d2 v6 i7 T) j- t- A
var tlength = arrtbox.length;
! b/ j; I9 N4 E6 C8 f8 d- ]! I; k+ Kfor(i = 0; i < fbox.options.length; i++) {- k. t' K+ H, \/ v4 T) }2 ]% G0 [
arrlookup[fbox.options.text] = fbox.options.value;
5 _: L( \8 ^) U( t( j  \if (fbox.options.selected && fbox.options.value != "") {+ O9 l! k; U  j6 ~
arrtbox[tlength] = fbox.options.text;( A' {, C# q+ j# g, ?4 K: C8 P
tlength++;
* _5 j7 S. \" g2 Q& K0 g4 ?}" X; R6 _  w! S' ]% b1 m
else {$ Y1 R6 |# z1 {3 T0 t7 q  Q
arrfbox[flength] = fbox.options.text;5 r- \1 u2 s+ l$ c; H$ x
flength++;
7 ~* Z, ^  s9 K9 r' i/ l+ w. X. r* _   }
6 z  [: s( e9 e. v}4 Q* k+ f. T% f2 n8 Y
arrfbox.sort();0 q! Z! q* {  h
arrtbox.sort();
6 t2 S, U- G6 W* Q: I- Y5 `1 s' Q9 q* m
fbox.length = 0;. S3 i) X" V2 t2 R. e! R/ c
tbox.length = 0;
' ^+ v  T" {8 {) c% j2 [var c;
! o6 f0 F" v( ]/ ^for(c = 0; c < arrfbox.length; c++) {
, m# B! [' G' l% X/ yvar no = new option();
3 F6 e* U" |; S( ano.value = arrlookup[arrfbox[c]];* A' E/ y' m2 L" W( ^. B, @
no.text = arrfbox[c];
5 V7 u2 M4 q! t# ]' B, ]fbox[c] = no;
0 d7 x' D( \; B4 F& I1 t' K# v" u" n}
7 c) o, e: r: @3 I7 m  y9 wfor(c = 0; c < arrtbox.length; c++) {( D# w+ S8 q+ R1 N& }5 j
var no = new option();
' K  R7 K8 ^( ^2 Ono.value = arrlookup[arrtbox[c]];
: e- N0 u  R  s0 k# Lno.text = arrtbox[c];
" H) h; q! X' L5 J/ o9 F  Jtbox[c] = no;
. s+ {1 U1 `% {& I& q   }
" C+ s0 _- o( X- S, X$ S! _5 z8 C}
. G" J( a+ Z/ Y7 J8 C. C: M4 G& Z</script>
* |2 m3 X: Q3 w! Q" @: i" V0 v</body>
8 Y0 x6 c9 E$ G$ R, w

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