Board logo

标题: jsp+javascript打造级连菜单 [打印本页]

作者: admin    时间: 2007-12-5 17:43     标题: jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"7 `( ^5 v2 F3 F* \+ z
         c pageencoding="gb2312"! ^& g# L3 x/ f' o
%>
7 J5 n- X1 b; f6 q( J<style>
9 K$ w! h; s+ B.f9{ font-size:9pt; }
# n+ m! Z: T  `7 I9 |$ Q1 p.bgc{ background-color:#aecaf9; color: #0033ff }
+ N7 u* F0 `3 G- x9 G' X6 j.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;, y+ q. L1 A0 d2 c6 \9 s
  border-bottom: solid 1px #4e7dc1;4 J1 e4 ]" C/ f% K( P7 e
  border-left: solid 1px #aecaf9;
* Q( u9 e1 L) y. Z( {  border-right: solid 1px #5679bd;" b! z4 S8 j5 @8 V0 L
  padding:1px;3 V* ]6 l' I2 p, \/ @6 A* \
  margin:0px;}
0 r  u. l. U, H2 ^1 K</style>" D/ K6 S3 @% s3 F" J( J, L& p
<script language="javascript">* V4 C, ]! _, u. H3 I: O# j" m
<!--
8 l/ [* X% @# e) e+ ~. Gfunction rv()+ `6 y+ i) y' i2 H+ |( J9 Z) T
{
* [8 M% b, i: V  n( i  var val="";
" `8 O$ t3 `$ Z: g' ?/ j+ I/ H# Q8 R  for(i=0;i<combo_box.list2.length;i++){
6 ]4 l  K( p  f# M7 ]   val+=","+combo_box.list2.value;
" x; ~* Q% Q% u& ?- W* i2 k5 _, l  }
$ c) a7 E3 p# e( ]9 q' ]4 [  if(val.charat(0)==","){( [! q% m- n4 Q+ Z1 }4 h  [
   val=val.substr(1,val.length);" e2 A' g* Y4 V8 F" v, z$ V. Q) k
  }
; R/ @) S5 B. L: B+ f  opener.form1.frecname.value=val;& S' C2 c$ ^( z+ T
  self.close();
% x0 D- M% X# n2 j# M2 q}5 g: n  a: j3 R# G8 @9 a
//-->. m8 G. }! P+ M( d3 `* g* S
</script># x0 h+ n, Q4 N3 r7 e2 d! M
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">- D2 g+ F5 a& u7 c3 r4 K# t& q
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
$ b- D" c- w7 B2 ?$ z" w<%
/ C* l+ v' v  O2 h- p# G( S( q  cdatasource ds=new cdatasource();  //数据联结bean实例) a2 x. o2 s" t# M, j; t/ W; S- w/ x
  java.sql.connection conn=ds.getconnection();
