返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
- J! Q; u# r; Y         c pageencoding="gb2312"$ q& c) t" a5 _: _, F9 s5 g
%>& p2 @  I/ k& y. d/ x
<style>
* {+ A4 d9 x' |; w7 ].f9{ font-size:9pt; }
0 Z7 }1 K$ u4 T  @  g.bgc{ background-color:#aecaf9; color: #0033ff }
6 x5 @, h" d2 j& ]( r& Y.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
$ m5 I! j+ ?8 R  border-bottom: solid 1px #4e7dc1;
- s5 S: O' A2 T! f6 _  border-left: solid 1px #aecaf9;5 r: m! i4 B. r+ I' e" ]
  border-right: solid 1px #5679bd;4 u/ ^( u, k: D) j4 h6 N( a
  padding:1px;
" Z" M) T  F& @3 \  l1 d  margin:0px;}
* {  S8 Y# T4 |</style>
. M* @* O* o5 ]! j8 Q, X<script language="javascript">; E! G; u2 ^! B  J
<!--
# s2 v8 ]! ~, a% t: Hfunction rv()
% z' u) W/ v7 v) u{
  |2 u* Y1 c' u  var val="";
9 m8 r+ M5 n/ ?, g, M8 u  for(i=0;i<combo_box.list2.length;i++){
( F) k) L2 d& `) _   val+=","+combo_box.list2.value;0 g4 ]$ H9 c* z" J. k
  }
6 S' Y) M3 ~, j5 t+ J  if(val.charat(0)==","){
; W  d! w' l5 f$ L& i/ Q   val=val.substr(1,val.length);9 d8 v: u, g( K. x' H  V+ a
  }5 T! K% E% c3 N% [
  opener.form1.frecname.value=val;3 Y7 Q, R$ b5 j& H
  self.close();  l) B5 g6 g% `2 l/ S
}
: }+ C* ^3 a1 t8 j3 s7 ?//-->
; E# D6 T* k: ~</script>; x- D3 Y" B- d& G
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">6 R% H+ w! s$ f  q
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />; j. O. N+ K, A5 \9 K5 s
<%
& o! l; e  R! Y' b& x  cdatasource ds=new cdatasource();  //数据联结bean实例
! o  T# L" w# ^3 g( K! D% p9 S  java.sql.connection conn=ds.getconnection();
1 b" D) b$ C6 u, T4 T  java.sql.statement stmt=null;1 K4 y* W& w0 l  M; ?6 e3 n
  java.sql.resultset rs=null;% v& _& E; h! ]- w  X
  cdatacheck dc=new cdatacheck();
! M, b! a7 V8 I$ z! p%>
4 h$ E0 ~# q" Y. R/ x<%
: v+ F" o8 A: p* f0 W  D3 Mstring 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";
$ R4 g; Y; D6 h* ^$ sstmt=conn.createstatement();
: X  \* C' W9 S' frs=stmt.executequery(sqlu);, ~8 h9 y1 N& ]; X9 q5 a: d
%>
5 P, h; [) E- u$ s8 _8 J<script language='javascript'>9 m9 z* Z/ W7 N$ A7 @( z. r
arr = new array();+ d3 m" N' @7 \
<%  int temp=0;
( C9 C; b+ M& P/ [9 x+ v# Y2 G0 \while(rs.next())
% {5 y! C' Y, ~3 E' M{2 n+ M( s5 C5 ~% h- J
%>6 Y! K! z) Y! Y  v# c7 ~! ~
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
9 R$ `; N# y; f7 K1 Y" K4 k<%4 R- y  J  s" W( b7 U8 Y6 b0 |- I& z! T2 z
temp = temp + 1;5 h* P- e# V1 D9 p0 ~
}0 X  H( S0 t+ H
%>, \# j$ G/ Q9 T- `
temp=<%=temp%>;
$ P( x% f7 S2 m; P( k9 |" t( ofunction changelocation(id){ 0 V1 E/ u7 f2 ?
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 2 ]$ W- S, a" E" p. W6 G5 e
var i = 0;
- }) `) }# W* `+ M+ `4 Pdocument.combo_box.city.options[0]=new option('-------','');
8 y  J3 Q9 N; F6 a& Tfor(i=0;i<temp;i++){
1 y- t- t( e5 Z& Z2 T& l; Q$ i: mif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] ; N, W3 j# |+ @* m- g4 K/ M
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 3 ^/ K$ w+ g/ }
} . @1 Q% q9 D% \
} , l' i% A! w/ y5 q
} : F: S; g1 W* t8 h; `
</script>
* a% n$ X7 D9 C' ]" f
6 m, p! @. e! L* N& q% ^0 H, Y! ?<form name="combo_box">
+ X# |3 L% E# {9 f4 |7 S1 w# K. s<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">) O( ^7 `# l0 @* c) N# O+ ~
  <tr height="24">
$ H! Q+ T& _, S7 q+ D    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>5 t' p: `& t; u& U$ O! w0 m
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
, g/ a- D+ J5 f$ w0 Y    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>- M$ g' G# a  q+ L& o
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td># U  O5 l6 z6 A% B- t2 J
  </tr>' `5 X, l; }$ U& j! C
  <tr>
' K* @2 _( X. c8 q$ Y    <td>1 n- C! L4 A: C: t
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
* M  X1 Q: a* g% K& H. d# |& k1 [  <option value="0">请选择部门 ---></option>. P$ B5 U: w: X1 }) M7 T6 s
<%. H$ t+ @5 N& ^% P, V
    string sqld="select * from tdept";
3 G, D  |: s- ]% P" j1 s2 p% lstmt=conn.createstatement();
  ?/ e0 v# u$ ?. a, Yrs=stmt.executequery(sqld);
6 u, w, A2 Y7 Iwhile(rs.next())
/ z+ g/ Q; Z. n2 n: W{- v. [$ Z1 I6 F& x
%>2 d; {3 `; o$ ]+ o7 Z' K
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
; y. l+ T; Z6 y+ N" Q, G<%5 Z, }. D" O. b/ w+ y$ X  |
}
# L& Z1 I7 e7 {! }# D! N%>
: w! B7 q2 i7 c0 W: r6 Y2 `- h! V  </select>
$ H: F2 H: C, x' B' `5 [</td>
5 I9 M  `% i7 j* ]$ v    <td>
: N1 E+ N+ ]3 n8 L8 H  <select multiple id=city style="width:150;height:200" class="bgc">
: _% X  E& ]4 \6 {. I! {9 X  </select>
1 B- ]9 Y; m+ D3 M, }  l4 j- ]</td>3 }; v+ U' v; ^! e  g2 s+ a- u
    <td nowrap align="center" class="bgc"># [, T" O' z* }
  <input type="button"  value="<<" class="buttons">" Q" t) L* W" G* o% `
  <input type="button"  value=">>" class="buttons">6 F7 S* x" X# B/ @% x
