返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
" t- A& v6 k* Z# I) ?% N$ q3 \         c pageencoding="gb2312"
& B* f- F) x, Z! D% U4 l1 h) v( x%>
: N3 A$ O/ B1 M* z: O0 z9 h<style>
7 c: ]" A2 m) M. S/ c/ F9 D: G.f9{ font-size:9pt; }% }! L# V8 w; ^: a6 A
.bgc{ background-color:#aecaf9; color: #0033ff }! J& @/ g: w* l$ Z3 E+ [
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;8 G8 _" Z5 W4 @" P
  border-bottom: solid 1px #4e7dc1;
( m2 G7 M: D: j. ~  border-left: solid 1px #aecaf9;/ a; f: g5 F. q- E% O* K6 |
  border-right: solid 1px #5679bd;7 }* W! Z$ [' @' ?: M! k7 Z
  padding:1px;. V, _3 }- c4 ?6 r/ t$ w
  margin:0px;}4 x+ @) b% z: x1 v7 W: k. L
</style>5 l+ V3 K8 v4 [
<script language="javascript">4 b5 K  u: e; u4 o! i9 Y2 L* e
<!--
, a7 e  u9 [" x! ?4 ufunction rv()4 W5 E5 e) k$ }+ l
{8 d! U" K6 T9 T2 P
  var val="";
5 Q) Z8 O/ H' N. o2 F8 V8 n  for(i=0;i<combo_box.list2.length;i++){
. c- V" `3 [8 l* ]( k: z; M) @   val+=","+combo_box.list2.value;% L- ]) o$ V. z. b4 i2 \, i
  }
; E" c' e) M- b  if(val.charat(0)==","){
; b  R" b, K* \/ a   val=val.substr(1,val.length);
- D8 }7 x' \# i% `) S5 p# b  }
  w# N2 G( q3 @  opener.form1.frecname.value=val;