+ @5 _: M. V0 n! _* {  java.sql.statement stmt=null;% B8 K$ n" W- {/ Y
  java.sql.resultset rs=null;: B- v$ @8 W2 _/ x5 Z* M
  cdatacheck dc=new cdatacheck();: t$ _& Z3 Y" i
%>1 G& G- H/ W, }: |* f2 L
<%
/ l' {8 Y0 z" S- }" Nstring 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";$ _; G! G+ J6 \9 q! `9 D/ g
stmt=conn.createstatement();$ i/ g& A2 W+ o6 ^/ _6 F( o  p
rs=stmt.executequery(sqlu);) N' V- v5 ], d% ?6 S+ ?+ l
%>
! y; ]9 s: {$ R/ n<script language='javascript'>3 Z* T" j9 |: L, [/ Q9 j
arr = new array();
) T. s; E0 @; t<%  int temp=0;4 l, I1 ]  K$ q( N* z$ x$ s
while(rs.next())- c  }7 N/ u- {  f1 P* {4 Y3 T2 i
{1 U' T. j* t1 }5 N' B
%>0 a/ h2 o5 S/ v$ {# D" z9 _2 F5 k
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
+ e- q/ d! g1 l<%
  m6 |+ j7 k0 M+ ~" Jtemp = temp + 1;
2 k1 S" Y  I$ _- ~7 Q/ _}
# @/ \8 S3 R& w! {/ r/ j%>$ j7 |7 n; A$ X* C
temp=<%=temp%>;
: U4 S7 I& \9 E( ?; g5 bfunction changelocation(id){
+ e9 q" O! e$ L. A, f# f/ Sdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
. E3 A: q5 J; |% |2 K  l5 Evar i = 0;
- v) E# G) ~' B- U  zdocument.combo_box.city.options[0]=new option('-------','');
0 Z7 |0 P( |* Tfor(i=0;i<temp;i++){
/ W: A2 \( V1 G/ iif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
0 ]' Q0 w( \. wdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
7 s( }& J, i& E}
' ?- a( ?& D/ R# I4 a} ' ?( T0 N1 s1 w* t
} , z4 J" g( f0 d8 u/ s  H
</script>2 f! w( E3 y9 S' p

$ @) K" R  K: `<form name="combo_box">
* E3 L" u3 B0 S2 ?$ k$ L<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">8 o% W9 Y% m1 i2 ?  V' O: V/ C
  <tr height="24">) V6 K8 O) h7 O& O/ W5 x
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>" F- u" m! K$ ~0 [+ {' F
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>9 {1 B' c# W4 X
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>5 C0 L1 x4 L8 r! y; N/ C8 T  X1 F
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>- F, S; B: X7 p
  </tr>
: ], V+ ~' c& M0 T# b) i  <tr>
$ s( w9 N. @5 b! h    <td>9 ^; D8 \$ e) f1 H  p
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
5 c4 U) v( o9 V5 k' t& w  <option value="0">请选择部门 ---></option>- s1 |# X. h3 ^! q
<%, P! s/ \: z+ c
    string sqld="select * from tdept";
% {  Q0 V9 z8 K% qstmt=conn.createstatement();
5 R# c8 H' v2 `3 \; g! @" {rs=stmt.executequery(sqld);
! b- e. r9 M) `) v: `4 D7 g6 Awhile(rs.next())
  z1 m& S% B! A* m$ d0 D7 \{+ O; w2 S- i6 W/ D9 X# X, p2 V& I
%>
2 g' |. q& _7 M0 e5 |- y: I( A  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>$ g9 P. d+ K1 @# P- t% ]0 o3 J
<%
% O4 M2 [# p2 y, ^& s8 f, [}. j  R2 }2 ]% q  r" \; q
%>
- ^* ~% G1 [! m9 A6 S& f1 `9 F  </select>. Z2 e3 y/ a# I3 S* M* Y- N
</td>2 ?' j8 V' f: j/ J: I0 G* H
    <td>4 u; Z3 ?0 \+ S, V; q: T6 h) l7 V
  <select multiple id=city style="width:150;height:200" class="bgc">: j; }( q) A0 j
  </select>
+ E; H: D$ n" b% F/ P' m</td>1 q9 ]- ^7 K7 {. r! o+ a
    <td nowrap align="center" class="bgc">$ R) k! ~+ ~2 H+ J, x( L4 @" e
  <input type="button"  value="<<" class="buttons">+ D( [9 E8 {$ Y$ F3 w+ l% W! w
  <input type="button"  value=">>" class="buttons">( n7 w+ h- ~2 U! d
</td>
- y1 `7 M( s" ]0 u    <td>4 B8 j; x7 V- X% c5 S5 G
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">7 |! C7 G9 q5 ~+ I
  </select>( p! Q& U( a: M2 \1 L
</td>2 p, P& w- t7 U
  </tr>2 g7 e) g$ t0 j4 Z5 k# i+ V
    <tr class="bgc"> 8 _1 m  t' ^4 u( e- M# f. b
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>7 C8 G$ S. a& s
  </tr>
4 e0 I+ R4 N+ @% G- v</table>
7 ]7 l4 \/ |4 J4 \) w, F</form>$ U0 M. @. i4 I7 a/ A" t
<script language="javascript">
$ i2 r2 N) O& N//人名移动
6 r0 Q0 ~4 _, o& g1 w3 bfunction move(fbox, tbox) {  v9 v* C' c% z+ l; ?
var arrfbox = new array();
+ l' |" T! q/ I2 d/ F( _var arrtbox = new array();
, N6 Z) Z" S8 o% I0 M/ O3 \# |# ivar arrlookup = new array();* X5 x! `. e( t5 B3 }& m
var i;
6 A" D4 O( P4 r: q, O" b6 f* Y! Mfor (i = 0; i < tbox.options.length; i++) {' h/ ^0 F* O; C- Q- t. i
arrlookup[tbox.options.text] = tbox.options.value;# C( n% T7 O( n# g. _8 h6 i' e- j! s
arrtbox = tbox.options.text;
1 B$ F! O7 R* x1 Z3 D* Q}# {7 T2 C9 v' k
var flength = 0;
# Y& x+ y( p- X; f, |( g& F  {var tlength = arrtbox.length;: Z4 H8 _8 m5 Z6 d9 v' c0 l
for(i = 0; i < fbox.options.length; i++) {: T; ?* K1 J4 _7 v# A; f) v3 k8 e: {
arrlookup[fbox.options.text] = fbox.options.value;5 j, I0 q$ u/ X) V$ ]3 u9 L2 f5 @6 J
if (fbox.options.selected && fbox.options.value != "") {
; k8 D9 ~7 D0 h) `2 f0 darrtbox[tlength] = fbox.options.text;
& m" y) o) [. u9 Q/ wtlength++;- o% ]: q, b  w$ s4 @$ }- ~
}
# p/ w- R) d% L) N9 B! K9 J6 Uelse {
* U) x! W. G* V+ oarrfbox[flength] = fbox.options.text;- h+ Q+ g+ f9 y! a8 y# h/ x3 s
flength++;1 b( J  R! f# n
   }& p& x. c4 _  y9 s6 Q
}( Q7 L! J0 D6 D9 b  p% p+ d
arrfbox.sort();
9 V( C7 b$ R. d% Qarrtbox.sort();
: U" y+ |9 T2 D/ d- e7 [6 m, \) ^1 B
fbox.length = 0;
2 {0 ]7 W, q5 k: k* I" n8 O/ p7 Otbox.length = 0;
; j% X* O( l0 G; O3 `var c;
0 i" I) j9 g  k: A; yfor(c = 0; c < arrfbox.length; c++) {, w0 r! I  w0 v# C4 p, |
var no = new option();
- q* E  p$ q  j, Z/ Eno.value = arrlookup[arrfbox[c]];2 O: j! l2 r& g% ^1 K% y3 e
no.text = arrfbox[c];
2 ^1 s8 r/ ?) x% O' D; A/ efbox[c] = no;& P4 p  \: d/ P5 j6 T" Q
}7 `; c" i+ _8 z+ V2 G3 a8 H
for(c = 0; c < arrtbox.length; c++) {* e* }1 e. ^$ b* ^% _1 k9 k# h4 e% \
var no = new option();# W3 [! \+ d8 _9 O$ k" T( x
no.value = arrlookup[arrtbox[c]];
% d7 A! q& c# w$ C; T! V; Xno.text = arrtbox[c];  W# b  K: w& c7 z6 m
tbox[c] = no;
6 }- }: X, ~# G# T( v  p  B" f) i   }5 u. _1 _% w; [# K1 n% U+ C& X
}9 ]0 f7 d& a# U. {4 @
</script>
* d; L, z  M5 }</body>. P0 r+ o6 e( Z8 G





欢迎光临 捌玖网络工作室 (http://89w.org/) Powered by Discuz! 7.2