返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
) x9 w8 \& S9 z0 |         c pageencoding="gb2312"1 [/ u+ b  X% F7 L8 `' I8 v
%>0 j4 _& q+ X# Y8 z5 r
<style>
5 T; f2 j5 h' Z+ ^.f9{ font-size:9pt; }
3 x9 p) U: w$ N7 M7 `7 ~; e.bgc{ background-color:#aecaf9; color: #0033ff }/ D" d( @3 ]7 W8 [8 T
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
5 m. k# ^! a5 Y2 g* b4 p, C/ w* w4 O* m  border-bottom: solid 1px #4e7dc1;
) N/ ~6 `3 d& j1 W1 b- P  border-left: solid 1px #aecaf9;
6 Q) ?% t9 f( a3 q' v% O  border-right: solid 1px #5679bd;
- J" @" b) V% H  padding:1px;1 z( M' f8 p0 H0 ^- w
  margin:0px;}
7 T1 X. M& J: v$ G0 @</style>7 i. j/ R* L7 u0 z) }6 Y1 i+ w, h
<script language="javascript">
# ~7 B) W$ l$ e( e<!--' @0 {! g1 J& f/ C8 G& D
function rv()3 }! q8 i/ W, C- S" E/ o
{  \; ?# Z. h, [& T1 y0 @& \$ ^
  var val="";
) V5 J+ A) Z9 v0 g  for(i=0;i<combo_box.list2.length;i++){
9 T0 z3 s+ L9 p( H   val+=","+combo_box.list2.value;
$ B1 T. ^% Q8 M( s, g  }; z- {' v& |+ n* d8 K
  if(val.charat(0)==","){
1 }. Y; N& _% D/ ]' O2 |   val=val.substr(1,val.length);
* {! d. f: A; F. h, L# ~8 P  }
1 M2 b: I! S+ P7 {0 ^  opener.form1.frecname.value=val;( d: }* b3 E2 O" a1 |
  self.close();; U- t3 V& N* v' C
}
: T2 N/ V1 T# [. q  \//-->
+ b* ]( q6 _0 W$ z5 R</script>
' n; b2 i, H1 n( B# n3 g. h+ T9 \<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">* S$ G6 q; D7 P2 d, G$ r) g
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />7 f+ w# \; y. S% k5 _9 H  y% R
<%& Z9 s; T: C, V+ A
  cdatasource ds=new cdatasource();  //数据联结bean实例
2 X" z, ~& Z  K9 J+ U  java.sql.connection conn=ds.getconnection();
: y5 N" e. o- a  java.sql.statement stmt=null;, g( M1 I# t; i$ u8 o
  java.sql.resultset rs=null;1 T4 n0 }  s. C' u8 O6 P3 e+ [
  cdatacheck dc=new cdatacheck();6 G6 c5 v, x1 `0 K
%>
7 Y. o5 v- g5 g3 v; v<%
- E+ p  i/ L7 S3 E5 jstring 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";* o6 z5 W, b0 s4 F
stmt=conn.createstatement();
4 |- e4 H* l. Z; xrs=stmt.executequery(sqlu);9 g7 }( G; z. R7 {. L
%>* {, J! G  s0 M5 o) ?
<script language='javascript'>7 E2 ]0 x; a$ [* P
arr = new array();
6 C, e4 p) j% n( j, \4 [<%  int temp=0;9 i9 l; Z0 {, J2 ?  _8 U' w
while(rs.next())
& v2 j* Q8 K" G* p$ Y+ A1 i{
: k0 X  s1 z: B%>
% k0 q, G: }( S1 L2 _6 Rarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");: T3 [2 D! r$ a
<%
/ Z7 w3 c7 W+ U5 vtemp = temp + 1;* i" `, R5 y) E3 L
}
  i0 T: `' X* o%>
3 h1 |* Z' h4 O1 ]. Ntemp=<%=temp%>;3 g7 }: U/ F2 A# C
function changelocation(id){ ( v( M& v, U* N
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
9 Z' a' A( W: [1 [  uvar i = 0; ) e# b( q2 G( H3 H$ C; P7 p7 z/ ~
document.combo_box.city.options[0]=new option('-------',''); 5 D% v! J- c& b( L1 Z' ?1 e0 s  ]$ ]
for(i=0;i<temp;i++){
$ A6 B7 _% v/ ]+ Fif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] " D& S: }( B7 R7 `6 W( q
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
2 v9 o, A0 R+ D; v2 ?& I- Y}
& r% @5 F  l! x, F+ l+ \$ ~* s} 8 x/ y) ~" N; |5 _1 B8 d0 }5 B" Y
} 5 ]" H, Q3 \' b5 x: F3 [
</script>
6 b$ v: C# p+ `: y8 W
% E: Q9 i. o5 E2 \) T! |+ O<form name="combo_box">
; ?# g% ?/ Q$ d9 j) q6 U4 w<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
( Y& X$ X8 ?" Y6 g, p  <tr height="24">2 p1 P: _! L+ C
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
  w# f/ U0 w5 V1 k9 _) V    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
; R2 o0 O$ P/ b5 g  B    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
4 t. x8 b) \4 I* H5 l2 d    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>5 E7 P7 a4 Q& E- G
  </tr>  r, ?7 ?  ?9 I! c
  <tr> * Q( F3 W3 n6 R) n; M! I
    <td>' G+ ?7 L6 o# e
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">: e: F9 A9 e" \" x! v( b9 R
  <option value="0">请选择部门 ---></option>
* X' x& L. ^8 W' x<%; R: k; c2 \3 m5 O+ J/ }
    string sqld="select * from tdept";4 S; v1 e7 T+ F) r" ^
