返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
$ M3 y% a7 a  e2 J         c pageencoding="gb2312"
, Z, L$ _- d) p6 }%>6 q' a+ n) [, i( \, W5 [
<style>+ d. o, }- u) ^" |
.f9{ font-size:9pt; }: I8 W) A: b, n. h! T
.bgc{ background-color:#aecaf9; color: #0033ff }% H, k  l+ i: @# |! O5 e
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
# c9 }& k/ n& M; m8 P  border-bottom: solid 1px #4e7dc1;" y% {; v  t; t. `" X9 t& N0 x
  border-left: solid 1px #aecaf9;9 Q7 X1 S; P, S; u7 X
  border-right: solid 1px #5679bd;
0 n, }) t/ H( D8 z5 K. p; i  a  padding:1px;
4 T) t# B4 ?( m. _  margin:0px;}
/ l( X; R5 i8 F. z' m6 b</style>7 d. n- p# P7 k$ n) g
<script language="javascript">
3 X' L9 q! @- V6 O/ ]# D<!--
" v. C9 d2 m- z5 l8 X  Jfunction rv()
. `- S2 e$ o( ?. w: e3 n, @2 X{
+ F4 U& Z% e- T5 q( y" A  w  var val="";
9 t2 B+ G; `, p  for(i=0;i<combo_box.list2.length;i++){6 k9 ~: a8 Q# M, U! I/ \; |/ z
   val+=","+combo_box.list2.value;! f5 l. H7 }, h
  }& `, J" I* |3 ]5 u! z8 S" w: Q
  if(val.charat(0)==","){) a5 x( X" e/ h
   val=val.substr(1,val.length);
" T9 Y( t: J& ~" L. ^! B7 ]  }
9 f& j) c) w' y$ g& x4 d+ }4 ~- c  opener.form1.frecname.value=val;# G* F0 H+ c7 C& [" D
  self.close();
) L. S4 f9 g: z6 I+ _+ H}
1 L) y4 `. A3 D( m- p7 E' j4 N//-->
3 w* f  k3 W4 S1 A, U6 j/ i0 s</script>
1 d- y+ D, `# _. D# [5 O6 H% o<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
1 O) S/ H; G' _) z% v<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
9 t9 n/ ?( ?( F* b<%
: A  Y) _* l: l. c9 O  cdatasource ds=new cdatasource();  //数据联结bean实例/ U5 H$ f  I6 v8 O. d
  java.sql.connection conn=ds.getconnection();
, G. J& }+ N0 |3 v5 H  java.sql.statement stmt=null;
1 V! w/ ?- }5 d6 X8 ?; I7 x  java.sql.resultset rs=null;4 l* H& h/ k8 C+ @/ p" Y
  cdatacheck dc=new cdatacheck();2 a: C, f% N4 Q4 x5 p
%>- H9 B, P8 f, x; D4 |( T
<%' u& B4 K% ~7 h( x
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";: z: R3 v1 Y) ~8 S
stmt=conn.createstatement();
+ ^! E0 m9 `* g- @/ u: Grs=stmt.executequery(sqlu);
* G3 t0 A+ t0 A& ^8 S2 Y; i%>
" x' m9 H* S' m) e7 U, i<script language='javascript'>
( E- @' {3 O3 E% A: Rarr = new array();: y( |. _2 ^  ]. `
<%  int temp=0;4 O- {* G$ f8 Z! v, u0 i1 A
while(rs.next())! s' o3 y! }* J4 f1 M/ W9 W
{
% g: N7 P* K2 ~3 N; x%>  K) W/ g0 ?! c7 {8 l: G8 h
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");: ^) L( Q+ a* [% B) x
<%
' q; C& }9 D7 f6 [temp = temp + 1;: w( L6 n( m1 O  C5 D' E
}
5 S5 C& }0 c6 P4 F%>
" O& x% p7 S9 L  t3 l9 p* Ktemp=<%=temp%>;
6 Q! v8 i; }1 |. O, I  }( I( \8 Zfunction changelocation(id){
4 {$ V+ ]$ K& U+ p& i' Idocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
3 H4 W& a# X8 L) p5 V# qvar i = 0;
! H$ O- t7 {0 R- F  m, Bdocument.combo_box.city.options[0]=new option('-------',''); $ a4 y/ v0 @/ a
for(i=0;i<temp;i++){ ! V. K3 N, `/ d( F
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
9 z3 Z6 w+ i0 e# Wdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 4 e$ d. y" [' Q- T; F6 I4 p
} 6 r' ]. E, j8 f4 Y
}
8 E5 \) ^# \3 I2 w}
% O3 h3 e2 f) D( g7 x, @</script>5 o2 {* G2 q7 m  Y9 P

+ F4 L0 G' y! `' f: Z<form name="combo_box">
6 z$ W1 x6 K: O. m2 R<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
/ A# h' ^2 ?# A) p* S9 p3 L9 X  <tr height="24">
# X* k% I2 t4 i- F2 H; `    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>; _. K9 X' m8 x9 }" b$ H+ L1 m
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>& I1 |) T" \8 B- Q3 ^5 t
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>8 Z$ ~  ]4 e3 G9 J' P* u8 U
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
) A' n; }2 h2 v  c  </tr>. }- ^7 F8 V# |5 n
  <tr>
/ B* }; a! W7 o& ]' j6 G3 Y    <td>8 y) e( o. |/ `: i4 k
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
, k- o5 p: B9 I4 m  `  <option value="0">请选择部门 ---></option>
, R0 d& l* m# ]7 o) p<%
/ C: b5 @9 ]5 T$ {5 N    string sqld="select * from tdept";
) R6 H, R/ m: u% x! \stmt=conn.createstatement();( J; I! T6 s* C. C
rs=stmt.executequery(sqld);
3 H1 H7 _. h$ |) U; t% e3 m+ qwhile(rs.next())+ S3 }9 N  Y# @( y$ G9 m" K( n1 i
{: x$ s' ~  R  l  Y$ i% H; ~( A) B; J
%>
" C0 d4 m0 Q7 h  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
- a; y& m1 w+ L/ p' o<%) m0 w+ \; [- K6 P) O5 @
}
; ]& t4 c; \0 D- z8 h%> 2 _1 v6 p; j, f, `
  </select>
