返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
& z+ W6 v( l+ g9 v         c pageencoding="gb2312"
& H1 }; J, d7 D. X& W, |4 q0 h%>- F2 |* J8 z; v0 K1 c) t$ ^- R5 \
<style>
( R+ }% @. K) q1 L1 R8 i.f9{ font-size:9pt; }6 s2 y6 x$ q, h! C1 h& ~1 O% ~
.bgc{ background-color:#aecaf9; color: #0033ff }& E* m7 C0 Q2 L- P" v/ \8 V! L6 g+ u
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
5 T2 I- X; f( P$ x: V! I  border-bottom: solid 1px #4e7dc1;( v0 E. f, P1 ~9 g+ i$ b; X9 k7 h
  border-left: solid 1px #aecaf9;
+ j, O2 W- F# T  border-right: solid 1px #5679bd;5 m2 B( T( W# p! n+ F& k
  padding:1px;
( {4 d" V( z  Z. u, _  margin:0px;}# i! `& A) b0 g$ s: N: T
</style>( v7 k% a& e9 E
<script language="javascript">
: i. h0 }/ P# y! H2 }<!--+ b$ @+ j0 C) e7 S+ s6 E6 z
function rv()
9 O6 E4 Q# G0 Y  T" g8 |{- }! v! ?+ w0 Q+ A4 V7 ]4 a
  var val="";
6 U1 `# s+ Q, _1 i  for(i=0;i<combo_box.list2.length;i++){% m! ?$ E" E1 w& e* r; W! t
   val+=","+combo_box.list2.value;% w5 B5 ?/ p% J; p7 e4 i
  }3 E' j* A3 q$ v6 {% F9 O" J
  if(val.charat(0)==","){
& ?: ]8 q; c! y2 n   val=val.substr(1,val.length);
3 d* G! H8 A/ c7 s8 r2 g  }8 k/ N. ?& |7 x) K
  opener.form1.frecname.value=val;
& F# j7 E. N( E7 g3 T  x  o  self.close();4 h0 J" c* L: ^$ b! g" R* U
}
( T3 n) R( L0 K# _//-->/ b& C6 ]% h2 o
</script>
% Y* r, j1 }1 Y0 m<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
0 v4 [( I9 I- {  _  o  W<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />: V$ t7 D+ r9 F( h6 \+ P2 n/ @% K
<%
) S# u3 b3 l- `: {. q* ~  I  cdatasource ds=new cdatasource();  //数据联结bean实例! \, v/ B0 i- J1 P  l# q
  java.sql.connection conn=ds.getconnection();
7 |/ G/ w0 n& L* Q  java.sql.statement stmt=null;
  p$ i5 w; X0 \. j3 M  java.sql.resultset rs=null;
# g4 ]' \" G$ F; A: f- a  cdatacheck dc=new cdatacheck();
1 C* h3 P; K1 J1 l: z7 ~%>
2 Z) l4 x' H. }3 u( E" A<%
. e. K2 {# Y+ g( b, Xstring 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";) k& c) s4 r- j5 c* _
stmt=conn.createstatement();
5 \0 X1 `: k& urs=stmt.executequery(sqlu);7 b& D& e% y$ j: b' u2 p
%>/ U- [9 l" F6 i% O
<script language='javascript'>
3 v$ a2 K5 U6 c) V3 H$ `arr = new array();
$ Z( i' X. G* j2 m7 v; R<%  int temp=0;2 n* _5 I" X' T8 q1 u% }. f* Z
while(rs.next())' Z- H  C& P5 x- d0 q: R
{5 [; l1 B0 H0 Q$ N7 v/ K+ H
%>
! I. O9 M& J  Parr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");3 E) H3 Y+ e4 F' d1 F5 C, a
<%
% ~$ |3 @6 b2 Q; _' o( Ltemp = temp + 1;! L- B1 m) ]( m
}
- }+ z* x6 M# c; Z%>
" c1 }1 ^+ w8 v; I& v5 {8 Qtemp=<%=temp%>;7 J, M8 W1 ?7 \) o
function changelocation(id){
& q+ n! [0 V! J8 U2 udocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 1 h8 W- V4 b5 x! ?* C" T* O- A
var i = 0;
, z$ [! W5 Z$ c$ T9 \document.combo_box.city.options[0]=new option('-------','');
; y; m7 A# x1 O! H& k# n$ zfor(i=0;i<temp;i++){
5 O+ F# ^2 t/ wif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]   n5 r# n0 \% }- o
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); # K; E' p( _: E' T2 s0 i/ h, |  _
}
  N  Y& a! r+ e; g} 2 ]5 a# u7 |# L4 J8 a9 ?) |
} 7 i! }, G/ ~- f# f3 Q. H
</script>
8 D) d6 u7 X: |) H% n
% @/ `; |0 k) T* v- h8 X<form name="combo_box"># w; Y5 ~! y4 ]" U
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
0 B. b2 D2 d! I! ~) T% G  <tr height="24">* {* a7 {) P, v; ^/ k1 }2 K, X
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
. o* O" n1 o2 N5 y  O    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
7 }, [) a; c2 v6 I    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
' D9 s8 S! F4 r; K& S3 b0 l! q; s    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>  c9 ]# F: M( C. ~
  </tr>2 o! f# f- A% M" d1 u  I7 x
  <tr>
& A0 `3 t% T" V+ I' X+ ^( m/ _; T+ W    <td>3 h" U5 B. Z' g0 [
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">- @2 l" V8 T7 x3 K
  <option value="0">请选择部门 ---></option>. N" U* {  w5 F# r! f
