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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"8 C9 e0 [0 i% v, N6 s
         c pageencoding="gb2312"8 i  X$ v/ L, r! A! t' X
%>* |/ ~5 @3 ]/ a. j
<style>
; a% g7 ]7 m/ Y/ w0 t! d.f9{ font-size:9pt; }7 G% Y/ }/ l! i: @4 M$ N! T/ C
.bgc{ background-color:#aecaf9; color: #0033ff }
" `5 g; \5 D* C4 T; C.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;" D, F9 ~& k, m" X$ W/ r" Z
  border-bottom: solid 1px #4e7dc1;" ~0 Y. R! S- u+ I4 y! P% E& X
  border-left: solid 1px #aecaf9;+ O% f4 b" B3 }9 M  i
  border-right: solid 1px #5679bd;# C. t  \6 W7 u" b! r% G$ T
  padding:1px;0 t6 l2 p3 K4 }. s/ ]) r
  margin:0px;}7 m4 {* }5 O* s0 p/ V- `
</style>
) A! \5 e/ c+ v- s  b) C9 O1 f<script language="javascript">
* m2 F8 p  N, z: w! E$ o/ S. L<!--; k6 b; F6 T7 o; s' k1 D4 ~
function rv()0 b+ z% V. Z. v" D
{
0 H. [" v& u  `) j7 Y. J1 q* f  var val="";. r% R* i! I/ w( O  v
  for(i=0;i<combo_box.list2.length;i++){
0 j; O0 O( p5 w) g   val+=","+combo_box.list2.value;' T# }' [& K7 f. S/ u
  }1 r6 X1 N$ K9 P5 v4 |8 c
  if(val.charat(0)==","){
" X6 ~4 p7 g  x2 X   val=val.substr(1,val.length);
0 U7 W" W& ^& D, z  }/ G, S+ i. B0 b: ~5 P& U
  opener.form1.frecname.value=val;( r' [9 ^+ y! g% u
  self.close();
+ k+ i+ A# j$ S/ ?! \; u# E}+ k( l; X# X, f2 |. T# d( P6 J, Z- F
//-->6 Y( L- M" ?9 t* ]- f1 l4 M
</script>% [- p( {! }! n$ E
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
8 W- _& o9 s. h; _/ g. p0 W5 m<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
! V* }) C: ^! y; S* T; v  k<%$ p4 V( s9 A6 w% B6 M: e! S* d, ?. o) y
  cdatasource ds=new cdatasource();  //数据联结bean实例4 _  A) `" [' x- w/ E! u
  java.sql.connection conn=ds.getconnection();1 s9 \, }1 @: S1 K" v1 O
  java.sql.statement stmt=null;
2 X% r2 }3 S! [7 y( y  java.sql.resultset rs=null;
2 g" w- x2 ^3 ?6 b5 f. a  cdatacheck dc=new cdatacheck();
2 Z1 e2 ^1 L9 m# f! b: h%>3 t+ q: {' ^8 g- g) b% l
<%% f& C' ^; F% v, [, v
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";
  f- {! O( O% R" V8 w7 U' lstmt=conn.createstatement();" C5 ~* ~+ A5 k9 K5 {
rs=stmt.executequery(sqlu);
) D9 ?$ _! O7 q1 P6 O! J0 u" z%>
- R) a  g* a- c# X7 [( {<script language='javascript'>
) M2 M; R3 q" M6 K8 |* Qarr = new array();
0 Z& x4 o! W6 d1 c  D% f: y# f<%  int temp=0;, N4 e7 O7 m4 b  M8 m& L0 F  [# |# o, i- g
while(rs.next()); i- Y  C; {6 D  H
{8 e$ ~& C+ W0 ~. T
%>6 ?8 `6 f$ R% w, M7 O
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");) Q' x) v4 g) v) @2 u
<%* x; Y/ W! \! B2 s
temp = temp + 1;% ~, K5 x4 S) E- n6 z8 q' v  m
}7 M2 M5 ~. _8 j, G% s+ r
%>" ]* u% ]' E6 T
temp=<%=temp%>;
; ~8 h/ d% m- n. Q  m' @+ S" }% Hfunction changelocation(id){
) W% h- W5 g$ V  D" E2 q+ {2 F/ E& Zdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
$ P+ F2 E: y2 d; |var i = 0;
- \9 D4 c7 z  ~* U# B; _document.combo_box.city.options[0]=new option('-------',''); ' U, i3 s) b* m2 b
for(i=0;i<temp;i++){ / W* W0 ?( g  C+ M. M8 i
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 7 W' l0 y, G3 P3 ?; _/ w$ ]
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); ; G3 {9 E2 }9 A- a1 o8 g8 }# O
} ! ?4 ~( V0 f$ b3 |8 N" t, y
} % z8 u2 O) k/ [0 ~
} 5 b; ?" ^& K* T' Q  ?- P
</script>) `& _$ ?7 Y* j1 q
3 F4 N% [+ q( l( U. U
<form name="combo_box">  S" z0 j7 E: \, n' K# C) E
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">7 [% K7 D6 y3 g" V
  <tr height="24">9 B) ], [3 w$ s' R0 u4 t  N$ x
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
) s1 U, a7 T! K$ s( C    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>' O! S; F+ M! n" ^
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>5 Q1 V" ~7 w1 m, g0 x# U
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
- o; g' F( O% _1 P$ h7 u4 U  </tr>
2 F; S  S, V* W1 I  <tr>
$ k4 ]: f. H3 Z9 ~' C    <td>2 w. z- ]% t6 F- A- k
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">+ F6 U6 ^7 B$ O3 q
  <option value="0">请选择部门 ---></option>9 W" g/ N. U' Q" v4 m* L9 v- V
<%
4 _+ P" F9 V' }8 k2 d) h, R    string sqld="select * from tdept";
. Y' }0 L0 |' n0 |2 v$ Lstmt=conn.createstatement();% w# e# L  i3 \: w& r5 y# t# B
rs=stmt.executequery(sqld);) R' i  ^& A. Q( M
while(rs.next())
) ?5 S; |, R# A: [1 o/ b{* D! c& |) l- I1 b
%>2 T$ ~& f/ v( `& p9 X- S
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
; s$ h6 f5 ]9 X/ d: v8 ^  `<%( {' G5 J8 @7 S' _0 z- @0 D
}
3 E- S5 E6 G) U%> * e) F6 s$ E' X1 k0 O
  </select>; ?. d% a2 P/ Z" [" X; Q
</td>. s6 u9 {2 z9 S% ~* x3 O3 j
    <td>$ k4 ]" b1 E' o) C/ P
  <select multiple id=city style="width:150;height:200" class="bgc">
) _" Q/ ?1 \/ W+ y1 @; s  </select>
, A7 \: G0 V# _$ a* x</td>8 I- `2 v) i) v( Z
    <td nowrap align="center" class="bgc">
$ S3 O" E# F& g  <input type="button"  value="<<" class="buttons">, W: z  L. d+ [. d6 U- T' A' ?/ J  O
  <input type="button"  value=">>" class="buttons">
1 m4 W9 E; B) c+ R7 q</td>3 V8 r" n! z  U0 T% c
    <td>  F+ Y6 ^1 v, z% C& P  E% _( G
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">3 [* ~, _8 _/ @' z. O3 p
  </select>" q+ ~1 M, }; V" h& L
</td>! I& r& m9 k! @/ |
  </tr>
% {; G* }1 o" @( n5 A    <tr class="bgc"> ' _; F+ f( @/ v! |  ?
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>& g7 L; {; o+ p( l
  </tr>7 I3 V2 ^1 q' _$ g" W1 m. C
</table>
* R# @5 Z' F0 H# V9 ^* x) D' h$ N</form>' |. j4 Y: [/ @1 D. K: J
<script language="javascript">2 ], ~0 w- p/ s- ~
//人名移动
: x. {* H" ?; W3 X+ X# \function move(fbox, tbox) {
% Z2 t. S* @1 h3 Uvar arrfbox = new array();( v) n- X- O+ A9 @! Z. {
var arrtbox = new array();& b" |1 ?1 j! U& f; C5 Q& ~+ O" x
var arrlookup = new array();, k* x" K; M( o! b8 [1 H! I
var i;
; b, O+ Z1 t2 r; Pfor (i = 0; i < tbox.options.length; i++) {
& \7 K, m1 s1 ]: [( ]( ?7 karrlookup[tbox.options.text] = tbox.options.value;
  P# r/ i( S3 s7 Q4 W1 {arrtbox = tbox.options.text;2 p/ e# c* g* }6 F% i
}
( O* w+ \2 z4 l* C$ ]3 x* Fvar flength = 0;
2 v, L# U  B" L; L7 ?( t7 G/ ~var tlength = arrtbox.length;
# I2 j9 _; F9 L) V" mfor(i = 0; i < fbox.options.length; i++) {3 Y- b% }, w: w
arrlookup[fbox.options.text] = fbox.options.value;
- ~8 G& ]$ }/ t7 oif (fbox.options.selected && fbox.options.value != "") {
( B  i4 c4 _) L* n" karrtbox[tlength] = fbox.options.text;# x+ W8 ~; r/ Z6 x! T
tlength++;
' z5 ?5 J4 D, T2 c}( j# m9 V6 |' M( Y* @0 |
else {0 B3 |; L  a' p" f! r
arrfbox[flength] = fbox.options.text;
/ j9 K$ a, ?# W+ tflength++;3 m8 b5 Q  m* B
   }
$ u: x$ R. Y* E7 [}1 k  ?, f% Q% Y
arrfbox.sort();
/ `0 q. v! ~* d! Zarrtbox.sort();5 J( w) G( P8 }1 P  P" g5 z, ^
( L% A! Q3 E6 v
fbox.length = 0;
( U  J6 `1 {6 g, ?" S, D8 y- htbox.length = 0;  q( ]! d, `0 D) d# ^/ V6 ?
var c;
5 x, K6 y: e/ o4 ~for(c = 0; c < arrfbox.length; c++) {
7 b% [3 c1 `) yvar no = new option();
/ ~" r* v5 J; ^* u3 Bno.value = arrlookup[arrfbox[c]];
1 o0 Q& J2 m! U1 h9 L" d* K# o! Tno.text = arrfbox[c];" _" z& y/ u' s. t; \0 C4 b
fbox[c] = no;
7 O$ r; b: E% {}/ W" R& Q& u' `+ `
for(c = 0; c < arrtbox.length; c++) {
" E: a( x2 V# m4 Svar no = new option();4 U0 b7 Y2 b6 O( R$ U- ?: h, s5 v5 B
no.value = arrlookup[arrtbox[c]];+ J& t' c3 m& N: c! |
no.text = arrtbox[c];
5 S. j' o0 v4 D8 L+ stbox[c] = no;
. m7 s9 v2 `9 O6 @1 y. ^9 a   }
0 ^" P. ^. A/ O$ m}
& z- p, U- G% z+ g% K0 q</script>
! Z5 I+ d3 a8 Y- {</body>1 l2 ^+ _- B4 [

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