Board logo

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

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

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"+ u" O7 G# Q* ]' f( M* ?& o% G
         c pageencoding="gb2312"
) W  f/ Y6 n1 ?6 C; c& E%>
. M( S7 V# N. G% r" y! Y3 T: P<style>
1 m) D, U) n, o.f9{ font-size:9pt; }  O( c- f; Z) [* u
.bgc{ background-color:#aecaf9; color: #0033ff }* `, t$ }8 C9 {' L$ u& g! J
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
( g; w" X6 Z" r+ u& _, v  border-bottom: solid 1px #4e7dc1;
4 _/ @7 x3 U7 v4 Z9 l2 h; [  border-left: solid 1px #aecaf9;
6 }+ J7 H# S6 `  border-right: solid 1px #5679bd;
1 e. t% t8 ~* b; N8 b) }5 t/ t  padding:1px;) L" R) H3 D6 y0 Z/ C( p
  margin:0px;}
3 d" M/ R8 V( r7 r/ [2 s( P- ~: y6 z  @</style>* Y! B& L8 ~' B
<script language="javascript">9 s) a$ G" N0 T* M* \6 d6 y
<!--1 R' a) _7 C2 x! v: P$ A0 W
function rv()
. B3 `" D$ d& L" Q. ^* B{
* W' O) F0 h# ~' m, c" D  var val="";
4 ?  K! i. b- p( T' W  for(i=0;i<combo_box.list2.length;i++){
- k$ i4 U$ Y+ v2 l, c7 i   val+=","+combo_box.list2.value;
; v& D7 s9 t( ]+ M9 v& R; h6 n  }* B& i. a; q5 v  M8 g. r
  if(val.charat(0)==","){' C) M# Z" B5 k4 U4 H. L* v
   val=val.substr(1,val.length);3 p7 Q( v5 V: x( d
  }
( j1 x" j! m4 ?8 u% t; @2 Z- }0 S  opener.form1.frecname.value=val;
% w9 T5 o& R* |: d$ r% U  self.close();
' @1 O) P. g3 Z}7 H$ ~2 v) D2 R$ ?& h( h
//-->
+ o, z  C% k/ R3 I' b# i# A8 f</script>
# u* h0 c$ n9 ~8 y4 L' c5 j  L<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">. I5 @1 G6 p8 o4 P/ q
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
' Z: g& q$ u! x  Z( ]- Z  N0 l<%1 c9 c9 c$ L: B+ [( w
  cdatasource ds=new cdatasource();  //数据联结bean实例
0 |* O8 Z0 a: Y/ J2 L2 e) k/ \9 c  java.sql.connection conn=ds.getconnection();
. J  K' T3 C; B& N  java.sql.statement stmt=null;% x$ l$ ]* X  I: c6 f8 |
  java.sql.resultset rs=null;: F8 C" Z: x& J) Y3 N6 N, E4 z
  cdatacheck dc=new cdatacheck();
$ z& l+ R$ B; @* t/ ~%>. o4 y) `% j) l/ y/ H" g8 w
<%# B; T0 L2 n8 e) [5 G8 T
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";# |) N4 G) T* n4 Z: q; b
stmt=conn.createstatement();
4 o, G4 L6 Q, R2 q, Rrs=stmt.executequery(sqlu);
4 Z5 C& I1 M8 z3 t7 y1 D%>$ j: D0 p& L3 a1 |
<script language='javascript'>
6 L. ~# @) O6 D# o( S  Y' uarr = new array();" C% O6 s- L! C
<%  int temp=0;
- g" R; c7 [; }# o8 b5 Lwhile(rs.next())
' N/ H1 c2 n& k$ b' A+ I/ \{  ^! u5 b* d$ r3 S4 {( s$ m8 e
%>
& o! E7 S0 q( n0 s- W  T# t5 ~arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");! \) b# m6 A9 c0 V$ m
<%
2 T* c9 E4 k% {6 Ttemp = temp + 1;) x; a: [/ j4 G  f$ a
}7 [2 G/ g4 l5 ?* h
%># {  Y3 c7 V  l4 x9 H( t3 a
temp=<%=temp%>;) p1 Y3 G7 l' ^3 j0 Y+ }+ {& N
function changelocation(id){ " k) Y) `; X. H2 Z
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 : r: m- O2 \9 Y. o3 w4 V
var i = 0; " k- C! C$ i. d, N
document.combo_box.city.options[0]=new option('-------','');
$ J0 A  @/ c+ W! |4 g* z3 Afor(i=0;i<temp;i++){
" i1 J! E5 e- q2 g- E; Nif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
: f' K' L; s, d& {+ {document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
; P! z$ F& m: d% f: d) c8 V} 7 g3 H; N" |! R: K7 k9 c+ b1 x
} ( N$ q1 r6 o+ p
}
  k/ h) w5 K" {! U8 ]$ a</script>" C" @1 T5 {5 c: m1 \8 h' I) \
/ N5 b* s- t2 z) }6 {( S7 \( z' c1 S
<form name="combo_box">
& x# Z' i0 k3 i/ V9 U6 u6 y# l8 j<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">. e3 ~+ p" b% n3 X4 K
  <tr height="24">! d' d$ ?5 J+ z9 D
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
* M/ V1 z# W! }' Z    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
9 I9 @3 M. B  z3 d# I2 ?    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>% ~, h# B3 b) h9 C
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>' m  P8 C% T. [" d
  </tr>( @8 U6 j. S6 b
  <tr> 9 R! b5 n9 {: Z$ u, A
    <td>! i0 S" B- b; Q2 A
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
3 v' B6 D# a4 G- N" O, n0 X  <option value="0">请选择部门 ---></option>( c* a2 Z3 A" j" }( J. P
<%
$ _! b% M% i# w. _6 m! T    string sqld="select * from tdept";! C2 R3 T4 z9 M# o( d
stmt=conn.createstatement();+ r1 m& r9 `, ^6 h$ \- ]" a
rs=stmt.executequery(sqld);
& E4 O7 N- a$ B3 R' zwhile(rs.next())7 n6 P6 |) m8 @4 B/ Y
{5 O# Y" K# M: n0 R% I
%>
: a  l, e2 M  B% g+ X1 T$ _7 |  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>. P  b# y$ W3 Y1 m% Z5 `$ d0 ?/ P
<%) c6 \7 i% u5 ?. }
}& @7 o- S* R, ?' v( }0 n# d
%>
. S) q6 O& K0 J  s% Y  </select>. ^, {" z! x% e, e0 }+ o( _/ P
</td>+ F5 g) V5 Z. n7 t* l# M1 E( Q  H
    <td>% }2 Y0 a% i" Q) c% j0 F
  <select multiple id=city style="width:150;height:200" class="bgc">
( [. x5 f% ?  j  </select>: n9 W0 w9 G7 N! u* E2 V
</td>  [; g2 q9 [9 U4 o7 L# T
    <td nowrap align="center" class="bgc">3 Z& ^; O' L1 Q2 W% S! ]3 L- {
  <input type="button"  value="<<" class="buttons">
4 |! K! j) p: c7 z$ N3 V# w" c2 s  <input type="button"  value=">>" class="buttons">
: W3 ?; T" h# v8 w</td>
- k/ c6 O; z" @    <td>
) |' H& ]  k9 _; A+ g  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">* L2 b' m; h) v# a
  </select>! A7 s) C4 ]1 |) I+ p& r. o9 z
