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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
% c7 b% A8 s7 ]/ p  N5 h! e( l/ Q( w         c pageencoding="gb2312"
4 s5 D* o1 ^; Y0 y7 v. d) P2 R& T%>+ B5 A) I5 @1 o& @* q2 U
<style>. Z) X0 \# l  i/ N) j
.f9{ font-size:9pt; }! R' L. o! l% K  m  x8 J
.bgc{ background-color:#aecaf9; color: #0033ff }0 h4 `5 t7 Y, v, ^2 P* k& T
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;2 f6 \5 s/ p6 H8 p! j( i, x
  border-bottom: solid 1px #4e7dc1;
1 V# k, r) g; G* ^7 t  border-left: solid 1px #aecaf9;9 |" C0 p. M, [# |& U/ |
  border-right: solid 1px #5679bd;% |+ V' l6 h$ D) S/ @# J" ]5 ]
  padding:1px;
6 v- u: Y! r% h/ g! S/ i+ b  margin:0px;}' z8 Y' |  }& G& ^: N) n% _/ r
</style>
! d1 G8 W& O4 }* T! }<script language="javascript">( P* W! J0 a% {) v' s
<!--. Y; _& j% |5 z6 n4 E
function rv()/ w0 F$ G' I2 q  h, ^, b/ `
{
# O* w' F2 `9 o6 A  var val="";; [% P& k% g# w/ w8 B3 _, J0 h) N
  for(i=0;i<combo_box.list2.length;i++){
1 i7 m5 N+ W2 ]( Y$ {8 o   val+=","+combo_box.list2.value;
$ I* z; G* v: t: p+ L: H8 f& n  }
6 r- i: j7 Q: T( s( D* G  if(val.charat(0)==","){% q, Z3 p5 r! y
   val=val.substr(1,val.length);/ M, x1 A1 G2 c6 h- L2 u, ~! u
  }
. T# K! k5 g2 z# K4 s2 ^$ r% h  opener.form1.frecname.value=val;2 D( H  h* W0 U! D
  self.close();
& X) C. N8 P  M* T/ E7 q/ p$ y}
/ G8 n. k( `  T( n. k//-->
% e' ~0 x# [6 A# u" P3 P& N" C</script>
% L' Y, {/ X7 W( V1 r<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">1 M8 B" |# Y6 E# s) j; V
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
! ?! \. Y; r* }: X" @<%. ?4 L+ I- B9 ?; a2 D: V5 Z2 |8 R
  cdatasource ds=new cdatasource();  //数据联结bean实例
8 [- x6 K1 p+ T( j$ z. I' E  java.sql.connection conn=ds.getconnection();, j$ m/ `$ Q4 B- h/ e7 b) I: ?
  java.sql.statement stmt=null;
! Y7 k- B3 ]7 |# O  java.sql.resultset rs=null;
+ G# X6 ?8 G6 C" P$ h( U% e  cdatacheck dc=new cdatacheck();
9 ?4 e8 B7 o( j( i' _  k. a7 c%>
7 n1 ?6 q8 x; e# V& @+ w<%
* Y: v- W0 R7 C9 o% v- k$ qstring 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";/ O& u4 J% p$ _# x6 m+ g3 r
stmt=conn.createstatement();* b4 U$ U, J5 J
rs=stmt.executequery(sqlu);2 s$ p  T" X6 r$ V; G4 J
%>
* X. [% J$ @# r% Z( Y6 H<script language='javascript'>
0 j2 @0 v5 a: v8 J# parr = new array();- g! v% `( V% T- t  |0 p# ~
<%  int temp=0;4 q; W  _2 v$ |2 s5 a7 N2 ]+ n
while(rs.next()). y, Y5 R9 e6 \+ E( ^, y4 s. E
{
; i: R6 B# v0 w%>
+ |2 |  k: f4 K( E- carr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
7 B% v. [+ p1 p: p) e<%* B) c& I0 c2 X' @5 N3 Z' C
temp = temp + 1;
$ N2 Y- m& P0 }+ g" T; X# f" K' g}
: r% O1 O% ]6 o# q%>2 L; ~; Z# z  q* o
temp=<%=temp%>;
+ }' J8 I- L5 z! T" O; bfunction changelocation(id){ % g$ m* y( _8 U6 [) {
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
* X* h! G* V# Y! c2 \* |var i = 0; " o: |* I3 n0 J+ b2 P4 X4 }* l
document.combo_box.city.options[0]=new option('-------',''); . Y; d2 }8 X  f( Y; N& G
for(i=0;i<temp;i++){
3 T3 l( X8 x$ z$ x1 Hif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
5 d  f5 B  B% F* g( gdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
! V  F$ u6 t) V} 1 J- K/ \. ?; j/ r
}
& ~9 l8 F" ]3 f6 k, o/ S4 G}
7 I" t2 b6 s$ j% ~5 |</script>3 O4 R% u+ a, z4 x4 A6 N+ g; b: t7 L3 A
$ J2 z! y$ @0 E+ Z
<form name="combo_box">4 H5 _2 R! ^) `, ]# l+ N" g1 a
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
9 G/ B- i$ }* T2 i9 U1 N5 v  <tr height="24">9 e, @" y2 O6 n8 Z& f! o, N. C1 `% `
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>2 p% F" x- b! Q0 b# B8 t3 E5 Z
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
& j7 J1 q8 j: g3 x- \2 h% e    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>8 L  h- m/ U+ B8 Y2 h) V) \. F  B
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
5 e$ e, X: e1 ^3 o  </tr>$ U" f2 B) ~/ W
  <tr>
- b) C3 J' E& y    <td>
" g+ X' g; S4 Y0 K  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
/ ^  I& r  b( w9 k# p$ m  <option value="0">请选择部门 ---></option>
: y5 `: z5 o  w7 Z7 N8 \<%
3 n0 o: a9 Z% I4 g    string sqld="select * from tdept";
6 f, a$ Z' S1 x. r9 ^- kstmt=conn.createstatement();, T& N! H. M5 y
rs=stmt.executequery(sqld);8 c7 i% w1 g0 t$ j4 f2 u( m. p
while(rs.next())
& d! h) h' X% ]6 T- p' S{
; T  j+ [" |! t- \%>
7 n' m- Y) x7 t7 l' h  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>7 \2 D" y: h; t) W: u& i
<%+ l* m$ y% F' R; d; }4 P' C0 @. w. ~
}& I# \# b: ~/ m" L% s& U4 d: Y9 c5 k2 h
%>
, e5 ^. {( G" ^% X+ L" T  </select>( ^+ m+ C9 @; E' {# A" L+ j! X! h5 b
</td>4 @2 X! V! V9 Q5 I* ]& M
    <td>
, d  A4 H) V6 O6 A( F8 @$ {  <select multiple id=city style="width:150;height:200" class="bgc">
* N3 D( C' d6 K+ v  y1 \  </select>) e+ Y: n- J& D
</td>. O- C- r$ I8 }' ~1 G
    <td nowrap align="center" class="bgc">9 O( r3 Z$ F+ r4 M2 s: W8 b9 y
  <input type="button"  value="<<" class="buttons">
' ]2 v5 h8 {6 h9 r% ~- Q  <input type="button"  value=">>" class="buttons">! E9 C6 H/ ~9 Z: F( B# C1 A
</td>
, m9 ?  Q4 ?2 O4 b# H9 c4 @: T: _    <td>0 J+ S+ S: {  x% K
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
! W- q7 [8 b" |) f5 Q1 L$ |  </select>( w1 I9 n. q4 n2 ?! W
</td>/ K2 ?  e9 p7 n7 n4 @3 S. q
  </tr>) Q  n/ e) z  M
    <tr class="bgc"> 3 b0 G3 t' G1 |; s
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>( X! _5 p, f5 y
  </tr>3 I; d. x2 S# o
</table>2 p+ m, k0 t" D# z& p
</form>. C# l7 X- u: K( F
<script language="javascript"># ~( k* J+ z2 e$ S  H4 Y' D3 ~9 X" P, N1 b
//人名移动  f, p1 @6 }: d6 h/ h
function move(fbox, tbox) {- F* P% s5 S' O$ e. W8 u
var arrfbox = new array();
6 H6 A) j5 q3 @var arrtbox = new array();( w! \) Z( v" A. y0 l" U
var arrlookup = new array();
$ ?% o8 N- B6 i- P' Yvar i;$ P& H3 R" x* ^9 _. H8 C
for (i = 0; i < tbox.options.length; i++) {6 m. q6 Y& a, q" Y, v
arrlookup[tbox.options.text] = tbox.options.value;
. y) E/ P5 d' ]arrtbox = tbox.options.text;
/ G0 T7 W- C8 B}* t8 ~2 c5 ]9 B! ^8 c- \/ a% x8 @5 O
var flength = 0;
0 i+ S7 a, G! L' K0 |5 vvar tlength = arrtbox.length;" W: n! c( V+ N* {  D
for(i = 0; i < fbox.options.length; i++) {' ^1 x/ p! T2 x" C6 G6 J
arrlookup[fbox.options.text] = fbox.options.value;
; q; Q2 f% ~7 t# H) uif (fbox.options.selected && fbox.options.value != "") {
- \3 l, z6 c  farrtbox[tlength] = fbox.options.text;
+ d' [% N7 j* h$ `2 p$ |; ftlength++;9 h3 u& E/ Z5 P3 w2 O5 ]% Q
}! t4 V& R& x! Z9 B  l6 l
else {
5 i# t) ~4 c5 \) uarrfbox[flength] = fbox.options.text;9 A) W2 X/ K: h2 v
flength++;3 Y# B5 g$ y# D- y% \3 f- x
   }! l, R0 ]# _) ~9 C
}* P1 B/ i5 ?5 Q# r% b! y+ W
arrfbox.sort();
8 M, P6 Z) _6 sarrtbox.sort();$ |* \+ L- z3 n) j; L* B- s
" b+ c5 P/ x2 `3 p" Z  j
fbox.length = 0;. l6 |; O0 h8 e5 S$ y- H
tbox.length = 0;1 c2 R) W! z0 M' x$ Y
var c;- a1 j+ M5 w; {2 i
for(c = 0; c < arrfbox.length; c++) {
, [3 c# A" E1 xvar no = new option();1 B- B7 z" e. ^4 u
no.value = arrlookup[arrfbox[c]];
. Z% Q1 Q0 G/ L) j/ a& uno.text = arrfbox[c];
9 `- o! X4 @# Y* v+ P' y/ |fbox[c] = no;
- S9 X: u$ K; j1 M6 [  r0 ]}
8 w) G' K# e- x0 I9 n/ jfor(c = 0; c < arrtbox.length; c++) {
, a! {+ V8 `5 f$ h5 F1 wvar no = new option();, v$ J+ Y% {; z
no.value = arrlookup[arrtbox[c]];
  |9 G( c2 z% d( ~2 ?no.text = arrtbox[c];
5 _& J5 L+ ]( O" W) atbox[c] = no;
# e; y' `' A9 r   }
7 |- {" G& H5 \" m! c}
* W  |; v( M$ O5 @9 |</script>
. O" Y9 E; i4 N3 j+ n</body>  [& R: {4 f0 Z' R

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