获得本站免费赞助空间请点这里
返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
+ v" U: c8 y! H         c pageencoding="gb2312"
5 X+ B+ f! A) r! q9 V%>
( F! H+ z. Y+ U8 H<style>5 j4 N5 ^! M2 }0 o3 y/ W$ E1 N
.f9{ font-size:9pt; }
# G1 ]& {) K/ W* T.bgc{ background-color:#aecaf9; color: #0033ff }" u8 s; d& a6 h$ @0 K# H! J/ B& y4 F
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
" T' t' z, e. {$ T  border-bottom: solid 1px #4e7dc1;
: j8 g- R6 f5 |! N  border-left: solid 1px #aecaf9;
- c9 C5 J' l5 ^( ]  border-right: solid 1px #5679bd;) G2 {0 j! E6 V) [, |
  padding:1px;5 ^" ~% }/ x$ t+ P( I$ f+ r. I
  margin:0px;}
/ `5 \5 `/ k4 r& t9 B6 A</style>, ]3 `2 v. J; k  K# L0 l
<script language="javascript">9 ?, H. V8 H9 T# h- u9 ?+ s9 S
<!--
4 w8 H% K: @- @* K) z8 n* j: F% ufunction rv()
$ k8 T6 [+ Q* y4 u# x4 b3 J{
1 O( v- s6 [' M, Y7 U( |) C/ O: ~  var val="";
$ ~0 m3 g( {( y1 X/ }  for(i=0;i<combo_box.list2.length;i++){
" ?0 t9 J# X& K8 H   val+=","+combo_box.list2.value;' ?0 u- D6 j- V) v, w  G
  }% I+ _! q# |1 x/ ?: t' Y( g
  if(val.charat(0)==","){( T5 J. B, t3 z4 ^. o
   val=val.substr(1,val.length);  D9 `# A' f- L3 H8 K' p
  }
