返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
. y( D6 }  V& S         c pageencoding="gb2312"
+ y8 t# g) _1 R1 P7 ^! V%>1 e& S) q- [4 e
<style>
$ A0 Y8 R/ \# S5 h/ b8 r# T.f9{ font-size:9pt; }5 P! {; K$ g; Y$ D5 F/ {6 ]* ~0 E1 Q" r
.bgc{ background-color:#aecaf9; color: #0033ff }
; {  @5 P6 T/ F3 k0 b.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;! \: b* l2 L2 y0 [) i! B
  border-bottom: solid 1px #4e7dc1;' T" e$ l  u. t* w( z, V) ^/ R
  border-left: solid 1px #aecaf9;7 u* B0 B* n3 P5 A( w) _/ F- [
  border-right: solid 1px #5679bd;5 P0 n6 T8 y% j( C( ~6 k. K1 A" a
  padding:1px;# g) k0 a+ ~; |% e2 \( I2 ?5 i1 T
  margin:0px;}
$ X8 H. x3 ^; v3 Q% S  f</style>
6 u/ Q- Y# U0 m- o<script language="javascript">: {5 J. H+ }: J+ g
<!--' q" i& D& B0 i
function rv()
" {# d) `% Y$ p* F+ m{6 f9 z1 P( U( B3 u% Z3 q! d- F
  var val="";
- k* A5 ^, `  K" [4 g9 O  for(i=0;i<combo_box.list2.length;i++){
4 L9 _1 [8 R3 S  ?6 k( V  t   val+=","+combo_box.list2.value;1 o' \* ?. B: i! J( C6 Y
  }
6 G8 P9 T6 A+ o" O8 M  if(val.charat(0)==","){! v0 I/ J; r4 Z& J* B$ z
   val=val.substr(1,val.length);0 A8 i0 g& F# q
  }- c% J* j$ o0 n. z
  opener.form1.frecname.value=val;
2 Q' i& W0 g0 z9 e2 t' E8 u  self.close();5 D! t7 E2 e' t
}" U5 b# y! O$ b9 g4 \4 _3 }
//-->% n# X+ `* L7 }5 `9 Y
</script>1 D. W* t+ U0 L! l* ^
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">8 i. r' A4 D% ]; w5 x
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />; `5 y4 ~  k6 B% x, M3 Q
<%- w  _9 w8 s8 w; b5 g; U" c
  cdatasource ds=new cdatasource();  //数据联结bean实例
4 R2 v% ~$ N  D2 o- G# B  java.sql.connection conn=ds.getconnection();3 [$ J! O$ k/ Q5 P9 B
  java.sql.statement stmt=null;
& S+ j; F: A" }% k+ v5 U  java.sql.resultset rs=null;
  o, o  X, H$ l  cdatacheck dc=new cdatacheck();
7 H  X% i& l# R%>
" x0 U3 z! C1 P, h* H$ z4 z<%+ p% W3 S) i# _( l3 O6 Y7 d
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 x+ U2 J4 G7 E6 H' B2 E# H" R3 Xstmt=conn.createstatement();
* H: p+ ?  c  \/ P- P$ crs=stmt.executequery(sqlu);+ b9 H, S* Q+ `; ^! s, r
%>+ u6 m' a; X- V: L9 p- F5 k3 j
<script language='javascript'>
: S3 O* s  H# n' A* zarr = new array();6 r1 |/ r; D1 x2 s% `4 i9 b; W4 A
<%  int temp=0;* ?& a$ ~5 d4 K. z& l
while(rs.next())
: p$ G/ l/ v+ u3 a2 [{8 d/ b3 B! i  x" f
%>
! j3 p. D* g1 a7 U* i+ Barr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");. i+ @9 T$ a9 d" _8 n, U4 L6 t
<%
! ~& v# @& W  ftemp = temp + 1;
0 c9 o- O1 ~  `  |: Z8 E}; D) h! d: o# }4 h# D
%>0 Z) ^  Q6 t  N) \* `
temp=<%=temp%>;
( B" E- T& Z" F" S* j/ v& Tfunction changelocation(id){
- k/ M% J9 ?3 m1 E1 n) Ldocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
- `$ n) F8 S( ]1 W7 [0 y; X+ l/ kvar i = 0;
% s/ s, ?% J5 n& ?  V+ z( X0 S  odocument.combo_box.city.options[0]=new option('-------','');
9 w) r8 P# X4 r- ~' t) U# Yfor(i=0;i<temp;i++){
) i/ ]4 b+ o* Vif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] ; B# f3 W. x8 E9 T5 _% a7 ]! Y
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); " i2 t: \; H5 B0 F: a* A
}
  a+ S0 X  X6 Z; |& Q0 _# H, Q}
: ~, S: A) Z& l) g: R5 Y/ R+ l} ' u# ~% T+ T/ \2 x6 V: b1 D
</script>9 h* N& ]6 o/ g5 m1 e

  q" _  `3 l8 ?4 |<form name="combo_box">. h/ P* ^3 e$ {: E
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
2 w# T3 Z/ Y4 [* ^- R% `% x9 v  H! [; |  <tr height="24">( Z0 j8 a% C' I) R1 t
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>4 i2 s$ ]* o" E% a* n
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
- S8 V2 t  h) `2 U) s    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
* P, R9 Q$ X) @% f# K    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
! R  r3 ?8 U; o2 x  </tr>
( p& N# \7 y& c# e$ H* D  <tr>
' u4 N1 z5 J5 y& K    <td>8 e! K5 A. z# C, [
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">9 ~: A; B$ C) V& |# {9 H6 P5 g
  <option value="0">请选择部门 ---></option>
5 f) L1 ]2 c" ~<%
8 z1 p7 C# `( x; B1 S    string sqld="select * from tdept";
5 X* s1 `- z' w9 G* z5 G$ \1 Bstmt=conn.createstatement();
+ w6 v' @  Y, {$ I7 c! K# s# i3 Zrs=stmt.executequery(sqld);
0 E% x8 Y3 V1 B5 Owhile(rs.next())  a: `' v6 Q& Q" w
{( n- u) ]. Q9 m: V6 j6 ]/ j' F
%>2 |+ }6 x0 S3 g. [  E2 R0 \0 l
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
  ]2 H. l' R0 z7 `  w  R9 {( E<%
