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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
, Z  I, W3 a1 j. _' Q         c pageencoding="gb2312"
' e7 }) g  L+ l- b7 o4 {# E2 \%>
+ r. ], q0 m! W4 e6 S3 E<style>
* Z( c  W7 T8 ~( m1 K4 r7 B! @8 E.f9{ font-size:9pt; }% Y* `  a3 A$ g- p5 d& o' x
.bgc{ background-color:#aecaf9; color: #0033ff }  ]( h  ~) \+ }
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;* b8 C9 q1 a' L7 E4 m
  border-bottom: solid 1px #4e7dc1;
  l% [% O6 L/ Z) h3 e: t- }0 M  border-left: solid 1px #aecaf9;
7 h; a8 |* x& d$ P* ^' J6 f: P6 _8 [  border-right: solid 1px #5679bd;
. Q% ^3 c9 i  A0 ^4 {* {. h  padding:1px;
7 {: E6 f  a  E8 R' x  margin:0px;}; R2 B. n# P2 \' t
</style>: Y; B' S! A) D' i$ r; O. Y( ^
<script language="javascript">: f! {) O" n# {, c* t
<!--
7 K6 Z" ~$ Q3 |3 ?function rv()$ S# m. w+ t% V6 d* k
{
* V2 U% o" V5 x  var val="";0 q  o/ t3 N$ Z% m! \( x. h0 H
  for(i=0;i<combo_box.list2.length;i++){
# Z6 h; Y& Q$ ~+ m1 u   val+=","+combo_box.list2.value;
) c6 A7 c: R  Z; K8 q5 e  }8 N2 r6 R) D! l+ }: W) _
  if(val.charat(0)==","){
% h, v3 b$ m- c3 H$ W1 s% R. T   val=val.substr(1,val.length);
9 @: x9 b9 O% p8 t  }9 @" g9 o3 E6 b* m' V
  opener.form1.frecname.value=val;  K  [7 \; V& C. g; S1 }" I
  self.close();/ I) j  G, N! l/ _& ~4 ]2 U: c
}
- p2 {3 f- g+ f8 b' E: Y//-->
; z7 K( A% B- O$ c</script>- y* s+ A$ U# A" V- L  }2 l  |- z
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">+ @  ~6 W4 d* s: V' q' e% }) {. ]
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
, |: S( n0 g' k4 f<%4 ]5 U' p7 \' r1 x  Y- d3 U0 \9 Q
  cdatasource ds=new cdatasource();  //数据联结bean实例5 h+ q: n6 H0 B0 t2 A3 N, i3 @
  java.sql.connection conn=ds.getconnection();# C+ w- ]9 ]3 ?0 @' a  F
  java.sql.statement stmt=null;  }+ j. c+ P; d$ T  c6 q
  java.sql.resultset rs=null;
9 E& o+ e9 [0 c+ M  cdatacheck dc=new cdatacheck();
$ ~) `( Q7 R1 m) D/ _%>
3 s; C+ B$ `6 d<%1 l1 }' b" T8 v7 O3 M6 R
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";
/ U* T# ?) b/ Y% A' G) F" Ostmt=conn.createstatement();! X# J; d/ ?9 f/ Z. l+ M; V
rs=stmt.executequery(sqlu);7 U' J$ c- w0 `
%># E. T, O0 F, i
<script language='javascript'>
9 L7 d! c3 \+ f" p2 j" f+ x; Yarr = new array();
5 N0 q) p3 s& u- \; e<%  int temp=0;. s2 s0 ~+ D# Q, V& ~6 d
while(rs.next())* b6 C% |& s" [4 Z) l
{% ^! c/ @. M' b: B/ T2 U
%>
7 B2 i0 C) w' f$ [$ Rarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");& \$ q) B4 A. h! P
<%
. q* K* n( Q- ~% Stemp = temp + 1;
* n; b/ p% v' x# w}
2 o1 Z* P, K! @# l* u%>
4 V* t, _9 H: ~4 J% {temp=<%=temp%>;
& q1 |. z" L1 L* Efunction changelocation(id){
9 A% i* ]- P9 B6 D6 A+ tdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
1 O8 ~: W  P& x. s# {3 Nvar i = 0; 0 F- Z1 [6 h+ G- G$ a
document.combo_box.city.options[0]=new option('-------','');
/ R( e' ^  B% D# ?for(i=0;i<temp;i++){ % d) B2 m. Z, J! p' x& ]" ~6 `, H- p
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
5 K7 ?5 U' X$ X5 {% vdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
, ^# s) h' v  H) A: ?2 ~} 1 t, u1 I% t, n2 t- p( l& _
}
# `6 s# a7 o* b! l  }6 }' D}
7 p' h( O3 o. t4 g5 \7 a' `5 t</script>* D6 I4 @& k& K% T% _3 R! E5 J5 q

% z4 h, Q; m) e( F$ G# H" T<form name="combo_box">
8 I: ?  W8 W0 S$ G+ w5 i<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
( N' {% z: E5 H6 X* ^  <tr height="24">! b, v! m" L" T2 ^- U
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>6 n# Q0 ~  A2 s7 J
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>" A/ g8 W! A0 N7 @
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>+ m0 X* t( ^7 F' N9 \) N7 S6 U
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
/ y) }% m2 V# ?6 e9 }8 x( l' e$ D  </tr>
; \# X6 K. E$ X9 \7 `6 P3 O/ y  <tr>
5 w; o- y5 z' Q- }1 u, v' Y7 W    <td>
/ b: J) e6 O& Y) ?6 F- ~1 \  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
/ v$ b: H, l: i4 w% C  <option value="0">请选择部门 ---></option>
- S& l2 b! g) I5 |<%$ Y2 ]7 ?, J# @( _; ~, s7 Z. B
    string sqld="select * from tdept";5 c/ n; W6 R( I( I) \3 q
stmt=conn.createstatement();; q! b4 X  v/ x; G' e
rs=stmt.executequery(sqld);0 n) |6 Q& g3 G$ x" C( y& i. K# B) M4 N
while(rs.next())
6 C" G& F% V  V( w{
# d& G; t- n. C( X9 ^%>; M- H- z0 f( k. b
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>7 k2 `5 F9 n4 q- f
<%8 g: E) ^  |6 ^( e/ U
}1 t, [; y% @# ]+ S; P
%> ) w  k: l" `6 K3 r
  </select>7 p6 ]3 c; d) u) o
