返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"+ P9 D6 g5 I* v3 N' f0 i
         c pageencoding="gb2312"
8 W( w+ p  d4 X: d$ u; ^* u5 |, b3 j%>
1 T( Y7 p* X: b0 m3 A: A0 |<style>2 N& L9 j: s) L$ B
.f9{ font-size:9pt; }
$ n4 \+ z0 C8 ]7 F.bgc{ background-color:#aecaf9; color: #0033ff }
% ?! I+ r  T9 m.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
8 t8 x: P+ X! f, X' }. X  border-bottom: solid 1px #4e7dc1;
- ~2 }4 l0 q9 V6 ]7 [' o  border-left: solid 1px #aecaf9;& `8 p, M: K1 W1 e7 F5 Y$ q$ C! S
  border-right: solid 1px #5679bd;* w# H5 i, c2 j
  padding:1px;
! E. X, {3 `5 T! r8 o  margin:0px;}* ]6 p2 k# y2 G) v+ p
</style># ~) y- I6 p. @# x8 B
<script language="javascript">
$ z9 U3 G$ ]( n<!--
5 g" A$ R5 I1 y3 @- w. Kfunction rv()+ z- V: G# w+ L( o; Z* D1 ^8 B
{/ E( M  n) G+ e
  var val="";
# _  ~; _; }& W5 H( `3 s  for(i=0;i<combo_box.list2.length;i++){
: }9 y8 P7 u% x% G   val+=","+combo_box.list2.value;* M2 {8 C7 c5 I4 E9 L% e! N
  }
, Y+ t' x8 W1 W- Z/ U0 M  if(val.charat(0)==","){3 j1 u4 d" ]- E6 N
   val=val.substr(1,val.length);. X/ W/ W/ R' N
  }
9 }& ^' X: l' U; y& N6 {. D: g1 x  opener.form1.frecname.value=val;  |9 p3 T, l+ Q+ r% A" e, B
  self.close();
: T$ ?, n6 |. p# P9 }9 O}
  A3 @0 Q" b" W# \) J//-->
# l; ~; F! o5 ]8 G3 P+ `9 ]* _8 y* i7 c</script>4 ]1 m6 B% I3 E+ s
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">: |6 s) O, \/ [5 ~7 w- o+ U" H3 @
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />9 {/ X2 y, v5 p! \0 x; z
<%
( E  C4 J2 R% C5 d  cdatasource ds=new cdatasource();  //数据联结bean实例- H% f$ A2 L$ \2 P2 Z5 W4 x  C
  java.sql.connection conn=ds.getconnection();
1 Q1 D9 c* @/ J  java.sql.statement stmt=null;
4 W& E: l) I( o# I* q  java.sql.resultset rs=null;
0 P% p1 J3 t% r8 u# x  s+ C  cdatacheck dc=new cdatacheck();
- o0 E" r+ R% N5 S%>8 Y- u  h! Q  A9 V# r
<%4 X% A/ E! l7 N; w& J
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";. I4 K# B& ^; G
stmt=conn.createstatement();
- j7 y0 Y& B+ a; m9 Lrs=stmt.executequery(sqlu);
" r1 o( {. I/ p) b7 v- }+ D" Z) K%>1 p3 l+ G3 `, T2 X
<script language='javascript'>6 a+ u' X+ K- x
arr = new array();
) t2 n: l9 \& z/ r<%  int temp=0;& }) R6 U5 X1 w" T  }* i0 G( u" ~
while(rs.next())+ l8 H) ^/ b9 @/ p% T/ ?
{
1 O: v# e* h  ]$ V%>
8 b! w) S" x0 Z4 W5 `- n8 Carr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");6 a; s# C) J3 w9 U6 P+ a- Y  s5 Q  H
<%
- U  k/ K( m9 ~- Ftemp = temp + 1;
6 ^) C0 H# Z2 m8 }4 _7 ~, K/ \}
* J- t0 h. }) P9 W  [%>. K4 E: ~3 Z& u: Y
temp=<%=temp%>;
2 C: m  a+ f& @" ?6 C2 afunction changelocation(id){ . e6 s& w7 {, j. v1 L+ [% m8 X
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 " t3 R5 r& b9 o  U- g
var i = 0;
/ n' R2 W& j$ b+ K9 ]document.combo_box.city.options[0]=new option('-------',''); , r3 S( F5 |* y* Z+ P* H( F
for(i=0;i<temp;i++){
9 l1 |- T8 I* d" g# P. z6 Z) Pif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] : ?- U6 t1 d* n' v. J9 S& S- k
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); * t& _( ?; M  j% p: l
} 6 Q/ c' B& R( L
}
2 S; Q, S5 l4 C4 w* R9 V# S}
  h! ]+ X1 q! A* \3 p</script>