<%: A/ M. V: \$ C# M# n3 p
    string sqld="select * from tdept";  @( \8 Q8 T% e& e
stmt=conn.createstatement();
* d$ _# T  S5 @3 yrs=stmt.executequery(sqld);& i8 e! o7 L3 |; }- ^& d( s
while(rs.next())
' @2 t' j) f/ K{: l) E" j$ [2 g" ~: u  B* t
%>" p$ R9 x2 @# A6 y6 O* O- b
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
: n3 w* q7 |/ L: U! ~<%
. g/ ^& x3 {* X; h) z" l}5 E+ x1 [( D6 u5 s9 e
%> , L* z, Q- j* f3 A
  </select>
. t4 \2 x4 T, B- s0 x7 g8 b2 _, W* C</td>
3 T* R: ~- v" P; R& g    <td>3 `5 P: S1 d4 N, |& R
  <select multiple id=city style="width:150;height:200" class="bgc">, n5 e8 J9 x& a5 G- |' F
  </select>+ F% o3 L2 i# m+ W7 Y
</td>
4 t& S' d6 L5 `# C5 d- a    <td nowrap align="center" class="bgc">
1 f# m* K8 K5 X  <input type="button"  value="<<" class="buttons">
0 M/ t) v: l: A5 r# U  <input type="button"  value=">>" class="buttons">
9 i5 x! Q7 i$ B- N3 k</td>
1 ^6 g8 S6 H1 D  C: A5 k9 t    <td>& C1 R0 i3 N- e& ^( {; `5 Y
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">1 i: f/ u1 b% B4 F& i
  </select># r7 d3 g/ T; C* C
</td>+ r7 W0 X1 |! ^0 X  r
  </tr>
! V8 l3 X" b* V) X    <tr class="bgc"> 9 R" V# z& q  r- R
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
1 i& ^+ O3 N  |' ^8 [5 F- B( K# `  </tr>
9 \0 O, C1 X+ H/ @& z* O</table>6 ?- U$ }7 z" P, J- }! ^* I
</form>
: N8 a/ \4 a2 d; x1 ~2 T9 ?<script language="javascript">
- ?; b& m3 L" g" c7 B//人名移动
4 D# l0 R1 J* K9 Tfunction move(fbox, tbox) {. Q: P: \: u" x/ N9 }0 Z$ K3 J
var arrfbox = new array();
3 s9 u( D0 G" k* I# t$ s  E$ R& U! F6 ^var arrtbox = new array();
) C( S# J3 k, Gvar arrlookup = new array();
# M- ?! D6 z$ c9 i( M. i5 Ivar i;9 ~& p1 C/ D, j( n1 S  T" H# |
for (i = 0; i < tbox.options.length; i++) {, k" Q+ K, h/ Q' G' y
arrlookup[tbox.options.text] = tbox.options.value;
7 Z* k( w- ?9 E3 _7 `arrtbox = tbox.options.text;2 P4 j* n; L2 l  n' }
}
, I1 q4 X5 h; J! }+ b* |2 |3 L8 jvar flength = 0;
) g  |6 U- ~% |/ U* Mvar tlength = arrtbox.length;
; U' F7 K, b/ N$ `6 o( ]for(i = 0; i < fbox.options.length; i++) {) C" q# I5 _' G/ o0 Y' B7 w* |, U
arrlookup[fbox.options.text] = fbox.options.value;
" P3 @+ ?( a, }2 Z( K& w1 |/ N& V1 iif (fbox.options.selected && fbox.options.value != "") {
* \+ r% J, b# `- |: Y( l  x, a$ j% yarrtbox[tlength] = fbox.options.text;1 c* R( q' Y3 R7 H7 t" i
tlength++;
# A* T! N9 \1 ]& A8 ?# }8 Y$ X+ j}
; H6 J  s6 v- v5 r! Pelse {
' T$ |1 @& V; ?1 W3 U; I* H" ]arrfbox[flength] = fbox.options.text;1 B/ O+ ~; ^$ V& X  {3 L
flength++;! ^9 Q( y3 X0 q! X9 b* ]1 \% t
   }
* R! S9 r* x9 `* `( u' h) C}
' M2 X" U6 n0 R3 y- \arrfbox.sort();2 ^0 }3 E# \; {  z. U. F; o
arrtbox.sort();
) q2 B% [7 `4 A) R3 `+ D: Z3 Q/ H/ U" W
fbox.length = 0;2 D; a7 D9 t7 e2 L2 ?" L7 D
tbox.length = 0;
8 P  o5 S4 ]( ]0 N8 U0 B. Wvar c;( [( H8 T9 z0 l  J8 s* c2 g: L. u0 w
for(c = 0; c < arrfbox.length; c++) {0 W- r3 U* z0 a5 \" e& `: H+ A, L
var no = new option();
+ e2 j) K3 A; z9 H7 K; eno.value = arrlookup[arrfbox[c]];
1 A8 E1 P) `: _' h; yno.text = arrfbox[c];1 h9 f9 A4 t5 F6 ~  a
fbox[c] = no;
: H% B+ r1 L7 z}
/ W  d/ j& c6 i" yfor(c = 0; c < arrtbox.length; c++) {
% F# e  s% k; J. }var no = new option();
4 P$ I& E( n) f; C3 uno.value = arrlookup[arrtbox[c]];
- e, |9 h$ C" t( mno.text = arrtbox[c];
# \" D! O* v# _$ b7 Jtbox[c] = no;; J9 L: p+ ^# q% }
   }
1 v5 f( ~& D6 g3 q6 R: o0 c( L}
/ \1 d* z' r& W( `5 l! X</script>* E' j" `* B% |8 |6 W, g
</body>. E% Q, g, C5 R# ]5 R

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