9 S* c+ a( v7 K7 Y2 i2 [  opener.form1.frecname.value=val;
# f, o2 X( ~! Z5 }6 P; G7 {  self.close();
7 `' \# {7 {$ |}' ?# A6 ^5 [' N7 l5 ^
//-->
& ^+ Z2 n! @3 ?# v  F- N</script>
6 R1 D% e' f' Q+ E/ r! U4 z  }<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
4 q6 n% E  f: Z1 C4 W4 U/ |% {8 w<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
9 R/ q" |; y  o2 W2 |2 T; z0 ]<%7 L9 I0 t5 [. u7 o+ U4 @& `+ }
  cdatasource ds=new cdatasource();  //数据联结bean实例. d" b$ A1 s# v/ ?- o5 d7 F
  java.sql.connection conn=ds.getconnection();+ d; z5 e- K! W- N1 K& z. X( g8 ?
  java.sql.statement stmt=null;
; G- Y- e9 I* R* [8 ~5 W/ i  java.sql.resultset rs=null;
/ |+ ]* x. a' u- c$ M  cdatacheck dc=new cdatacheck();
% g, ?$ n$ K" |+ v" e, `%>
, M* i+ d' P& _) y  t<%% p& ]+ @0 Q! r1 }2 K$ z
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";- W3 }; a- C( B' u# j
stmt=conn.createstatement();
* q7 G$ b3 a# Prs=stmt.executequery(sqlu);
/ T5 ^/ l( @: B. N4 y( ?+ m# T%>0 R- q5 g/ a* N2 w
<script language='javascript'>
, b; \( J0 Q* |: ]! {3 X$ M: Yarr = new array();
! \, W% J* ?" ~& M<%  int temp=0;( u* U+ h; f! h) T
while(rs.next())% C" L! n" Q0 H' r
{: I7 b7 h7 Y3 i4 W) ?
%>
& e  R: L) X! {9 s3 earr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
1 Z0 W% N/ T- B<%
- b; L3 R; G# Z( C" Y$ d( Jtemp = temp + 1;
9 e3 X% z" X6 L3 }- ^7 a}0 f3 }) y. u8 a
%>+ x3 O" x9 T! T& p; B6 L  S
temp=<%=temp%>;
' d% O4 z& n: Lfunction changelocation(id){
( b( n3 S$ K' A! E# ]7 s- h# L: ldocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 & ~4 ]3 x$ B+ r) H
var i = 0; # J- M0 }# o) e9 C) \4 s
document.combo_box.city.options[0]=new option('-------','');
( b& f. a# B0 v9 ^for(i=0;i<temp;i++){
5 E  T4 {) ~: _  O! Q) V3 u7 jif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
: S1 F0 e0 I9 s0 [8 ]4 K- Pdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 5 X2 k3 s( j7 H% T: i: A
}
) X# @! J+ M! E# }3 A0 q6 W" {7 n}
- }5 z- y8 Q$ n) M}   o& |9 h5 L6 X) T- z8 w
</script>0 P; _( U: ]' A( B

  W" ], {7 p  K0 g; B+ ?<form name="combo_box">6 a' K+ R, l! P+ o4 ^
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
+ ~* }( S, H* Z9 M  <tr height="24">
$ L5 `. z. d; p, b' J    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>' V; m1 i, @; `# P. k2 z
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>5 m5 _% h3 e4 l0 h' S+ ^5 Z
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
8 d- [6 u0 Z$ `8 {! i" b    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>/ L2 d1 `) e. \  }- w4 ?
  </tr>* J2 A: A( r, d6 T& a
  <tr>
) @* N$ Q$ J- ~    <td>; b6 D4 @( y2 c7 x$ y
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
$ n( _, j* e( _. {) m2 F  <option value="0">请选择部门 ---></option>1 H) |4 j; V) z
<%
3 ]% b% ^$ e2 b" Z! `    string sqld="select * from tdept";
4 V% C. E0 D' G. r+ W5 b; p$ A2 [stmt=conn.createstatement();
. T6 u; Y. M# G# W, Frs=stmt.executequery(sqld);; y3 S0 z$ r( x! o
while(rs.next())7 {+ j) ^" t5 I& H  N
{+ Y$ |; [1 ~$ [8 ~, \
%>
* g% B, M- p3 ]7 v  w+ a  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
2 W: B! k+ p8 Y) J3 i6 e* q/ P<%
4 x5 L4 @* Y. e: Z}
; O) I5 T  |* P; ^%> 7 P6 _5 M8 D" b1 `" B
  </select>
% N& U3 `$ V6 ]2 J) F</td>
( t. ?2 b* N% p+ @    <td>
* K- A: N; k* W  }- }# C  <select multiple id=city style="width:150;height:200" class="bgc">& n& g# p- E- o; |% A
  </select>2 ?% t" b( O1 g+ f9 B
</td>: u+ Z  j( c5 H( I% l; b
    <td nowrap align="center" class="bgc">: ^* L9 }8 _5 U8 C' N3 r, I
  <input type="button"  value="<<" class="buttons">, }) m3 \- {0 E6 W
  <input type="button"  value=">>" class="buttons">
, I3 i$ }+ u( m' Y# g( v</td>* q& ?3 V7 s: L# ~- s
    <td>
$ G# O4 q' j- f' F' @  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
" L' N3 x* \- A  </select>( l* h- f: l9 v/ m( X) {
</td>% w# a9 w. \: }$ x0 H) H+ d, `
  </tr>
7 k6 a) B" q- ~  W    <tr class="bgc">
' m: M% O3 }7 P; ]* e( Q- _0 g0 f( r& H    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
& U% _4 L/ u8 E% j! f6 `  </tr>
7 M% |9 q/ o- M' V1 u, p/ z</table>
7 l2 w2 b+ }4 T5 w' }</form>$ E, g/ d6 [4 ?- c
<script language="javascript">' a% ~: }3 B& f( F$ ]# w% s
//人名移动
- T! `5 x" y' G0 Ufunction move(fbox, tbox) {
  P4 _# I; D; v# d: d& `5 bvar arrfbox = new array();% {: f/ y9 f' a* d6 f) W
var arrtbox = new array();
" a! @- |% }4 x# ?# F9 hvar arrlookup = new array();
- a7 m' F! I% b5 R7 m- rvar i;# O( J- I' [8 u8 j# T# R2 l
for (i = 0; i < tbox.options.length; i++) {+ E! ~* w; w3 N/ I3 H: a' i" t) o
arrlookup[tbox.options.text] = tbox.options.value;) c4 L/ @* c; m! p0 Q- [) l
arrtbox = tbox.options.text;) s" l  R7 f& G3 G" C. |
}
9 o0 K$ B1 R5 L2 ^& kvar flength = 0;
3 x; e7 X2 y+ Gvar tlength = arrtbox.length;& R8 z( W. U  u' V
for(i = 0; i < fbox.options.length; i++) {8 L. `. @6 s! x- j
arrlookup[fbox.options.text] = fbox.options.value;
) z1 Z% y+ n& _; C9 Cif (fbox.options.selected && fbox.options.value != "") {" g1 u$ o/ h1 U3 P/ c3 W
arrtbox[tlength] = fbox.options.text;6 `/ O" d& Y, s/ `7 j5 ^* f
tlength++;6 e2 v/ U  ]# g3 j- n0 ~* Q4 W
}
% I1 g. M  d7 d; ]. c  Ielse {
3 i( D5 A% u2 Larrfbox[flength] = fbox.options.text;
( s/ E# g  y# z8 f' Yflength++;
: q/ B' J; [! m   }
: X. e' H4 F. n) b}# v  f) Y5 h( \, c4 A6 `. ~
arrfbox.sort();5 ]' O9 `, S" q; L4 @, |. ~& W
arrtbox.sort();
# G1 h  J# A  x- h9 ]( k# j# y  x1 K; E! Y* T9 c3 o) m5 b3 `
fbox.length = 0;. F& g( ~& y5 f% @; R  d( y, t
tbox.length = 0;1 b2 P$ s8 D  D
var c;. w6 _5 y8 e, U: G) c$ y) `! x
for(c = 0; c < arrfbox.length; c++) {
( L- D9 g: {+ w# I# N/ ^+ Mvar no = new option();
6 n( k& k* r% Q% Jno.value = arrlookup[arrfbox[c]];
5 h7 \7 b1 W% z; W" kno.text = arrfbox[c];* j. L; o( i: a; @! f' o
fbox[c] = no;
( i; u1 V4 o+ d% N5 r. x" D% Z2 K8 b}
4 ]9 M7 [2 u( z9 [1 r2 H- Cfor(c = 0; c < arrtbox.length; c++) {( e+ L5 g  U6 h  k
var no = new option();- j3 A" i/ u6 q2 T3 U% }6 G6 |
no.value = arrlookup[arrtbox[c]];) b) ]! f! S, B! |; n
no.text = arrtbox[c];
. \1 E/ `$ O& }: [  jtbox[c] = no;
' @# o+ m9 y# J2 p/ T; \: i) x   }, J& Q( z" G* _. }" ]% n1 E
}
" d" n7 n1 P% F# B. Q& d</script>$ L2 a  Y, Z8 p- [4 P. C
</body>- w4 \5 ^$ ^8 g6 g: U. b: s  j" \

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