4 Q4 J1 h  F) Y  N; Z+ M}- i% k- @+ n; `# o
%> 0 F5 R5 r/ P. B* k: w5 g
  </select>% B7 R$ c0 h2 h0 r# G! \- J2 K& R
</td>
0 L( F7 J, Z- H( s    <td>
$ O  `+ C; T- ^( F  <select multiple id=city style="width:150;height:200" class="bgc">, i. u; v! A7 J( P3 @
  </select>
. A: ?( F' x8 _: l9 i& q# x- _</td>- o" D8 Z5 _) d+ b
    <td nowrap align="center" class="bgc">) A  G+ N7 ]. e' e  ]! u  g$ L
  <input type="button"  value="<<" class="buttons">6 j* C, g4 X9 G( M
  <input type="button"  value=">>" class="buttons">
5 y% T" J* M" X7 {; B3 \; ?. o</td># e2 O+ i0 X8 L3 T( l6 v; Q9 W
    <td>
$ R; ~" d: x% E5 J  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
7 _8 Y; l. ~4 ~: u5 ?+ L3 f  </select>) }+ A5 W# I0 K, R4 H6 e) f
</td>
( C0 j' |* u1 M* r  a  </tr>. k: w, |. U! G1 D
    <tr class="bgc"> 3 Y9 x7 n$ z; q& S
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
) _& `7 x" F, Y6 c/ }( J% V0 U" n  </tr>+ p. A# I+ U$ p% H
</table>* n7 p) t6 J# |9 y) I- p
</form>/ ?9 B0 N" f& O4 c' `: S
<script language="javascript">
0 C1 }" x! ^, S//人名移动
) ?4 J+ \$ q/ X7 Qfunction move(fbox, tbox) {
. P0 H5 U% J8 U' f" y! R! b( ]0 qvar arrfbox = new array();* ]6 T1 v$ \/ |# r/ i
var arrtbox = new array();
* t' f% d9 v3 Q4 B& Y& Z  ovar arrlookup = new array();, Z* F, @$ v. w
var i;
3 E, {8 Q9 |, k/ ifor (i = 0; i < tbox.options.length; i++) {( l$ m2 b/ h" t. Z/ z0 B
arrlookup[tbox.options.text] = tbox.options.value;
3 F2 _5 j5 }2 I3 J$ D4 C# Barrtbox = tbox.options.text;7 P& K* @% {% ^/ e6 o6 ^+ i
}
( W7 z" }. y  Y. Vvar flength = 0;; k' `- W+ V# k5 a/ T5 \
var tlength = arrtbox.length;
3 V. D8 q7 t/ x) P; b' lfor(i = 0; i < fbox.options.length; i++) {
  O; T( P. q( z  n" Karrlookup[fbox.options.text] = fbox.options.value;
( M# |" s+ X# {, eif (fbox.options.selected && fbox.options.value != "") {# E& k% G6 i: s+ }" q
arrtbox[tlength] = fbox.options.text;
; F! N$ S5 h) f( f7 i! rtlength++;5 `+ w7 o2 e+ T' ?
}
) E! {; R3 ~% p2 @& T) ielse {
2 g* z& r' p9 r& P! f0 u, P% j8 ]& Oarrfbox[flength] = fbox.options.text;
; b! u: X) N7 J2 ?/ fflength++;
4 }# S: B. O3 U4 N! v   }6 M2 q& x  f, l& F7 a) g: d
}
2 t0 J5 o9 Z' F4 A( H: \2 warrfbox.sort();$ @2 p. t1 X% N  f) ]
arrtbox.sort();) a$ }6 T" B+ H5 G3 a$ R. B7 C" x

1 D$ {3 A* k+ E  dfbox.length = 0;+ H8 U  M3 B7 ~) _& `# b1 [1 D
tbox.length = 0;7 X' o; M# X7 M/ A0 c
var c;- r  e4 E1 k6 c
for(c = 0; c < arrfbox.length; c++) {
. I8 G4 o+ a7 S& T' pvar no = new option();
" n, v+ m' I5 {* f2 F1 G1 H( Z3 xno.value = arrlookup[arrfbox[c]];
$ S7 O: N& E6 Q! }no.text = arrfbox[c];6 K; H  S7 ]5 k4 Y$ e9 W1 F( D
fbox[c] = no;
/ {1 Q& e9 c9 L3 ]$ d}
* A$ a; S& K) c7 h) a" F  i! Afor(c = 0; c < arrtbox.length; c++) {
+ D. u  I8 \2 e( g  ]: p5 Tvar no = new option();2 @0 N1 ~! e: K, Y
no.value = arrlookup[arrtbox[c]];/ G2 w2 C  `- m8 g- I
no.text = arrtbox[c];
/ U- Y: Q# K, `tbox[c] = no;1 P, Z( q0 I2 H! _4 `
   }% z. i4 q  e% I4 R' l& c
}0 x% T. y$ ]" o
</script>
* n6 K$ `; ?# t2 p( V</body>
. q8 r8 _1 R9 n5 o

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