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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
- `' V% z/ k/ e6 ^" Q8 S+ H  }' `* T         c pageencoding="gb2312"' A& V& l/ S: Q  Q# }) ~+ w
%>, |0 k& {; N1 Z: r
<style>. F+ b- h# ]* _( y2 E* q3 W
.f9{ font-size:9pt; }
1 H! C: y* h% @.bgc{ background-color:#aecaf9; color: #0033ff }4 T# V* b- d+ x: N* k9 L/ o) r0 U
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
0 d  y# H/ B4 x  border-bottom: solid 1px #4e7dc1;
; r) J9 E! n# P1 `. s% F0 Q8 H( U  border-left: solid 1px #aecaf9;
/ b$ U  Q6 {- s  border-right: solid 1px #5679bd;0 v# M( @: F5 ~6 x% m
  padding:1px;
  s  G8 |- o3 ]  `* e  margin:0px;}
% @& z- n' b" b! Q. v</style>
0 q6 P  `8 z6 d* i/ G3 N<script language="javascript">; P- `0 D6 j) r# r: O% I0 Q
<!--: U6 ?8 s/ Y6 ~3 N6 c$ a
function rv()* @8 V, R  t2 ]# P6 W: w. u! b$ c
{
9 s, |1 d, G3 e) A0 R4 B3 D  var val="";
  j. X) x' Z9 X, L! r$ R2 [, f0 l  for(i=0;i<combo_box.list2.length;i++){# {5 @, w+ A' A; [. p: A2 L( f( Q
   val+=","+combo_box.list2.value;! n+ f2 d- A. e3 T& M& Z2 p
  }6 j- v- ^9 }; [* m! A
  if(val.charat(0)==","){/ T0 n, h) Z/ j- i1 E% I! E- D
   val=val.substr(1,val.length);2 n1 w5 p* ~5 T
  }
% p, ~' \( ]. X) K5 V* X) @  opener.form1.frecname.value=val;4 C* G0 q" f2 u, p0 c$ _
  self.close();* d' |4 i7 {% ^  G
}
/ M+ @) x' P4 [7 ]//-->
% s  f9 ^# n) k2 u0 [+ O, m</script>" V3 _/ K3 I: ~. ?, [- A1 Q
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
1 p5 F7 M4 M1 N% U7 k( o<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />3 F% M: M* ~3 N: i, F/ [( f
<%2 K3 `7 J% X! L
  cdatasource ds=new cdatasource();  //数据联结bean实例8 g" t& M; |# a4 [, L9 O6 Q# n6 N
  java.sql.connection conn=ds.getconnection();9 L/ V. n! K) p2 A
  java.sql.statement stmt=null;  b# }# o0 \, \6 t3 ]! v! g
  java.sql.resultset rs=null;* M5 c0 N" q0 u+ ?; l! C6 q
  cdatacheck dc=new cdatacheck();7 z5 @+ E/ e( F. @
%>
" d* S! c5 I# W% f: ~' U4 g<%
& V" ^; Z5 D% T9 ?! L) rstring 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";
% M( Z) W. i; z; ?" Qstmt=conn.createstatement();( z2 R& O5 e. Q; o, s& l5 G
rs=stmt.executequery(sqlu);
5 M' O9 E( S1 R' n9 V%>
9 W5 U9 H( N; ^! A! ]9 V+ g, `<script language='javascript'>9 A1 u3 M0 }+ x- Y1 Y0 ~
arr = new array();; k0 P; Y4 g( p( B1 k
<%  int temp=0;
: k: v+ B) Q6 pwhile(rs.next())
2 \' I+ y0 A5 l( c) W{
0 e" B4 V; j, s" {; p%>' q! |0 W. w, W+ @
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");" S' o! O5 C0 r$ C. J0 ]8 ^0 a
<%
4 v! c8 [$ H% \temp = temp + 1;
* K) i- _$ U1 q7 Q( S" n2 G" e}; j1 _/ ]: `% i
%>
3 G4 @, I! `+ ^temp=<%=temp%>;
9 s* A, l& C- X: S/ W. U! e1 ofunction changelocation(id){ ! |; E4 s: l+ r( E3 B* [
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
3 g: r" i9 A7 R" K2 ~& p- Dvar i = 0;
0 P* k) k1 G( e7 ^. M% [1 `: Ndocument.combo_box.city.options[0]=new option('-------',''); ; x3 F/ n, d: D" J7 e
for(i=0;i<temp;i++){
( C9 l1 B7 d- C& u' a5 C# Pif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
3 m  O) a+ Q6 Wdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
6 Z9 |& l* F+ K/ x- v2 x}
. m" V; j; v# i}
! Y" ~5 \+ _8 a4 M& \# G% F}
( O6 z6 b1 h- C2 X</script>
' p, \# h8 S0 L) t; z- i6 @7 P9 a
! C/ S% `$ p( }! C  Q<form name="combo_box">1 y0 [& u0 r% H0 Z) @
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">- S( B) n3 g5 }% W, d
  <tr height="24">
% ^, b6 X1 w4 Y" ~    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
1 l0 }$ w9 V. k# S- [# W) u    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
* L$ p1 y/ O$ U, M' e, D; b/ _    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
( }$ \) J9 C2 n3 S( w: ~$ D: T% `    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>% N4 J* ~2 C3 y3 T
  </tr>% f. V3 ~# ^& o5 S9 j2 q
  <tr>
$ A% t0 D3 z  I7 g# ]1 V6 |3 o6 K    <td>, O8 `0 D8 J' J4 s" J, f5 O6 V- i
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">! |* _% u$ w3 h8 @7 U
  <option value="0">请选择部门 ---></option>4 u5 A2 S/ L! a0 [
<%5 A, v0 l: n+ y
    string sqld="select * from tdept";; D2 u. H; D2 s. R) A$ J7 w7 l
stmt=conn.createstatement();
" ^- M2 m4 s" M7 @rs=stmt.executequery(sqld);
) D8 w. b0 H& _) u, e2 gwhile(rs.next())
2 b" b, z0 A+ E# b! y8 C{
6 f. E, c) p1 {; P2 D%>0 ~  ?& i, f! s6 L( Z8 U3 }
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
1 @' a8 \2 t1 R! X<%+ c, q0 g8 Y1 m1 X7 ?& u
}
( H" b" f4 s3 K, [%> 2 ]2 N% n4 x7 Z, q9 P4 ?8 V8 t
  </select>
6 H' u5 S0 m/ Z0 q" T</td>% w( A5 N! d1 d- z  g
    <td>
; ]$ C% }/ T5 w3 C- h4 e  <select multiple id=city style="width:150;height:200" class="bgc">
0 r0 }  i6 B; u6 f3 Y" U  </select>5 K9 I0 q' ~0 M
</td>7 P- Q& o+ a9 z9 `3 f9 K$ v
    <td nowrap align="center" class="bgc">4 P( e" `6 v" O7 x: h8 J0 Z
  <input type="button"  value="<<" class="buttons">
