返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
; o/ p1 }% b  l3 I7 D         c pageencoding="gb2312"8 ]2 [! c9 ?4 y6 ?" C" _+ R
%>6 f7 ~9 l" G% c, \1 W* C, e4 O
<style>" y7 f( W$ _$ v, [8 p$ s9 G; Y
.f9{ font-size:9pt; }
1 Z1 W: o4 R* _1 `7 d: {, ]1 X# X.bgc{ background-color:#aecaf9; color: #0033ff }8 O* |+ q* P' C( j, o
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;: a- V% K6 z. ~$ s! b, ~4 B# U  ]
  border-bottom: solid 1px #4e7dc1;
, T5 j5 v& @$ ^- P6 ^% p  border-left: solid 1px #aecaf9;
& y/ z" s7 P5 T! H: C  border-right: solid 1px #5679bd;
  y1 O: L- n) |& d( ~& K  padding:1px;
# q& d0 n0 v- O) n# k  margin:0px;}
8 \) b; E* u: L</style>
& u, z5 G7 W7 w2 U, j3 f<script language="javascript">
. X0 R- F! ]7 |5 U9 K8 V9 m<!--
1 s) e; P: q" ?' U+ m$ vfunction rv()% }! j) v! S* Q+ B; a. B+ Z& g$ z" d
{7 z0 E( F. ?& g1 O6 F9 e
  var val="";
% S6 |6 s8 M0 \, ?4 B+ w  for(i=0;i<combo_box.list2.length;i++){" D$ c- e" M4 O+ G
   val+=","+combo_box.list2.value;! R! ]- ~. G1 `# {& p+ i
  }
# x' q6 ^- l( T, t9 D  if(val.charat(0)==","){' C( }% Q5 Y$ S$ W3 {5 l
   val=val.substr(1,val.length);
/ a5 d) n( a" P# a. E  }
( z) [- M8 p* u3 L2 \. ]+ l0 a" M: c  opener.form1.frecname.value=val;& X' A9 r: h- o  l8 Y* y+ \! ?
  self.close();8 s$ Z# K; p2 Q1 @! J
}
9 ]- X: o' [# u  m3 R" `//-->
7 J0 h3 T% y  Q1 d% l/ J6 m</script>  G( k& g1 j; K! G1 T
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
- @9 p# a3 M$ j5 Q3 E3 k$ \. E<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
& d  j& }8 m. u1 Q<%0 v% t  K( _* e1 B
  cdatasource ds=new cdatasource();  //数据联结bean实例
- b1 b9 W0 }9 a1 x) H  java.sql.connection conn=ds.getconnection();3 R: g" g% l& j- F! ^; ]1 T
  java.sql.statement stmt=null;
! H8 O4 @  I  G' r: _! l' B: E; m  java.sql.resultset rs=null;
; v* Q# {6 b5 o  cdatacheck dc=new cdatacheck();
% ?! Q+ B1 Q) O& l: l%>
) }$ x* a. J! i8 C% B: m<%+ z4 L- O  ~- [* m: U
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";4 V3 f/ G$ `  a3 \  \1 {
stmt=conn.createstatement();
4 t4 z$ C3 m: U8 jrs=stmt.executequery(sqlu);4 t5 C3 c, `0 ]& x1 D
%>' [& g9 d4 g& O+ p% E3 B. U
<script language='javascript'>
" F4 f/ A; ]; F; T) qarr = new array();
( d2 b0 m4 n  Y<%  int temp=0;' h4 [- K/ S6 @! i
while(rs.next())) H& {  Y4 l2 B: N4 U4 B! e
{% c1 a( p8 d5 Z
%>
! S) d: U. O* W: J4 }5 ]arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
, U% K( M  F) w  e' h<%% ^5 N& i. g. j' i4 n5 c6 s
temp = temp + 1;
6 M6 J- f/ G) e' O" E1 c. W}
& {; D% _, s- T3 b4 d2 [. p9 }%>- f" C. F- X# N. P
temp=<%=temp%>;
; G2 n4 H$ W9 E: M" A3 _function changelocation(id){ " F+ w  G% z% ~+ _; O; a
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
  z/ c# `8 D$ ]" }; ]+ U/ [! x: Mvar i = 0;
