返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"+ y, M+ a5 Y; q+ i( _
         c pageencoding="gb2312": ?: n5 _% z# P1 c! M0 R
%>
9 n' r$ [& z6 E' U1 G! q<style>
) V$ i+ n6 z! i.f9{ font-size:9pt; }
: m. [1 ~0 B9 d" ?" Y.bgc{ background-color:#aecaf9; color: #0033ff }
$ r% e- M2 U! U( r4 n+ y.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;4 F, J4 S+ i) u, Y: r, L
  border-bottom: solid 1px #4e7dc1;5 A& m3 L+ u8 @
  border-left: solid 1px #aecaf9;' a2 D8 Y( S6 g- c% u* T2 W
  border-right: solid 1px #5679bd;8 p0 O$ D- A/ m1 V# O" ]/ Y) B
  padding:1px;+ H3 u7 a" o- Y; n2 \
  margin:0px;}
  P4 c# _5 L' z: @! G% e4 s: i7 u  z% ?8 _</style>
% I% W0 E1 q" O  p4 K<script language="javascript">
& e( a2 W2 J7 G6 q4 K: Q+ O$ Z<!--( ^7 u2 n# m4 H9 G' z7 D. e2 d( |
function rv()
+ p' D1 |  u$ D  r; E) A) W* \{
% [$ R6 l1 U. a  var val="";
) K7 g0 D1 V* I1 @, ^$ p  for(i=0;i<combo_box.list2.length;i++){
& V8 ^/ E9 M0 m- w) j   val+=","+combo_box.list2.value;
: S9 C% |% Y( v, {2 x  }
# M: v3 [5 L4 }7 i$ @5 _  if(val.charat(0)==","){- k: B# h/ q' r/ D9 s
   val=val.substr(1,val.length);3 ~. l3 x; L2 w  J" h/ O8 b, v
  }
+ X" {" t% e5 K7 k$ _5 w  opener.form1.frecname.value=val;4 x5 ~0 ~" F/ C& O) W: K- A- L
  self.close();7 d5 T. ^& x: u7 a8 e! \8 ^
}
& Q( C: L  W5 w* G0 ]//-->) `8 z3 e6 P4 v- x
</script>
: J8 C8 o$ n/ @8 M' R5 K<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">4 v0 H4 n/ X* f. |& L- v
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />. \8 O+ j# s) [; ^' h% i8 x
<%% a9 Q# V+ \0 e' I. F& h5 t; J- t
  cdatasource ds=new cdatasource();  //数据联结bean实例; g' d7 E+ O/ \& x. p: r% }
  java.sql.connection conn=ds.getconnection();
  R0 k/ e: N" F7 n  E  java.sql.statement stmt=null;( r* y2 [$ `' `& U" v7 \
  java.sql.resultset rs=null;
# }+ B/ K! ^3 N- d$ A1 d2 D% ?$ K  cdatacheck dc=new cdatacheck();
+ b- p- Q" V9 a%>
; n0 L+ [: t1 _- c& m<%) N# g4 Q  O$ o) r6 D9 \' h, q
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";0 P) X: X) V4 d3 O
stmt=conn.createstatement();8 j! ]! [0 o; Y2 R, G/ x
rs=stmt.executequery(sqlu);
$ W2 g. S/ U: p/ g; N; x1 M8 H%>6 M! r3 w6 e9 ~$ x$ q2 S1 ~9 u
<script language='javascript'># J' p% G) G9 L/ U$ j4 c  \: Z& T
arr = new array();- a; n7 D) \- K! [4 l: D0 F
<%  int temp=0;1 X* _. a6 M& X  `
while(rs.next())
# o+ x- O% i+ \. B% u' A8 Y0 y{
& p9 I3 U8 w) _# E# {%>
& r+ N' N+ T7 U3 Garr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");9 y* Y: t2 p2 d; X. V$ |
<%
! z0 _% R  \0 `) p, l6 Btemp = temp + 1;
5 u6 D( d5 Q9 E/ U$ s# F7 N}) ^6 b0 P4 c$ @$ Z0 I/ u
%>3 ~. N7 F+ e; }3 e, n, d* m; Y
temp=<%=temp%>;; E$ ?) }# `: L- D. ^' A
function changelocation(id){
; Z7 `" N7 x( e! Rdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
6 W* R+ l/ {" {/ B+ C6 c+ |/ Evar i = 0;
! D) {( u& g. r. `/ C5 O# vdocument.combo_box.city.options[0]=new option('-------',''); 1 q8 L/ Z1 m7 S
for(i=0;i<temp;i++){
+ O2 ^0 [: K3 wif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
- w8 o* t  }, [% E2 H9 \. ?& edocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); . x; k6 ?9 v- O4 [2 @0 P
} 5 ~( M' Y: w- y0 \7 Z
} 8 K8 f3 `; U/ n2 W# a: U$ V
} " L- B! t4 K  `$ I' h1 d
</script>
+ `1 p4 E( A) f- g! _/ v  q" U6 E) R0 X1 C+ W
<form name="combo_box">" A% M7 I! B* q9 ^" Z' t( L
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
4 D0 r# s) f: ]6 q! h  <tr height="24">
. f  t) W: Y, e1 Q) y( {, z    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
4 W$ K8 N. w. k' `+ R    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
; v, C4 g, X2 D9 r    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
- |' Q, `2 \: R* q. X# j    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>' O: Z& Q( [. p; E4 p# a1 ^2 M
  </tr>' O5 ?- x$ z5 a6 k& Q
  <tr> ) T: Q/ ^( U  e9 ?9 f
    <td>
5 ?# K2 c# `& P: [6 L  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
, g; f3 H1 ]0 H  e. m7 ^3 f  <option value="0">请选择部门 ---></option>
/ y. W; i6 Z( F<%
8 i, u" e! s; X( w    string sqld="select * from tdept";
6 h9 e. u7 l" g; G6 Z! K! dstmt=conn.createstatement();
  ]' n; d, B1 Z7 v" X' I7 z( irs=stmt.executequery(sqld);( [$ g  H2 ~. M" z8 v( k# l
while(rs.next())
7 x, ]; D' D0 @7 N7 X" `{
% N( s% Y) ]9 ?& H; _%>
) y3 h2 K' @0 _1 f9 O3 Z8 I: k  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
# ~- Y0 c% L. o<%3 f) |- C2 S: T4 `# }: d
}
0 Q# I* O  J7 s; `3 \' d%>
. S& z( j5 o5 v- @  </select>
0 S& g0 C. f6 U</td>
6 S2 z4 p( M) W0 W5 ?    <td>  L, c8 C- x1 }5 J4 h
  <select multiple id=city style="width:150;height:200" class="bgc">$ ?9 |: S* w# s$ n# u$ E
  </select>
0 j  [  Y2 W5 U1 v. d</td>$ V" H* A* N; ?1 r( S
    <td nowrap align="center" class="bgc">
% _% C$ `5 T) N/ N4 i7 ^5 ^+ L  <input type="button"  value="<<" class="buttons">0 c( |* j7 v- E. }1 j2 d. _
  <input type="button"  value=">>" class="buttons">4 A# b& U8 w! N
</td>
5 |9 c# q6 s3 M# _4 G1 T7 H0 G    <td>( _# E  H. p' Z
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
8 m( i- |: ?0 _. L0 p3 u9 T  </select>4 M# x% ~- l# p. Z' w3 D6 K( j* r* @
</td>4 n3 e1 f  i6 l( q4 m
  </tr>7 a# Y4 q5 u+ w& y6 ~' m
    <tr class="bgc">
* _$ O, J$ x" J    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td># J% I% t2 [* T! Q6 W4 P" W, p
  </tr>
! _1 K9 j  v' J# b</table>
4 U, [% G4 w( P' I* o/ M</form>, a' k2 d/ D6 M
<script language="javascript">& B; L# p/ [4 s- S: w
//人名移动
. {+ n+ S5 ?. G; o, Kfunction move(fbox, tbox) {
$ p' N- E5 L! g2 Dvar arrfbox = new array();
& V& u" p# G5 S  i* wvar arrtbox = new array();
2 I: R* z6 ^  l/ Z7 k9 H# e4 Evar arrlookup = new array();
1 e2 }* [, d' m6 |2 Fvar i;
9 r+ B4 t4 r; j( b' f. _9 Mfor (i = 0; i < tbox.options.length; i++) {% ]6 c4 h3 X9 T0 o& c. `
arrlookup[tbox.options.text] = tbox.options.value;
' Z  @6 t5 I5 k0 U  sarrtbox = tbox.options.text;& e. _0 ]: L9 M. D- x, Z
}
: ]) \1 f) v& T0 ?, Cvar flength = 0;" O" \' u( c4 j: S. W
var tlength = arrtbox.length;
, ?- L  P  N: t0 }7 nfor(i = 0; i < fbox.options.length; i++) {
; ~( s$ w% a; Qarrlookup[fbox.options.text] = fbox.options.value;
5 T) v  v1 |3 G# }if (fbox.options.selected && fbox.options.value != "") {4 k/ R4 P( e0 s! o1 x- l8 a& Y/ j1 f
arrtbox[tlength] = fbox.options.text;
5 u" R' G: f( C: ?! R5 Ntlength++;
. J- h- h# Q$ A2 y# Q}) |3 U; q/ y9 c& H! M$ l
else {" N) e$ m2 ?' L- M5 i4 D
arrfbox[flength] = fbox.options.text;
9 h( p) V! ~+ h/ iflength++;
7 S7 X7 @- ?! R5 Z- ?" a1 {6 s   }
: r3 D4 |) _  `3 V/ t& D# w}; G# U6 N  U- T  F" ]
arrfbox.sort();
& K4 Z9 r/ I/ p7 V; rarrtbox.sort();' o2 O1 J5 z: i; F9 \* c

, O+ v+ k8 d8 m' P* c6 tfbox.length = 0;
& w, s# L0 u* wtbox.length = 0;8 h% q. C  ]( F; S" z' F
var c;
5 z8 `" Z) k- T) p8 Z6 |  kfor(c = 0; c < arrfbox.length; c++) {
, V( j  H2 o( m& `var no = new option();
. d  s& ]9 o; k) {; \5 L6 a3 Kno.value = arrlookup[arrfbox[c]];
; O" E! a% c) K. ^no.text = arrfbox[c];
' M& N% J; }; T+ O/ d/ A7 F" [fbox[c] = no;
( o' R& Q1 z# T. X3 E}
0 v- G3 b( _1 U4 Q, c# Dfor(c = 0; c < arrtbox.length; c++) {; \" |6 t+ g  G3 ~$ X; M. i
var no = new option();
! g7 }4 y% O, _& N" M8 ano.value = arrlookup[arrtbox[c]];
% l! c% X: X) Q% Cno.text = arrtbox[c];2 n! `8 ^' F7 i; p" N
tbox[c] = no;
5 }; M' o  E+ V$ O   }
$ F: N  ^' H: a" i}8 v0 y- v% x" R, q3 m2 Y. o
</script>
( l9 }* C; G( [0 }2 N</body>$ ]" N: C& b& O- J

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