</td>+ V( i+ y; T/ u3 C) _; G5 [, b
    <td>
% t; y! z- B) E& l' Y  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">3 p1 I/ z% w! Q* A
  </select>
9 n( ?. u# T' N9 V0 y! h9 t</td>
3 o5 u  l. w, L5 Q& W2 ^( t  </tr>
4 t+ E# d8 X1 E4 y4 \; ^2 J+ k% S. Q5 j    <tr class="bgc"> 7 ^( w( Y6 i; z4 G  D" O
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
' M1 p5 l8 m9 [+ L4 d9 V  </tr>
0 v) X5 I$ Q. T# P4 S</table>
9 c. f- R- J) N</form>
, X# |  a6 c% f<script language="javascript">- T+ A2 v$ [9 {( o0 q5 |
//人名移动
# H2 n) m, a0 r1 r' ~function move(fbox, tbox) {
' m/ v: B, D! E* j# H4 ^+ S1 J6 z6 Tvar arrfbox = new array();- p9 j/ f& ~3 i* H9 ~8 b
var arrtbox = new array();
0 p+ [% m* N! `- u, ^var arrlookup = new array();7 |1 o+ y2 A  P
var i;
3 G8 [6 s9 r# N1 o8 K/ Jfor (i = 0; i < tbox.options.length; i++) {+ b( k( C2 {; z5 i
arrlookup[tbox.options.text] = tbox.options.value;: V2 @; I  a% a% x
arrtbox = tbox.options.text;" z& ^6 `: Z3 i  c( I* ?0 B
}# `2 V# B2 ?7 G! g7 F& A. p
var flength = 0;
4 K6 Y8 ~  a2 G- ovar tlength = arrtbox.length;& o( q' W: _) w% D0 R& O+ @- c
for(i = 0; i < fbox.options.length; i++) {9 Z) y4 y- H: a& I9 m" W* a
arrlookup[fbox.options.text] = fbox.options.value;( ~) D' Z  R% Z( T
if (fbox.options.selected && fbox.options.value != "") {
& E- `7 q* l) p! u7 Oarrtbox[tlength] = fbox.options.text;
7 V, O/ r/ b9 Qtlength++;
$ u& ~" |$ Q" ?* w& t. u$ ~  K}  w: O& S9 _. T9 M
else {6 P8 P7 i+ h/ h& ]
arrfbox[flength] = fbox.options.text;& s8 X; S! j! y8 C, x- g3 Y
flength++;
9 j, r' p$ U2 o& j6 ^2 u   }' f) ?- @! M8 `/ C, A
}
- k5 u+ D9 y3 n2 w5 ]3 farrfbox.sort();- e" M7 N1 Q4 C4 o9 ?
arrtbox.sort();+ H) ]: f" N# ^* _7 c; t+ m

/ y0 x4 N( J  g- sfbox.length = 0;8 A: U: m* Q: c- i: V5 T4 _1 k+ O
tbox.length = 0;
8 i9 j( f! _0 B* s2 ^var c;
* h* |5 P) b7 S- x& ]: w! v  Dfor(c = 0; c < arrfbox.length; c++) {! I7 G$ H) x6 l3 V
var no = new option();
& {4 R1 N7 |. H; Q" G3 u4 y* Eno.value = arrlookup[arrfbox[c]];
8 o( Y+ [( U. p3 g0 `no.text = arrfbox[c];
9 G' ]* M! \0 Sfbox[c] = no;, b6 p: q" N5 V6 G+ z/ E0 g% K" }
}3 X" r( n( y$ u5 G& G3 K
for(c = 0; c < arrtbox.length; c++) {
% M% f0 ~( L' d" j. evar no = new option();
" b, `5 U9 [6 c2 Z! E1 ^7 z8 xno.value = arrlookup[arrtbox[c]];
0 p5 F0 d" u; p: Lno.text = arrtbox[c];7 D1 F# L7 c1 d, T& L
tbox[c] = no;
+ t% I! m! v2 [' T. A   }9 ?4 M' C7 Q( R' r4 C- t# v- w
}
* k) D5 e5 J# m</script>( k! n% G# d+ w) L7 \% b% B
</body>5 L' b/ A+ d$ w. j; J) @

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