' E. ?$ ~' {  C/ u/ Mdocument.combo_box.city.options[0]=new option('-------','');
" h0 a! b- U$ J7 t" u) N0 e" rfor(i=0;i<temp;i++){ 8 V4 c( ]' S# I0 }0 q$ u. M
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
% [* G; |' O4 ]$ W3 w( `document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
8 u3 E! T+ i" j) i} ! x5 D& Z2 F5 S# q; ?
}
- u* d) ^- |( e& ~}
! K9 [( ~$ L% d# A( X' |</script>
! z- G  \1 K/ I$ a! s
3 y+ c, B5 z2 K+ H9 v<form name="combo_box">* s; `& f/ h" T9 ^. _8 T
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">& |) T2 j1 G7 r( U: Z. y+ L
  <tr height="24">
5 o' ^. T: M* w0 L& m    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
" t# n) p7 R. F7 R3 M    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>4 }' B! M/ u6 s1 b
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>6 m& t( J* \/ O( C0 Y  T) B6 O
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>$ {/ ^2 N9 w  C# b
  </tr>
" }0 \% k8 O- x9 b' p  <tr>
8 k5 G) j  b! w3 N    <td>9 e# F" C/ h5 F: D" ^
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">* w; x. o2 [& H* z+ X
  <option value="0">请选择部门 ---></option>
: S; ]/ i, \7 q! x# P<%" }* j* o% K. q7 x# H* J( n$ P# r
    string sqld="select * from tdept";
) ?- W+ j% s1 O9 p, z& n5 v2 Istmt=conn.createstatement();
: t& s6 A) a! {, \+ {rs=stmt.executequery(sqld);; _1 K+ G. O( M0 @) T) G( o' _
while(rs.next())
0 Y- ]7 u& h! J  B6 D) e{4 l, I6 V4 P$ W
%>
+ M1 I4 U5 R1 O: O1 r4 I  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
0 E( B8 @$ P( H6 _( ?<%# }: i% b1 u9 c: n) \8 @
}
  P/ t9 _. V4 m. g3 s%> ; n4 c) G, c' D% y2 H  K" M
  </select>
1 ^  j& q5 R; k( J( k( q</td>+ j/ P& r  {! l1 t
    <td># f; \2 l' `0 A. N4 ~0 U+ X1 l$ q
  <select multiple id=city style="width:150;height:200" class="bgc">
! T1 n$ j  n3 ?, P+ T7 k5 W  </select>7 f+ X+ I2 O& t6 d2 H
</td>
& Q1 q: {4 u  q7 ]2 q2 t6 R    <td nowrap align="center" class="bgc">
2 }+ ]1 z2 T& U& p  <input type="button"  value="<<" class="buttons">
9 @2 m" B. \9 F8 p  <input type="button"  value=">>" class="buttons">
9 b, B, ]6 b: b: ^' U0 H' I</td>
% n- R8 s( O4 T; y+ A$ F    <td>
* h3 n  N1 {3 ~  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">) ^# D+ l' f8 J8 B8 J9 j, t
  </select>) x) C2 M+ O5 e6 w
</td>( z/ q4 u: y* T
  </tr>  ^( p7 m3 i, s& H* C4 a
    <tr class="bgc">
5 E# ?0 R# R3 ]0 t! L$ O& h    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
( k, Q9 W! k$ k. |& a1 Q! }  </tr>3 l3 r+ G  V5 Q' E
</table>$ i( D$ ?& n( U) `9 `8 j9 p
</form>
4 r+ t+ {3 v! _, ?<script language="javascript">) ~; d+ R# M" V, a1 [2 D+ Z
//人名移动
7 @* k! L0 A+ A& l9 U: F7 Gfunction move(fbox, tbox) {0 E) d1 Y3 c/ j$ [/ c
var arrfbox = new array();
) N2 t( e2 h! W8 q- S' Kvar arrtbox = new array();
2 T6 R- d4 ?7 v( _7 i% G' H" l3 E. ovar arrlookup = new array();
# ?  W* Q/ H* D8 {3 K5 ?4 mvar i;
. N9 [% W' R+ N- [: H* T: Q; J- T0 O/ ?+ rfor (i = 0; i < tbox.options.length; i++) {
' v# h$ P0 O4 v8 `9 H: Y! Marrlookup[tbox.options.text] = tbox.options.value;
8 |  {5 `* M6 Q* B9 Earrtbox = tbox.options.text;2 p& D0 I+ R' K' Z$ s" ?) f# q
}
) C" _% q- C- Ivar flength = 0;. j, ^7 }; E+ q1 z/ ?5 a$ ?" j
var tlength = arrtbox.length;
( f: G2 C. o0 ~8 u4 I; sfor(i = 0; i < fbox.options.length; i++) {
; y9 d. x5 [2 k6 X4 U2 [$ Z5 Marrlookup[fbox.options.text] = fbox.options.value;" @  ]+ U4 i2 R
if (fbox.options.selected && fbox.options.value != "") {
4 E; o. b& q# I3 ~0 V1 K+ H. ]arrtbox[tlength] = fbox.options.text;2 K  U" [# U+ o$ I  ^, f
tlength++;* Z$ K' I) v/ A
}
- D/ l$ E, }2 \4 _else {
; f3 L, j8 O; _3 Z' y. j2 o2 F( L: ^arrfbox[flength] = fbox.options.text;. `# y5 p: t! g9 i7 X/ P* X
flength++;
1 a( g* `! C( @8 G   }
+ S+ g/ y& U) Y2 e}
6 Y/ S# n5 y( `* Narrfbox.sort();
' Q$ |* Z% H; [  h) i" rarrtbox.sort();( G# i5 l/ [( J0 J
+ t* ?8 y7 h; y2 k  e3 l& G3 Y
fbox.length = 0;6 [5 U; d: F% O  R8 [3 u
tbox.length = 0;
  `1 }' w4 b% g2 Bvar c;; k& ~: F3 m, c8 }$ B1 T4 G
for(c = 0; c < arrfbox.length; c++) {
/ p* A8 r. j& zvar no = new option();
9 S  t* e3 L+ _  _6 ?no.value = arrlookup[arrfbox[c]];! E$ b" n4 n# O3 r/ F
no.text = arrfbox[c];. o+ y% ^; o9 m! n& G) e3 X" _
fbox[c] = no;5 A, N: f5 M: h! D# T
}
+ ~6 P. q/ r* \6 Ifor(c = 0; c < arrtbox.length; c++) {/ S7 w  o2 W% q1 P
var no = new option();
; E  O) ^& _5 d1 l7 L6 D2 f* Hno.value = arrlookup[arrtbox[c]];6 `6 J" c( \# _1 R% }7 O! J
no.text = arrtbox[c];
5 _/ j& |6 G, W$ Gtbox[c] = no;- L% s3 }' X+ j( \$ C3 X
   }
; u" s7 a) {( ?+ _}
- R3 m) e( F* s</script>
0 G2 G+ P$ Q+ ~% Q6 o</body>
; q3 V/ g1 C9 N8 [! O2 ]0 b$ C

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