: `, w9 u1 F5 k4 j% ]- R! K7 h9 I</td>; S- O) ?7 E" E! a+ _% N( s: l; o
    <td>+ P3 ]5 M, `. G/ n: `
  <select multiple id=city style="width:150;height:200" class="bgc">
0 A  s2 p& d3 E) d* Y$ K, l  </select>- M0 k0 |! V: w2 r/ e. p2 F0 @
</td>+ ^- A) C: g; X+ u3 C$ p
    <td nowrap align="center" class="bgc">& q/ A$ ~- @1 u
  <input type="button"  value="<<" class="buttons">* \: S( I: \0 E" j
  <input type="button"  value=">>" class="buttons">, H- l  B. m$ z- w" A0 R) P
</td>1 |! W6 f/ P5 M& ~3 d% K- n
    <td>( D, v5 `5 _( ~: y$ ~* ~: {0 u' R1 b* O" ]
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
$ ]/ g  O5 F* X- |7 R  </select>6 c; N* A8 N! E" x* g  o- d/ w
</td>/ V" A1 I; s# _2 n
  </tr>
* ^4 x# b* z. U) ~    <tr class="bgc">
- }- C$ }$ B0 m' ~/ k    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>! O/ E1 L- n% m) n( R0 ?+ n
  </tr>, x$ D1 i. [: k8 Q/ {: I
</table>
/ W% @% b! e6 r</form>  n( U/ y* U) P5 o
<script language="javascript">
2 E" W( `4 X5 i4 L6 Y//人名移动
; F; C% v! D$ j! f2 [function move(fbox, tbox) {5 n, ~) L  h5 C- {% T' f
var arrfbox = new array();
0 w  P" Y* P0 jvar arrtbox = new array();
- N" `" G6 [2 A, nvar arrlookup = new array();
9 H8 q  Z4 S9 V5 V5 }2 Yvar i;
: N: j# ]4 O4 `7 m4 y( G+ r8 \for (i = 0; i < tbox.options.length; i++) {1 Y; p( |- Q+ U* S+ ?
arrlookup[tbox.options.text] = tbox.options.value;+ ~' d9 L$ ?( z# j, j
arrtbox = tbox.options.text;" r' z7 u% M) O! Y% P0 e
}
0 N5 o  Y6 d+ x: g  Z+ p. L* Vvar flength = 0;( r/ X5 [5 Z5 L
var tlength = arrtbox.length;3 ^; o( y& p. S" Z5 R1 ~
for(i = 0; i < fbox.options.length; i++) {
5 S# E. S1 C' y( H8 c% Garrlookup[fbox.options.text] = fbox.options.value;
/ ]# F- _3 O; x1 H4 ~if (fbox.options.selected && fbox.options.value != "") {
* t5 \" z) m/ u$ h, Narrtbox[tlength] = fbox.options.text;
* y: H! D: A0 X$ W/ ~8 i% N2 [tlength++;2 c, K+ s& |( n
}
5 g3 ?; l) _% D! m+ ?else {
2 L4 j( O/ }: b# earrfbox[flength] = fbox.options.text;
' v5 j! Y' o5 t8 a% A9 ^flength++;& z5 f$ k; b6 G' Y# v( X' c$ a
   }% z; Y7 y2 {4 d  f) q" m
}
" j: r( P- Y+ \, X+ warrfbox.sort();4 u, p: W7 v+ A% H/ Z# d0 f
arrtbox.sort();
+ x6 j( y' v! Y7 b) G
6 k" F& H( j9 \! P( u2 ?4 @% f1 s4 \% Nfbox.length = 0;* F" A* i, [5 U4 Q+ x) e
tbox.length = 0;
) S% R! Y3 X& n% fvar c;3 v/ v* ]- l2 Y4 \3 j
for(c = 0; c < arrfbox.length; c++) {& G% u/ A- U8 o; p
var no = new option();
3 h6 E# K0 ?; x* H+ y0 ono.value = arrlookup[arrfbox[c]];( }7 A; w2 n; ~
no.text = arrfbox[c];0 ?1 D& b9 y( Q  C; j5 j
fbox[c] = no;+ J! n9 W, `! a$ q3 i1 R
}$ S( y' `7 A+ e3 m8 r
for(c = 0; c < arrtbox.length; c++) {9 j9 d1 }# n5 d( Y) i; `
var no = new option();
7 L# w; s/ m2 W! o7 J( I" V9 Rno.value = arrlookup[arrtbox[c]];
4 x# X; x, @2 V7 G4 Y0 v+ R  D9 Cno.text = arrtbox[c];3 ?. O7 R) s# z; v
tbox[c] = no;' g' Z" \5 Y2 \1 X
   }# @% ^( Y8 U  z0 L/ }$ ]
}: f7 v( `# O7 i
</script>7 c3 t. d; [5 r% W6 x/ U
</body>1 }& X4 }3 w( `, @; I+ R

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