返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"9 e9 n4 u& {# l0 m
         c pageencoding="gb2312"
' g# V! D' v, ?3 v& Q# @$ o' b%>
! v8 N5 Q# f8 C$ ~<style>
& O! a  o. r1 M4 X0 ]( j7 p.f9{ font-size:9pt; }" b, g( l5 |6 k- x7 t
.bgc{ background-color:#aecaf9; color: #0033ff }
; V, x4 r5 p9 g  }2 D. R4 ~/ j.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
1 N' M0 k% Y5 x, f7 A  border-bottom: solid 1px #4e7dc1;
7 a" k, j1 q( {7 S  border-left: solid 1px #aecaf9;
! T. v3 D  ], _: Q. B2 J6 G; R7 w2 k( |  border-right: solid 1px #5679bd;! m: o" L% a6 M! D. \# O
  padding:1px;0 Z+ `- _9 z' A
  margin:0px;}
3 H" l) V$ T- I; p, q</style>
3 W5 ~$ }9 h  t: b<script language="javascript">
: u& U$ b3 u4 Z8 n1 M<!--
- Q) W( P: l0 hfunction rv()- R$ d9 V' k4 l" s0 r8 X1 E3 q
{6 M- U: o4 }, n8 ~+ L
  var val="";7 x+ |( A) }$ G& ^
  for(i=0;i<combo_box.list2.length;i++){
; m+ N) G5 ~0 a, A. h   val+=","+combo_box.list2.value;
7 x0 k9 H2 O* H0 K& x  }: t2 e& F5 B0 ~. r# M- ^
  if(val.charat(0)==","){6 i# r* N7 Y7 P" v! |
   val=val.substr(1,val.length);; L% j! B+ |, H+ I# n( x
  }
8 U6 X/ i" K9 _+ X  opener.form1.frecname.value=val;# H8 r1 f: q5 W4 X5 w
  self.close();
' y6 e1 H  t% {# h, k* J8 t}
' e! e2 Y9 A" }% L//-->
- T8 S3 b( t* K( r8 s</script>  M$ ^* `! J! h, c
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">6 t  B- U, S$ O* P/ [
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
/ P7 ?' q5 c3 X3 b5 m5 ]# H<%4 d/ h6 V2 [  |
  cdatasource ds=new cdatasource();  //数据联结bean实例: `- _% b; ^! {: [) l6 W
  java.sql.connection conn=ds.getconnection();
3 ^4 a8 F- l3 X# [  java.sql.statement stmt=null;" v$ q, F) L9 [7 E
  java.sql.resultset rs=null;
  Z- O$ \5 O2 Q$ l! i; Q( D  cdatacheck dc=new cdatacheck();+ j3 S' M- E6 Z3 B2 }: A) g
%>
- A, K& u* H# O" ^) Y! J<%: o/ A5 T! s0 V  ]# T1 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";
1 P6 y! K% R9 \$ ?/ F3 Vstmt=conn.createstatement();; I7 V+ m. l0 j  }
rs=stmt.executequery(sqlu);$ |+ a) a! g9 J' Z/ A: i5 Q' L
%>
1 h; ^, d3 h/ G5 D<script language='javascript'>
( I* p" `; M1 O! D+ p9 i$ L$ Aarr = new array();
5 c0 z# e  ~0 |<%  int temp=0;
* V; G/ z; L( Nwhile(rs.next())5 G) c; l3 v7 Y+ ~% y( i' T
{* r3 I3 g4 {. j( J7 Q/ z
%>
5 ^0 v4 c! f  o! J0 v* xarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
7 m3 _8 ^9 @- m$ u8 k<%* q% D2 Y( L9 @
temp = temp + 1;
1 a3 `" c8 C3 ~2 W: g}+ Z1 o1 C# @3 M  S) G& s/ D( j
%>4 Z8 `( R) L7 Q3 B, u
temp=<%=temp%>;
6 P& S/ q( n2 D5 ~& T' I) W" z. a2 T  Bfunction changelocation(id){ + w& Y) i5 p8 d! Z, j
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 ; N0 @4 i" }: K. `2 j, j
var i = 0; & f. t% Z; ~4 U3 l1 n
document.combo_box.city.options[0]=new option('-------','');
" h6 B/ R% c. Q$ Tfor(i=0;i<temp;i++){ 1 q5 Z0 [* C3 v/ y" f
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] : E9 \4 @3 E3 t# l7 Y3 _5 I/ w5 @
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
3 K  k0 U( m. v) R} * l9 p5 y4 a1 m" p) ?" V+ |) @
} 9 f& i6 v' z. }) k* k
} # h  ~1 g% H. s1 i+ o. W
</script>
( M2 K  z" w; c
- {9 J% v# N" u' P<form name="combo_box">
  a' J( b5 T6 q" M<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">6 m, ]" L4 Y; f# S8 R, ]. l. }: D8 C! W
  <tr height="24">0 h9 b& J/ V: }0 {, D7 j9 x
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
) L# Z* U# I$ U: E- _% |* L    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
1 B6 M* M. V! h. o) A    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
# ?# A7 r8 m; f: w0 m    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
$ h% _- a$ P  I! Z; F- U  </tr>
: a- _, j8 x! r2 n  <tr>
3 c3 @) U% v: P, k    <td>6 r) T: y) A  Y, [% n; R0 f
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
5 t4 g3 [; a, T  a, ]1 C: y  <option value="0">请选择部门 ---></option>
( [" k) d+ K9 \9 a4 v/ n<%
% ~: f8 R1 q1 X9 _+ x8 B    string sqld="select * from tdept";
& ]% h+ Y: @9 C5 b% G, Zstmt=conn.createstatement();
- d! N3 y8 K& T0 \& I7 c$ Crs=stmt.executequery(sqld);
# s' {. c3 P) |+ Q/ owhile(rs.next())6 j' e6 ~: D. o6 J1 c7 Z9 ]
{. _5 s7 |$ p+ S1 D0 h+ f" n
%>
7 f5 Y. k/ o1 S9 A( B  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
1 t. Z4 a7 p" x" x' o) a<%7 V9 e4 I- \0 r9 Y) T) a7 }" O) Z
}
3 e2 x1 n+ q% b3 }& u( Y& D: V1 z: }%>
  k; Y& r& k) u: P  </select>* Z$ |  u( j5 M
</td>
% ~, @7 T  {( u0 o: @- Y! o    <td>! ?1 C- M( J4 l4 s( n
  <select multiple id=city style="width:150;height:200" class="bgc">3 |' H" L# ]4 P
  </select>
% {( Y! r/ K/ N" f) J! i- A- D. z2 `</td>9 m" F4 L4 H2 d4 K) t6 N& ?
    <td nowrap align="center" class="bgc">2 `& x9 o2 [$ }3 W
  <input type="button"  value="<<" class="buttons">
$ Q6 A5 ^2 H# Q9 J  <input type="button"  value=">>" class="buttons">+ N; ?* r4 J' Z  F' K# l$ a
</td>+ h. p  q- ^. f  e% m, n9 E% k
    <td>7 H: @& `2 e" h7 s. N
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">  {0 y: J$ `! R+ V1 y% s
  </select># ~* z+ L+ D' P  j$ Z
</td>
- d& G3 h5 ~* x- E9 u  </tr>; q  l; q7 i; q' M
    <tr class="bgc"> 8 b8 I  v! ?$ ?
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
: ^% f# k8 [, n+ H  </tr>2 X5 _* p  y+ A0 r* \8 j' V" e
</table>
1 P$ ^. @8 {6 Q1 @: C" z- R/ f</form>
# \0 y9 W7 ^* n9 ]4 g# ]  J<script language="javascript">3 J& q" c" I" j; C& K1 ]) K* d/ a
//人名移动
/ a, N/ E9 N. u! @; gfunction move(fbox, tbox) {
1 f- d. z/ K' p% c& Bvar arrfbox = new array();+ {# n" U+ r+ G( N
var arrtbox = new array();
: m; G, q2 {0 W, {! h* I, r2 uvar arrlookup = new array();
% J$ y( G, o$ [' e; A- @% [( tvar i;! h' t7 J) B+ ]$ @. {, k
for (i = 0; i < tbox.options.length; i++) {2 [2 F* O9 i) g9 P: A5 z
arrlookup[tbox.options.text] = tbox.options.value;
: L9 \, E. ?5 |5 N1 y2 karrtbox = tbox.options.text;, T3 O* p* i0 }  O# A& {3 ?
}& E/ {9 c3 b' _& I) ~" [$ u
var flength = 0;& [( S& ]' h& f5 L
var tlength = arrtbox.length;
/ A/ K6 C7 U4 W5 u2 Tfor(i = 0; i < fbox.options.length; i++) {
7 B% |$ f" C! R* varrlookup[fbox.options.text] = fbox.options.value;4 Q/ E  w  d/ p! X/ s. c4 _& Q' V
if (fbox.options.selected && fbox.options.value != "") {" T7 p/ r! T/ j$ a5 N9 r& O
arrtbox[tlength] = fbox.options.text;) ?) J, L( A2 x' X
tlength++;# M( b0 Z0 k. W% p! Z6 F( s- `$ L
}  z* p+ e9 b- Q, o
else {' i# R! P6 M8 y. f" X% P
arrfbox[flength] = fbox.options.text;3 [) D4 t1 f* V& f4 T
flength++;
: `$ c4 e8 s! t" W7 y) n   }6 E9 }: k; ^" G( _: a9 u3 p
}
0 u. D( K; x, Z/ uarrfbox.sort();
1 ~4 T4 ?1 ?0 z' x! G$ f2 E+ Y% `arrtbox.sort();
! C; F6 i& L% l
4 S1 K1 v; Q& H% @8 [' h( t2 ufbox.length = 0;
- G9 V+ [% h6 {% Q9 U0 \1 }' ]tbox.length = 0;
" u& D- k# z4 [var c;
; q% a3 G; h) [/ vfor(c = 0; c < arrfbox.length; c++) {
. O6 z1 Y- R" L) G7 C! B9 \var no = new option();3 C6 w- b6 {9 U- Q) p7 e: V6 u
no.value = arrlookup[arrfbox[c]];. u" A/ T$ w% }, f1 v, U+ w9 ]
no.text = arrfbox[c];
* |) |' H8 u& g- {# }) wfbox[c] = no;
+ Z0 J3 f, i4 _}
+ s+ |4 b9 `3 |% V3 Qfor(c = 0; c < arrtbox.length; c++) {
3 {- |0 z$ b1 a8 Svar no = new option();0 B+ ^% ^" V3 j
no.value = arrlookup[arrtbox[c]];; ~* o: d. d. W' ~1 i
no.text = arrtbox[c];
) ~& C$ O' Z# Z, Btbox[c] = no;
+ u2 |% c3 Q! ^+ M" M   }1 W: x' h0 j- U% n6 b  @' u
}
/ L; d4 ^: k  C( Z</script>
* v5 d& {. U) y, O0 r5 R# L! b, p</body>8 i- C0 v! |. L. X. _' a

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