3 `' a6 l* G6 ^" G# x% }9 [" v5 I  <input type="button"  value=">>" class="buttons">( |0 y' X1 M  u1 F* z2 Y4 k
</td>
) y6 g* m+ D7 k1 [. w) Z    <td>
* s+ Y; s6 M0 t9 ^6 e  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">2 x9 k6 C" I! M+ W5 N0 P. _3 k
  </select>
# W2 l. a  `+ A2 j</td>
; g% [5 p7 Z8 z  </tr>* t# I. y' j) d  o
    <tr class="bgc">
) K: x6 L% f1 `, R" D8 y: n* I    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>3 x7 P0 M8 Z& }0 t# t" Y6 U
  </tr>
. N6 i5 K; o* M) b& f</table>
1 j2 g( E' x6 h7 u+ T4 A</form>2 W/ H0 I- ~' g# e+ E
<script language="javascript">
7 U% O3 p0 e, ?. a) L' {/ q. f; G$ W//人名移动; Z0 w3 F+ k0 ^. R/ u+ x5 F( q
function move(fbox, tbox) {
* l2 M" I. X8 u/ A: o. fvar arrfbox = new array();5 k' h. [8 v" t, |, ?5 K% B. t
var arrtbox = new array();3 P0 _' y" U- [7 x4 o# P
var arrlookup = new array();
  Q, t# K  G# U0 ^, K1 }# }var i;0 l! Y8 M$ o" B9 `1 v
for (i = 0; i < tbox.options.length; i++) {) Z+ `0 ]& g1 L. V
arrlookup[tbox.options.text] = tbox.options.value;- S4 Q. K* {2 N4 K0 c
arrtbox = tbox.options.text;
1 X5 }" B: k' N' f& l2 ~}
+ g+ Q* ]4 j4 g3 F$ Q# ^+ ]( ?( Vvar flength = 0;
, T' @- S) Z6 nvar tlength = arrtbox.length;
* J; S% P4 l! f6 |7 k/ j! cfor(i = 0; i < fbox.options.length; i++) {2 k. R% D; ~2 K0 x' }
arrlookup[fbox.options.text] = fbox.options.value;
3 ^  U6 v: o3 [1 E% y7 E/ i' uif (fbox.options.selected && fbox.options.value != "") {
) r8 R- H7 J3 W( Harrtbox[tlength] = fbox.options.text;( T( c. Q, h9 m1 X5 p
tlength++;
5 c+ X! @1 l: ]8 ]}
/ m" u  G9 K" ~. r( celse {: }0 \' B9 }) i: Q( r4 A
arrfbox[flength] = fbox.options.text;4 O9 T; t2 C6 n8 |, G/ R
flength++;: B2 Q7 K' f7 ?. h* c- \: e
   }4 f2 i6 o. q# M  U
}) {8 H$ |% ?% X( h/ b
arrfbox.sort();
2 N) _/ K5 M. Y( n' }) m, |! Narrtbox.sort();8 I) A/ k0 _& S7 h

: I' g- W6 m" w1 \$ gfbox.length = 0;
. V# B' N0 k% X8 F8 d- G2 q- wtbox.length = 0;
- ?( ~# W6 m" c2 n' |/ y  D- \! Lvar c;; C, [& v  Q, T1 T% X
for(c = 0; c < arrfbox.length; c++) {  `3 U+ m' R5 n0 u+ P% @! N
var no = new option();
8 M5 }& g/ r* H! e( ano.value = arrlookup[arrfbox[c]];/ K# C: v8 g1 z& M$ R
no.text = arrfbox[c];
; \- q& h' p4 v5 ?+ E6 gfbox[c] = no;7 y. Q$ Q5 J0 U$ K0 y4 J
}
# A) h5 r! S9 B. _$ u  xfor(c = 0; c < arrtbox.length; c++) {
" v; a' R6 ]- r) t5 w; ?3 X$ Avar no = new option();# o4 }) S, {5 f2 p' G
no.value = arrlookup[arrtbox[c]];
* n7 Q+ T+ ?# D) z& Ono.text = arrtbox[c];# I+ i( g- B3 r
tbox[c] = no;! m. @8 C8 ^4 u" h5 [% W
   }$ o4 M1 s5 E+ P( D
}- F4 Z0 I" l" b6 B% N
</script>6 o( t6 A9 l4 M/ i3 h: m" m
</body>6 a( Q' A( c/ f

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