返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
$ n8 z' m) H- P' ^9 q         c pageencoding="gb2312"$ c8 A- h" e8 }
%>
1 j0 p  R( R$ d( G* D! V<style>
& y/ ~0 ]8 k6 Q. f' a6 T/ I1 x.f9{ font-size:9pt; }6 ~2 s- U, r: s7 G( j
.bgc{ background-color:#aecaf9; color: #0033ff }
, Z& z% t! Z: H# V% r4 e" V.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;. A6 |4 i, o" j, Z
  border-bottom: solid 1px #4e7dc1;
" E7 ]3 G1 L+ P, w" v  }  border-left: solid 1px #aecaf9;
+ B6 u5 o8 c6 Y  border-right: solid 1px #5679bd;2 o7 n0 z+ U4 ^" o. {) J2 m9 Y
  padding:1px;
( N* ^, D; t" R4 w  margin:0px;}
: \* K0 p5 R. [, I' }/ \</style>* u) ]+ \0 b) z# k' g# e
<script language="javascript">
2 F- D- T6 }: a* G<!--9 q5 ^0 W5 Z* W% B
function rv()1 j7 s+ C5 @1 l- a6 w* p
{  \3 Q# k. f+ {# ]% e
  var val="";1 j! i/ a% l% s& Q) M1 r# n# x
  for(i=0;i<combo_box.list2.length;i++){
) U, x) a8 S6 j0 K   val+=","+combo_box.list2.value;
' r3 Q: U1 E: y4 o, Z* Y  }* T( z3 d1 u% k$ q' ?2 u' z
  if(val.charat(0)==","){
: j2 _! I3 n" g( _9 R7 D5 w; o! |  C   val=val.substr(1,val.length);
- B) q1 j4 y& @. X" P4 S" h  }
1 @# R$ i) m1 U* n  opener.form1.frecname.value=val;% V3 W2 x; k7 _: u' {
  self.close();3 L4 I8 @, h( i6 J6 z9 e
}
/ j# Y/ l# M4 A. |0 C9 Q//-->
) \3 k5 z3 S# j6 o4 k9 Q& T</script>
5 u' ^6 z# A& |2 \; Y' n% X5 f<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
% n! r2 V6 v7 d. A" F$ G<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />5 b6 f' V- \0 M$ P3 J
<%5 Y& V' n( [) V5 @* V
  cdatasource ds=new cdatasource();  //数据联结bean实例! e' w+ r+ _7 d
  java.sql.connection conn=ds.getconnection();* w/ r/ g) O. M
  java.sql.statement stmt=null;7 a. @: P5 R! S/ {5 J
  java.sql.resultset rs=null;- g/ I- x8 O* L8 _' m6 B
  cdatacheck dc=new cdatacheck();' J" O2 z5 P0 E6 \- b& P
%>
" Y7 p, d; y4 e2 o$ M, [+ e<%7 A: B9 s9 D' }5 u0 ~
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";# X3 Z& t: g5 q  {$ `
stmt=conn.createstatement();
, t8 u, x0 `- |8 v1 A! f, L+ |rs=stmt.executequery(sqlu);
) x& b# _, Y! c% J) l( |%>
5 \6 z, \- N( o( _' i<script language='javascript'>
+ Q) a" p% U& e* w- v: parr = new array();# c  i! U' r- {; G: c
<%  int temp=0;) l9 b! f1 {/ y
while(rs.next())
. h. u4 D2 v$ ]3 s0 B+ h! m{. m6 u" M2 p" n
%>. r7 [# ^  r9 A" n" X8 ^
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");$ t# u1 t& {8 D; V
<%
( X  _6 J2 D5 S5 W& [& Stemp = temp + 1;
% Z9 E7 {. z" I& w3 c2 Y}
1 H1 s. M2 B5 R; `/ ^%>
! L' @6 a" M% Y+ E4 ?1 btemp=<%=temp%>;
' w' G4 O. g/ h* Vfunction changelocation(id){
" `% ^+ V& l! u* G' wdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
% c. }  O4 v8 F6 B6 Pvar i = 0; 4 ?5 l2 c; u) e  Z8 N* x1 K
document.combo_box.city.options[0]=new option('-------','');
2 `8 `+ t: L1 y% Q% vfor(i=0;i<temp;i++){ ; Z, n+ ~+ T9 u( A, ~
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] * N% _0 j) A& [6 Z3 G" r( X
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
( w  t/ c; |  O8 b$ @) [} * Q/ x2 q! L7 G
} # ^' m3 c& p! D9 U8 E
} 3 \( |* T" d1 i8 t! t& Z# |7 h2 _! G
</script>
, k$ l7 {" E1 W# Z: o6 v( o4 i7 |1 r8 F/ \5 ?' p
<form name="combo_box">
; A1 X& _( \5 ~<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
+ y( K- X( j1 W. k  <tr height="24">
/ v5 \' Z. |% T& b9 D8 J8 d; d    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>9 d* J' G: ~0 |# p: o9 S  k) \
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
1 e9 M/ d7 h2 j    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>& d; e  r  X) {* K* f$ t
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>/ D! g' H$ t) N: B7 f/ O
  </tr>+ ?5 Z( B: @) @4 F0 Z: c
  <tr>
  y3 I3 A" \- A7 Y7 Q    <td>. _. Z9 J  k  z1 P! I' p
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">2 F0 D7 L" l8 m
  <option value="0">请选择部门 ---></option>
, b% w5 J9 I7 D! [* G0 W<%
) ~* O4 L2 \* P: u' c; |9 ?, t    string sqld="select * from tdept";2 h7 j9 S0 h5 R) {* u" l4 t8 j
stmt=conn.createstatement();0 g* R4 q  w4 j+ C5 L) E+ g. k, |
rs=stmt.executequery(sqld);5 y. Y$ l/ o8 K0 p7 p
while(rs.next())5 a1 t9 |, G! }4 a+ p+ h
{
. u7 q* g' ^3 T%>
% n9 d+ {. ?/ m4 W5 c) C  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
0 t: X* Q. Z( B# u% C% o, i<%% a1 v( \0 f7 K8 H; v- a' }3 C3 X
}- o( r2 I7 O0 C5 \
%>
3 i1 [6 U( {% c9 p  </select>- T& p% k" M* [& ~3 Q- r3 _
</td>3 K3 S$ J2 B$ P$ a2 r4 w+ d; {0 t
    <td>
% l" W( @4 r( e. o4 y& p9 b  <select multiple id=city style="width:150;height:200" class="bgc">
* m: D, i+ K  ]/ z7 A: Y6 C% X$ E  </select>* t" |( ~# o# c  ~7 ~
</td>
6 ?# X1 ^. j, S    <td nowrap align="center" class="bgc">0 a$ i9 Z. S! T0 J3 l: }1 P
  <input type="button"  value="<<" class="buttons">
8 j* Y9 w* z4 `& w. n  <input type="button"  value=">>" class="buttons">( Y  q  Q5 f* z) T% |4 Y
</td>
, a5 M! A1 W# J0 \    <td>
5 f: ~: a, `8 g( r9 v  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">) K% L: J( j2 h& }( X8 W, [" P. T
  </select>  V$ z  G% ?2 h0 Q/ H
</td>
2 x' K9 o2 A2 r1 o  </tr>
; j( k5 o" C* f1 @5 O/ x    <tr class="bgc"> $ q% |1 O+ F3 E
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>+ p+ c' j( T$ Y$ t: q% S1 j  T+ f& y
  </tr>$ n) F& N# O# {" I/ d* X
</table>2 E+ S, h6 ?1 s, ~
</form>
4 W$ h2 Z4 o# b3 r<script language="javascript">
) s  y) k# e) A9 q$ G2 [* V//人名移动
( O# l* Q; Z* j( c4 l( R/ n$ x, jfunction move(fbox, tbox) {
+ r( W* `8 T! s( i" |! M" hvar arrfbox = new array();
; f* Z2 \4 F+ a- w5 Vvar arrtbox = new array();2 A$ Z5 c' p  Q
var arrlookup = new array();
$ d/ N& z: z' ^1 n3 nvar i;9 N1 u7 Y  d. K5 P( b% l
for (i = 0; i < tbox.options.length; i++) {
2 }0 x/ [9 c, @8 L0 M  H( G4 L- ~arrlookup[tbox.options.text] = tbox.options.value;
$ v4 G  f/ V- F. v5 p' P6 v# G" Sarrtbox = tbox.options.text;5 m2 g; c  A" F8 \( I' ^( Y6 a( |
}
0 g+ X3 z/ l; kvar flength = 0;
% ?' {* j1 d" b; i) `3 vvar tlength = arrtbox.length;
8 p% I6 b2 Y1 w9 f+ O) D( yfor(i = 0; i < fbox.options.length; i++) {
: ]. L) |+ s. `arrlookup[fbox.options.text] = fbox.options.value;
, Y5 S4 g. F: t9 Y* uif (fbox.options.selected && fbox.options.value != "") {" X( n9 ^" b  d2 T* c3 [
arrtbox[tlength] = fbox.options.text;
1 r$ S  \" @  Ztlength++;
1 k0 k: `2 ~: i0 l9 k5 L, k) E8 m}
9 @4 P8 z6 a1 E. |  {0 p. D8 ?else {+ s$ s7 b& t# `3 @' H/ n1 e
arrfbox[flength] = fbox.options.text;
4 N2 ?3 r6 _8 H6 g5 C! ^% \flength++;
% J  s1 L$ \# v7 w   }
) D$ w% F0 k. k}/ }) b- J) ]4 O" M. ?# e: M1 P
arrfbox.sort();
2 O5 ?$ l6 y6 k, }arrtbox.sort();
3 j+ C2 i1 \5 N6 R
: h% Q- R2 V3 p; Xfbox.length = 0;# S/ D, B6 K3 ^0 I" X7 E
tbox.length = 0;
  p( L0 G/ M$ j* e# |var c;# s, i8 X6 n5 c# U; o1 U7 G1 J
for(c = 0; c < arrfbox.length; c++) {- s5 k( H5 ]6 `9 W
var no = new option();$ }& o% Y4 p/ \/ e% e
no.value = arrlookup[arrfbox[c]];+ P6 f- O9 J5 d; o
no.text = arrfbox[c];/ R9 a4 J& |+ F; V7 @
fbox[c] = no;
+ a* Q+ P  T* C, j! U}+ ?0 I& {0 u( q
for(c = 0; c < arrtbox.length; c++) {
. I! ?2 f- t" F1 Y/ Y* \var no = new option();
" \: V9 ]3 L# G: D* f; Tno.value = arrlookup[arrtbox[c]];  F3 N. E" T# @' N1 W- v
no.text = arrtbox[c];
' \* T# i# i  e* c) Dtbox[c] = no;  }* ^* |; J* [" L
   }, E5 }/ D& ]: _8 U9 z; ?
}
1 i/ S1 Y% t; @: i# E) m</script>
- U' R# q# k# c: f" I</body>
% a- S! T1 q6 M. Z4 M$ H

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