</td>
& Y( @$ o8 D9 e4 G5 [. t) c  </tr>6 M5 P2 Z( A5 p4 t+ g
    <tr class="bgc">
4 W( {5 H, }) l( V) s3 ]. O" K! U1 K    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
8 I( @+ D, S. B0 o7 z  </tr>
0 C( Y8 r/ [+ ^4 |$ r</table>
7 [& T  S" n/ l4 q/ a$ V/ L8 [</form>
; B0 p8 J1 R$ l) c( P<script language="javascript">0 z, Q/ k* m# K+ D: C' d3 K
//人名移动
5 C* D: F( u: ofunction move(fbox, tbox) {
6 L& O6 E5 V" x4 _" _; P* [var arrfbox = new array();
$ F1 T% |8 v& h7 ivar arrtbox = new array();+ f/ U1 f1 X% L' S4 ^1 g
var arrlookup = new array();
. s: o7 R/ @$ w- s3 `var i;
  @- z; f6 s% T6 ufor (i = 0; i < tbox.options.length; i++) {
, C& \4 E1 r* Z% B( L" G3 a+ Rarrlookup[tbox.options.text] = tbox.options.value;
3 ~( S+ h7 z/ L+ w6 f- ?$ [  R. sarrtbox = tbox.options.text;  n1 w8 Z4 l6 ~' E: }1 U
}, ^% d- H" O, M, ^0 O  ]& _( {
var flength = 0;3 K! I5 M2 `0 [+ x. K
var tlength = arrtbox.length;
+ f9 d* C3 Q, ^/ K; Z7 P8 t& M4 Ffor(i = 0; i < fbox.options.length; i++) {
/ j, ~! g$ ~, f# w% O% N3 Warrlookup[fbox.options.text] = fbox.options.value;
8 r" |5 V; f0 Xif (fbox.options.selected && fbox.options.value != "") {/ h$ T+ P! ^; l' H+ W
arrtbox[tlength] = fbox.options.text;
6 p. H- h* y8 b4 K1 Ttlength++;
+ E* w- Z6 d% _6 f; o1 n3 I}
7 ~: ~* M" I3 ^! ielse {
2 Z+ e3 H0 r, g) L3 m' X9 S, Q8 Varrfbox[flength] = fbox.options.text;7 j  ]4 s. q$ X# {3 L: E3 E; V3 M
flength++;7 r9 F7 y3 S; }9 i& h
   }, m" R" e) F/ B, V9 y- h' Y$ |* T
}
# _2 X+ a$ _& E! V+ D9 carrfbox.sort();
& d& O5 }% z6 R. d7 ^- oarrtbox.sort();
) y8 i$ L1 u9 L$ ]6 K0 M  g# j3 U8 L! @. i: @% e# |# g! R. a
fbox.length = 0;8 k/ ?" b+ L" I0 M
tbox.length = 0;' F3 X. p- o: V3 v  |! y: ^7 R
var c;
; K2 z' K7 z$ O  E" h: k' Hfor(c = 0; c < arrfbox.length; c++) {' p& n/ g  v0 d# i7 ?0 O
var no = new option();
: A/ o5 E  }' J+ }8 A/ mno.value = arrlookup[arrfbox[c]];# o8 Q& S: t0 K
no.text = arrfbox[c];8 _; G! p  R7 d1 v8 F1 e  _
fbox[c] = no;: f, J& I7 D$ b; s! p1 j
}
1 n/ T8 G& _% X) F! yfor(c = 0; c < arrtbox.length; c++) {
/ B4 U& d* [" G# [! qvar no = new option();; I4 L1 q7 U" Q- k% Q7 A/ w
no.value = arrlookup[arrtbox[c]];1 S: T, J( Q- u+ v% R1 Y0 h; l) Y
no.text = arrtbox[c];
& @& t# X- F6 m+ M" x$ Ftbox[c] = no;
) U. G# T5 K0 P; L6 l+ v   }* V/ |$ ?+ }$ R7 i- M) m9 ^. p# i+ S8 C+ f
}
2 @; G% L  C6 J! w7 a7 _6 t( e</script>6 m7 T* D4 s( [
</body>+ O1 b. z. T4 ^





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