stmt=conn.createstatement();
8 w/ _* B. I5 j* i/ Trs=stmt.executequery(sqld);
5 @5 j, S  q+ j- m$ I& Wwhile(rs.next())% }3 C! B* \7 e+ f  x, \
{
: \: a" f( U6 {, r* H' v  P7 u%>
) K% Z3 H7 c4 t: M3 X  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option># Y6 C4 T+ Z0 ]8 |  N8 v( O
<%4 E  R' S& a% l4 k& S* p4 L. ~
}" w; x4 ]" W- D$ v* l
%> 4 R" c9 L/ h+ H* t9 b4 P
  </select>
$ W# m$ \3 _, q+ m</td>9 t% P/ [$ w2 X, t- ]
    <td>) {- l: ?8 `; v1 h& E
  <select multiple id=city style="width:150;height:200" class="bgc">: Y4 [+ M: V$ i% K7 Q
  </select>! J$ t& |  H( p, S, G
</td>
9 L' M$ g+ B5 N, C" J    <td nowrap align="center" class="bgc">- ^# B) Z/ \5 W$ V7 b
  <input type="button"  value="<<" class="buttons">
1 V4 R1 p' _- @) A- t1 n  <input type="button"  value=">>" class="buttons">9 o. }2 v2 \' n0 H9 L# @/ V0 R) |
</td>) z1 ]6 _$ Y* u; d1 C; y) q
    <td>: N* `8 i- F) L$ _$ T+ N+ }9 ^
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
. Q' H3 c" z! a# ^  </select>
/ I. t8 b8 [' P9 ~* h</td>
4 n5 D( z9 s# |: C& {4 [7 E  </tr>
# W+ A6 m; G& J! L( O3 X    <tr class="bgc">
* V0 n+ x5 N- W1 l. e  b( B    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>3 {# K4 v+ e8 W1 O+ Z3 [5 A7 N
  </tr>
. L4 j7 ^8 p! t4 I; C1 g: m* D+ `</table>
8 j6 `# X5 G% J( H1 ]1 i</form>
% I- r: r' f9 C$ n; B% L<script language="javascript">" Z' `# c6 g1 t. j5 r  {& ^7 ~
//人名移动, k9 u8 ^4 \) l* j7 h1 v6 R' G, }7 c* o
function move(fbox, tbox) {1 o" y2 y9 V! H" @4 b( [  o6 t
var arrfbox = new array();4 P+ E, W4 o- P- @7 i: R
var arrtbox = new array();1 v7 g1 v( F. d* z4 R3 A* K
var arrlookup = new array();
7 w) h" B. I1 @7 C6 Jvar i;
; i- r' m6 O5 Zfor (i = 0; i < tbox.options.length; i++) {
  \: Z% O, i: ~8 X. j* H' uarrlookup[tbox.options.text] = tbox.options.value;) y$ Y6 t) p. h
arrtbox = tbox.options.text;  v% t/ N4 X! p1 r: J, u
}
+ Y( o: G7 I. d- @1 W: l1 Avar flength = 0;
% ^. d- x* B; J! H' r# Zvar tlength = arrtbox.length;9 x- y: G( e/ C0 U  J) z! X
for(i = 0; i < fbox.options.length; i++) {
3 u5 n" t" R- U" l# q7 T/ l. Zarrlookup[fbox.options.text] = fbox.options.value;
& I- r# J0 v: l( }# O8 c' M7 Dif (fbox.options.selected && fbox.options.value != "") {# |* e9 P1 w  v4 o* b
arrtbox[tlength] = fbox.options.text;6 F- s, e" X1 c
tlength++;# ~& R1 N4 M5 u
}' l- X* d# T, G
else {3 }$ o8 Y9 L0 h* X! ~4 x4 {
arrfbox[flength] = fbox.options.text;
, z" W! N8 J) s/ E' a/ B1 \flength++;
; u8 ?# M% j3 O$ r% N+ p   }8 c  h1 p3 H, f. D  ]4 X0 J/ X  _% l
}( J/ a6 p- s. B6 V" |, X
arrfbox.sort();
( x- C( w! K; g+ |1 Narrtbox.sort();. E8 W% T! ^9 ]4 q; w

9 ~5 t: d3 Z+ r& f  `fbox.length = 0;' i* `  b1 x) u3 a
tbox.length = 0;
9 ^, L% S& q+ k! O0 q/ H# \: Uvar c;) x8 t& G6 `9 S6 Y! S! k: P
for(c = 0; c < arrfbox.length; c++) {
. S  U6 k/ S0 N8 x8 Svar no = new option();1 \# `4 z% K1 j5 `4 ]7 u$ v
no.value = arrlookup[arrfbox[c]];, r% F0 O7 k+ E7 S
no.text = arrfbox[c];- o# r* |# }6 V1 {6 ~4 W
fbox[c] = no;# m4 ?# U% E% z7 c$ c
}
  R4 }: T3 n' zfor(c = 0; c < arrtbox.length; c++) {
4 ?; B: M+ p# G+ jvar no = new option();
: y! m$ ?# b" I4 Xno.value = arrlookup[arrtbox[c]];
0 w; T! p' s- Z; X7 pno.text = arrtbox[c];1 Y" m& u& V$ C8 x
tbox[c] = no;
' V0 w  d. t/ Q/ K/ y$ |+ U   }
' \7 L4 Q( R8 k4 r3 M}
, p  Z3 I$ {; \# T& O& V" a</script>
6 R, A/ P2 c' t# ?# {# ~& i</body>
  G$ K" j+ ^3 T! A1 r

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