: N% P" [0 w5 J7 u3 ^7 U6 T, ]& x7 J9 ?: _( F
<form name="combo_box">( q5 \& R; o  ]
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
; w4 R9 J" c- F5 A* C3 E7 _  <tr height="24">
0 U2 }* f; g- N$ j9 y; K2 r    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
, y* ?3 n. ~; R. _! e    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
( X7 [: s: p1 G  M2 W- w* R    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
, E! ]; J9 C/ n2 u' J- }3 Z    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
( H! E; |+ n4 I, X  </tr>
9 j, _5 z1 m4 ~8 o6 o# i# e  <tr>
$ ?9 p1 O" i5 k" j& s    <td>( S" k# h0 S2 x& _8 `
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
0 X. R2 t! z+ R; P* w  <option value="0">请选择部门 ---></option>' Q9 j0 ]6 A& A7 R  t% G
<%
% s& P) N+ B0 i, H/ @  G; M    string sqld="select * from tdept";
/ h, B% B! b+ W9 s7 b, z! R' E: Astmt=conn.createstatement();+ U( B( w+ ~5 ?* B% J
rs=stmt.executequery(sqld);' Z. w! r7 o6 ^6 R
while(rs.next())
: L- g. E* m; y5 w8 x9 H5 T{
; O$ U+ Q0 x+ U1 G- t" ]5 P# Y- C5 Y%>8 A. Q% w: H" r, a: o5 W8 H
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>" i1 Q: l8 [: J
<%
7 M: C: A" ~( H+ u6 v1 L1 A0 L( F* H& L}
# `4 p7 @/ a3 o( J- C%>   W) @" C5 ^# k) E+ o  H: a
  </select>
7 |7 q! J; ^7 I( o8 [</td>
0 |! B" V0 U, n' \3 L& A6 J! ?. a    <td>6 `% A: ~8 b+ R9 [0 R" d) X
  <select multiple id=city style="width:150;height:200" class="bgc">
; U( k1 A6 |7 R' z+ c" Y  </select>; H& x4 \* ]# m" P# D
</td>
; A4 u9 E) U4 j9 J7 s& h! [8 v7 j    <td nowrap align="center" class="bgc">
2 q9 z7 w2 |5 |* j( R5 P  <input type="button"  value="<<" class="buttons">
  O  z* q6 ^! B" v+ q8 R( K2 @1 l4 w  <input type="button"  value=">>" class="buttons">
6 w; I2 n8 C* N</td>
' u9 Y/ z* @4 w" w1 X/ i    <td>
7 b: y: s; }; \  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">5 u2 y# L; w6 S: n7 L
  </select>
9 }4 W, l8 k! s# I" }+ X1 @</td>2 |' M$ [1 x, i+ Z( [
  </tr>; q" q! E( t' `# _
    <tr class="bgc">
  |& ~$ F! n9 Q6 g. ?    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>  Q  _' ?# }/ z  D  R3 j- U
  </tr>
# t) n& {+ q  _: G3 V2 L# ?/ r</table>
0 L) V( t0 r- Y* d</form>$ q* q* \$ B, w8 K
<script language="javascript">' q$ |# m- {$ O5 `. N
//人名移动3 Y4 t$ v! w0 b9 p6 Y& ?9 _7 D3 ]
function move(fbox, tbox) {3 H6 L. O. Q# j6 l" ]4 }4 _) F
var arrfbox = new array();
. C4 `5 A( r" h8 Y0 a. C" l) D6 b' E! tvar arrtbox = new array();
0 p! m) Q" {1 V$ `; i( ]var arrlookup = new array();$ B' q& C/ M; p: }& f4 P: S
var i;
/ }- d; u; {! G  K& Ofor (i = 0; i < tbox.options.length; i++) {
0 `- Q6 Q; L4 _9 ~: Narrlookup[tbox.options.text] = tbox.options.value;" s: W/ n0 O( a) u
arrtbox = tbox.options.text;% s* ?# i/ N8 \' h; ^% v( ^+ w
}
# h% z- J# z- s9 S2 mvar flength = 0;6 N, E* q; @' s
var tlength = arrtbox.length;
) K6 ~# ~- b+ Tfor(i = 0; i < fbox.options.length; i++) {
( d" T  f. ^/ n9 l) `arrlookup[fbox.options.text] = fbox.options.value;( o: p' T' \% H" k6 F  ]
if (fbox.options.selected && fbox.options.value != "") {
1 {9 G. y3 f0 e2 S7 k& f6 z5 Karrtbox[tlength] = fbox.options.text;3 V1 @! w+ N1 j- G
tlength++;
9 C9 \. ]% h# s}9 Q5 a  m: C" V( |5 A
else {
; X3 s* \$ Q/ i0 `9 zarrfbox[flength] = fbox.options.text;
) {5 g( ?* c/ D9 O9 w5 W9 tflength++;
: B! r0 C* E% S2 W   }
' f, j: Z' d) X# \% Y3 s}
3 E6 k& r# Z! l+ V. t6 n2 }% @' varrfbox.sort();7 J) C  M- o8 @8 r$ ~3 [" f
arrtbox.sort();) x5 E. b6 V. l2 m' {; Q: Y1 S

2 ~- l& ~0 N- }7 l  Kfbox.length = 0;# B4 X: ~! m+ f
tbox.length = 0;& K' o0 E: p4 A: N; ^7 u# x# H0 f3 V
var c;
- T3 c( r' Q8 z" n4 Ifor(c = 0; c < arrfbox.length; c++) {
% [% u. D6 b$ ^+ l( X7 Nvar no = new option();8 M- |4 a* L! t- F! Y
no.value = arrlookup[arrfbox[c]];$ e, \7 k6 b0 U# ^' |9 u. {
no.text = arrfbox[c];
+ e& c" Z0 d( l: X5 k3 J! u' [fbox[c] = no;
' X9 k) ]8 I7 ^4 a" A3 F}
  o: K, \& @" p8 j" c6 G+ l2 ufor(c = 0; c < arrtbox.length; c++) {
6 c. D' M' X: E7 w) N" _6 cvar no = new option();
+ s1 E: }7 y4 s, q8 y  _no.value = arrlookup[arrtbox[c]];4 \+ s; I1 w) _% X% W3 c/ p' o# c
no.text = arrtbox[c];
3 B. h# }" F) e8 A' P1 `5 N8 Gtbox[c] = no;7 Q" o/ ]  V3 ]
   }
4 a' D! r! N, |8 X+ v8 |' C1 Z( F}
6 [1 ~: _- X0 ]' b0 R  n</script>
- v9 g& `/ H0 T7 r</body>
4 R6 Z. v: Y" h! D' S2 x

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