</td>
9 V  Y* L9 M7 X/ x* T    <td>
% F7 `1 }6 g; [3 s( B% U) N: z  <select multiple id=city style="width:150;height:200" class="bgc">& K( ?" h% u' t7 L+ F1 V# X
  </select>
! N: O# Z9 R! D2 }8 f</td>, F1 G1 \! h! c/ D
    <td nowrap align="center" class="bgc">
- H. O2 f, C8 t" g  F3 B8 W  <input type="button"  value="<<" class="buttons">
/ |) [+ U5 ~9 m  <input type="button"  value=">>" class="buttons"># D4 o; f9 G. w) n( Q, p2 ]
</td>' S8 n! i9 f- ~7 C
    <td>
; ]+ j. J( y5 S. s. u  x  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">, B& d6 p7 _/ t$ i: _) H
  </select>
: c: _) s# u. d8 I</td>
$ Q$ a$ X) ?1 u& Z/ \  </tr>; c: s/ j4 y6 U, k% P
    <tr class="bgc"> ) N2 T9 r% h. j7 J5 l/ |; t4 v
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
& z" z; X1 s* |4 @1 V( U5 m, `  </tr>
% j+ h6 o; q4 R; U6 s, s8 K5 t</table>
; G1 e1 u( p$ Q2 Z% c  p% y</form>) P7 W5 p; W" N# c; [: B
<script language="javascript">
8 B0 M+ u+ q2 t) E) |# ~//人名移动* C  c: q% w' x4 i' T
function move(fbox, tbox) {
  z3 e, G9 d) S+ r0 x2 Yvar arrfbox = new array();
" D+ n5 I7 w& T& J2 T) yvar arrtbox = new array();% A- r) Y* F4 g" e
var arrlookup = new array();
: k. G& ^3 ~' h! l" Y  V: n( Ovar i;5 j9 M$ t% ?$ p) D
for (i = 0; i < tbox.options.length; i++) {* I5 f! C  s7 J+ u  V
arrlookup[tbox.options.text] = tbox.options.value;4 Q0 P9 ~! o( {! ^
arrtbox = tbox.options.text;! ?5 w" x! _- [
}
$ z) f% a9 S$ n1 e5 r7 Z4 Ovar flength = 0;6 w6 d7 @- {# k9 ~$ [
var tlength = arrtbox.length;4 d& U" h$ s: r* g) C1 m; E6 M
for(i = 0; i < fbox.options.length; i++) {
3 r1 _3 J7 V% D9 F* B5 Q8 ]! \arrlookup[fbox.options.text] = fbox.options.value;
; d+ H' E0 [$ S" ]  zif (fbox.options.selected && fbox.options.value != "") {& H1 r' O! n3 |; @- d
arrtbox[tlength] = fbox.options.text;6 j. n( t; i4 j2 d7 R
tlength++;) v- K& q3 P: |9 ?* D. ~/ b& c
}6 S4 d- x- T$ x9 ~5 Z/ J& H
else {
2 j; R; j5 A, V4 J, R' Z5 M% h/ |arrfbox[flength] = fbox.options.text;
( y( L- @& G% gflength++;
4 f2 U" d, L2 T6 i   }
$ M8 }8 g. q7 N0 o4 l/ e}( k' l! c* |+ U$ ?$ G  V& `! e
arrfbox.sort();
4 J/ ]3 U  ?% w/ Q' [  Barrtbox.sort();
& A. q1 v/ [( i, i1 _6 e. i3 ]8 l( z: f- e" p- O% {
fbox.length = 0;$ o$ a2 k7 h4 r8 W6 ~# |
tbox.length = 0;
) a% Z2 }+ r" |var c;8 C. [' X1 |. H. V8 i* P7 Y( l
for(c = 0; c < arrfbox.length; c++) {
4 Q0 S) R% b# h+ x, v* tvar no = new option();1 C0 x% {, I; g5 Q6 b% z
no.value = arrlookup[arrfbox[c]];
* ~+ I5 w8 o) M/ u9 b9 Vno.text = arrfbox[c];0 i. u2 N# @; i$ J/ r8 N
fbox[c] = no;9 l* F4 N0 l3 Y2 i& W0 h
}
: A3 d4 z% k) o! {: `+ m9 `" m8 nfor(c = 0; c < arrtbox.length; c++) {7 x0 ~! j, L$ E( c
var no = new option();4 f* V9 K% k8 D8 o4 }, v$ w& z% Q
no.value = arrlookup[arrtbox[c]];" \, a' N! h! N& z
no.text = arrtbox[c];
( R) `4 H; m: d$ H% n$ i6 Ctbox[c] = no;9 {5 K/ E/ ~- T/ S$ L( i
   }
0 f) Q' g) z3 T}
- F) j  T8 w  X( W</script>
! F9 v' k# f+ h/ p</body>- w: f6 y. Y' E. e

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