% R+ {/ {! l4 ~% b9 |5 p% V* L" v  self.close();, K2 T* Q& i" {. o" M' `% N
}9 e7 u( a# I; |) o& b8 c
//-->
  e8 T& n' s9 c) B7 l2 l</script>
6 j3 ]* H1 f: k$ h2 W<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">1 K9 k5 ]6 j6 |0 ~8 l
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />* b9 {: _: F9 f2 E4 H
<%
. H" j  z2 f+ t& ~% q! k  cdatasource ds=new cdatasource();  //数据联结bean实例
- M0 U' T: W. p+ o$ a4 n1 y  java.sql.connection conn=ds.getconnection();7 W3 G& Z5 Q5 l, \* w: l
  java.sql.statement stmt=null;
) t# l0 J' c5 D  java.sql.resultset rs=null;
! s; s7 u2 G5 a6 _% y. Y9 `  cdatacheck dc=new cdatacheck();( k1 d& @: X- H1 w" G
%>. X+ Z7 a  ^9 G
<%7 B* `0 y8 A3 {. _( 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";9 H, `! ?" A- X# e
stmt=conn.createstatement();
' ^' w/ \% x1 R& t2 j( m- s$ Xrs=stmt.executequery(sqlu);
0 s! ~/ m/ h! r; k5 o) {%>
- y9 b7 C8 M) B* w+ B  L. n3 j; L<script language='javascript'>8 p- n1 ?0 P8 p6 d
arr = new array();& s1 z, A( q: o# x/ A+ Y
<%  int temp=0;
" x" u/ p; Q# c& e) Uwhile(rs.next())2 J  s, F: h$ `/ W# n6 R
{
8 C( N7 g  ^$ N3 a%>7 u* Z/ S" }1 B6 G/ l' `* q
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");5 `& d: ~! Q8 w4 H7 e" z
<%9 v3 {/ `- n! q5 i
temp = temp + 1;' `- b* n) J+ Q- k
}4 z2 v/ p1 V6 T! T3 j' ~) v
%>
. h$ ]0 u! M, W1 t% Z5 k7 p+ C. Itemp=<%=temp%>;
3 F9 p8 y7 g; c( o0 m9 @9 r& Pfunction changelocation(id){ , n: T" r) v8 E: |+ \4 E3 H' u
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
2 v& r4 F* u2 F, D/ g- i* Evar i = 0;
7 |. U" g: o, s( Z) Jdocument.combo_box.city.options[0]=new option('-------','');
- `% _& m& t$ I+ G- y7 I; }( M$ Efor(i=0;i<temp;i++){ 3 v& f# d0 d; |: l- y6 `5 a
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
% m7 h! n# _6 \: G! B0 hdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
' A/ l8 Q1 H/ l6 U9 y% b} 9 o* e2 G% E1 Q' z# G% w, K% U5 D
}
/ W' E2 z! z# f8 X} " d- g! B# j& N; m; ]
</script>7 L+ J3 j: t) u( h
5 _" R+ j1 P' y6 a1 Y+ p- R
<form name="combo_box">
1 }7 f& j0 e) f<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">" p1 G5 y! A8 ^0 t$ c( Y. |
  <tr height="24">
( G6 k5 Y0 P+ ~* c% I6 l4 R    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
+ w: Z* O4 F  q! W! g% e. h    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>* S  N, a: N( u5 W3 q7 \
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>9 r% s2 H3 W$ q! E
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>+ \+ U/ O& s4 ^" t2 I1 v
  </tr>" a  H" d  @$ v# L) ?$ p0 ?
  <tr>
& w" ^* X$ T4 c. ^" `- W8 E    <td>, x6 F- x8 d& c* N; ^: w
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">3 G+ J" V2 C& v- B! o1 J
  <option value="0">请选择部门 ---></option>
. u# {6 E1 r/ n, T* H<%6 T& W8 B8 F# i# ?( w, m* ?
    string sqld="select * from tdept";
( ~) p3 g: k1 Z* Z& m7 f  D; s  @7 fstmt=conn.createstatement();) S; f- c5 q1 W- f
rs=stmt.executequery(sqld);
- u7 y, b  A+ O2 x2 ywhile(rs.next()). ?; |' O9 L5 u& j- S/ a
{
  a0 q, T: Q1 m$ z* a%>
, [$ l! @# Y7 N$ `. o9 S, P7 ^2 C  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>" X. v* X, D$ _9 `8 B1 Y" d
<%; y/ s7 v" w4 l) V3 L4 M8 ^, c
}
( a' {1 z5 m, x& b, ]%> 7 ^+ t% V1 \4 f. |
  </select>
- s  W- k( q. H6 }</td>/ {5 x# s* j; F+ L. R
    <td>
; q. A7 u6 x7 ]' Q; c  <select multiple id=city style="width:150;height:200" class="bgc">
8 O5 ~- J* z( C6 q/ ]* M7 L$ `  </select>8 o# t- k$ l: g3 P5 F  d
</td>; B5 V- C+ P1 X
    <td nowrap align="center" class="bgc">6 N- U( d  X+ x' i4 @4 P
  <input type="button"  value="<<" class="buttons">
9 S1 Z6 j2 V9 f) R) u- `( H  <input type="button"  value=">>" class="buttons">
$ y" T8 x0 U  Y, m: w</td>
, S5 D, u+ o; Q  u    <td>! a4 q* |" L( U! g
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">( `% c. x* x0 c5 [! ~' @1 {
  </select>
( k* t  d" G4 c/ g2 n2 ]</td>
- b  U5 @4 P) ~: h; H' u! F  </tr>  h) w! B0 E; H7 B7 h! K3 e/ j
    <tr class="bgc">
. W7 v& [& m3 u6 _+ E9 U    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>: J/ O, ?) |6 O! G+ c
  </tr>
, y+ E3 F% s' w9 a% M& }, ~0 B  o</table>8 E) `! k7 o$ }2 f2 Q
</form>. m( j6 B7 D# }. q$ G! t3 x# T
<script language="javascript">6 @0 N) `2 u1 b/ |( l) U) d
//人名移动
7 d2 K9 K" W) Ifunction move(fbox, tbox) {# I* y' @7 I! r: Z
var arrfbox = new array();; m* C$ \2 W. ~1 d" r7 ?0 h' _
var arrtbox = new array();
  T, o. u6 z5 V+ H. ]; S4 V. gvar arrlookup = new array();
$ l1 `+ {3 H- t4 Ovar i;
3 t9 t) ?. K& pfor (i = 0; i < tbox.options.length; i++) {
  T$ X  r; ^( J; Zarrlookup[tbox.options.text] = tbox.options.value;
$ Q4 p+ R; Z+ barrtbox = tbox.options.text;
6 o& ^* t8 K4 M2 G% U2 E6 N0 T}
2 ]( N4 W- L2 t. Y- B, d1 @7 u1 _var flength = 0;' E0 P/ X+ [! K; \: G) a' N
var tlength = arrtbox.length;, i- X( c; _# y$ T
for(i = 0; i < fbox.options.length; i++) {5 _% D  o+ c5 J, i. X% ]
arrlookup[fbox.options.text] = fbox.options.value;
2 Q: @' O: |- M) s- c% H/ qif (fbox.options.selected && fbox.options.value != "") {+ o/ Y7 ~/ Z$ z' ^" k" \# e, i
arrtbox[tlength] = fbox.options.text;
3 w$ M. R: U6 Q; _7 P$ Stlength++;
+ v- ^! O/ _8 y7 o+ y6 Z}& w5 x) V. n: A0 X8 f
else {
2 j* m% T, L6 garrfbox[flength] = fbox.options.text;: ?3 l" w4 c9 U, e$ ^( q) U
flength++;
$ o3 H( h/ R/ |3 {, L  z( E+ g6 q   }
) q. Q! z, {( Z7 _' d! w8 S}; G1 r; {7 y/ b( g8 j; i8 W& N
arrfbox.sort();
: X* G8 N9 c6 X* Z  Sarrtbox.sort();
8 ~5 l+ J1 N8 t& e8 e& r
1 u7 G4 F/ l: Z4 m& Y3 L- f- o* Ofbox.length = 0;" W# C5 |& c+ V( F% j" r
tbox.length = 0;
5 E. n7 g  r  N6 ]var c;
, n: n- l8 O! i$ W1 Ifor(c = 0; c < arrfbox.length; c++) {8 W1 H8 [, [6 }+ ^6 b
var no = new option();
2 G4 b0 V2 \. G% H0 k4 y1 @no.value = arrlookup[arrfbox[c]];
6 j1 J; v  ^" uno.text = arrfbox[c];
7 ]+ R! s" ~* q9 L" f+ Lfbox[c] = no;
6 U4 b' F4 M4 s, z( W}
2 K0 j' ]( q* _5 P0 p& D' j( k# U4 dfor(c = 0; c < arrtbox.length; c++) {: Y1 q/ S% Q' f; y3 k
var no = new option();
! J& ]$ Z# C: u2 `5 X# u* xno.value = arrlookup[arrtbox[c]];
/ |6 r4 E6 g1 d, Q3 B3 [no.text = arrtbox[c];
7 V9 E* q& O: A$ O3 Gtbox[c] = no;
+ K( m9 U6 w% k: t, t   }
% [* G0 t2 ?/ o7 \  U}
" N1 c$ l5 U( d9 S: C</script>% c2 U% i& ]# h0 M5 D( K2 U& x; \" H0 J
</body>
6 R: j  b; M1 J& T& o$ M. s* w

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