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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
, Q  `/ H' J$ c3 W7 \         c pageencoding="gb2312"/ w0 R+ y' e* ], ~3 t4 Z3 y$ E
%>/ \' e/ E* B. S2 G/ q/ H1 m
<style>: e* ~; c& c( L' U& l
.f9{ font-size:9pt; }7 N: A# \$ @+ Z- v& z# G
.bgc{ background-color:#aecaf9; color: #0033ff }
6 `& m- j. [6 I- \6 E.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
9 Z* M; l* u; L$ x- m. W  border-bottom: solid 1px #4e7dc1;
) ]3 t, q4 G2 y! g9 c( B& l  border-left: solid 1px #aecaf9;6 Z# L5 p* ?" W$ }
  border-right: solid 1px #5679bd;
6 C1 E" h8 s4 g% d3 ~6 e& g2 R  padding:1px;* `, x4 k. t' O9 j# b% @. N
  margin:0px;}! S% y1 F' g1 u
</style>3 q' X& J0 H. |4 A4 r6 l' a
<script language="javascript">
$ R3 U+ w4 \) v/ v<!--
) K9 \$ G0 P7 U1 kfunction rv()
( d+ ?7 ^4 i4 `- ?{* v6 F3 l1 F. |5 \3 o2 M/ K( q
  var val="";
9 e1 ]3 V) K' c; b: c, x1 J  for(i=0;i<combo_box.list2.length;i++){
" N/ V0 x  }$ Z) @$ r- J0 c   val+=","+combo_box.list2.value;, W% b7 l  |( y, {5 T% X+ r0 E) [! K8 t
  }
" `3 Y( g2 m5 E1 Q' U7 ~* f* J  if(val.charat(0)==","){, C9 `+ ^6 d% s* f% z
   val=val.substr(1,val.length);7 C- ?& V% L8 ]/ [9 w2 m
  }
8 y2 c* I* W- S) o$ Q* J  opener.form1.frecname.value=val;
* a9 l! W0 q- f; ^& X  self.close();
. }: \% Y' W, i- k0 G" [' e; ]}
/ c. V' q; }& B) T; ]//-->  f  S7 A6 }+ ~
</script>& a$ z6 x* W% ]# n# P
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
5 D: r/ w0 q5 `" f6 {9 y# E<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />) L3 y) n0 T1 c5 E' n* y6 E/ l8 `3 a
<%% y+ O0 Q+ Q7 B0 c7 x, F
  cdatasource ds=new cdatasource();  //数据联结bean实例
8 |  k3 x( [( R+ N  java.sql.connection conn=ds.getconnection();( i) A0 V/ g, K2 u( U0 O, E
  java.sql.statement stmt=null;
. Y/ p( F3 r& P7 {  java.sql.resultset rs=null;8 E1 X/ [4 Z& f
  cdatacheck dc=new cdatacheck();  _2 B7 N+ G3 y9 Q, a- J
%>
$ p: o4 k8 [3 B9 _* K4 U<%
0 Q. J$ T$ r2 i: Pstring 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";
! E! M6 Q! ]4 \) j' d5 t6 A( z# `$ D& nstmt=conn.createstatement();* `9 L0 v* A0 _7 j2 V
rs=stmt.executequery(sqlu);
4 q/ k8 J2 {+ c3 ]%>% I% V5 e- s# G3 g) T% ~& u: x
<script language='javascript'>
! n9 j$ ?! |0 Y2 Aarr = new array();
: @6 E' E* {2 N, o9 q3 q+ V<%  int temp=0;
7 [% \1 J5 H/ B4 K$ _while(rs.next())1 t, K) N" i( J8 [" f8 l
{6 H0 s9 b# |% F5 n
%>
! m: M2 B( d2 V( r. X, Xarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
. e) ~! p" p1 `% L8 k<%- \& F$ D( U6 u' Y$ W
temp = temp + 1;! N: m* i: y  y. |
}; J2 D% M7 q( E" t4 n' T% c4 Z
%>4 Y5 a  _8 n/ \  n1 L$ n
temp=<%=temp%>;6 f) d  I- x* o% ~
function changelocation(id){ 0 H% d* c0 c: t7 G$ }6 }
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
# ~9 |% O* o7 J- s: R8 N, avar i = 0; + H" A) W4 L" \1 V. b
document.combo_box.city.options[0]=new option('-------',''); / K4 r2 P/ k0 G, {% i/ a
for(i=0;i<temp;i++){ ( F# \0 B% J) q$ w, R+ m9 u% R
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 7 P  _" b4 s5 R
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
# g5 @& `6 [- c# z2 w# ~} 1 [2 z0 j1 V( t  \! z% Z  d
} : u: ^: c9 y+ p
}
4 Y) Y$ ^6 P  Q( a3 D7 W</script>
( k* f$ u+ D" l+ c! l% @' w( L! z# a' B" o( @6 Q
<form name="combo_box">: ^1 m/ A3 M. v" e6 v( M, s& V
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
6 \) s, V3 E. Q" t  <tr height="24">
; ~4 L7 E' h' |9 c0 J+ X    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
8 B7 `& s$ g3 \9 U( n. S    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
0 Q, w& c8 F; n% b5 M+ G3 B, N5 Q    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
* y/ [6 T  `& {  C    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>+ t( h' B+ a4 Z" s; r$ m: n
  </tr>* \* ?" R/ k0 w3 H  C
  <tr>
( V; O0 i  r0 E. G    <td>
5 \5 \4 \. a3 `" e' R  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
8 |. n4 y8 W0 U! f2 l, g  <option value="0">请选择部门 ---></option>
3 k5 l! x: W( k7 ~<%
" n2 H% H2 q# R. L! c    string sqld="select * from tdept";# p: N' t/ a& z7 P9 y6 U0 ^: c
stmt=conn.createstatement();0 R' @! \- Y& S% O: f' o1 }7 @% `
rs=stmt.executequery(sqld);
: S# A. h# E8 }5 Kwhile(rs.next())
- e5 t  `& ?( K8 Q' w+ g& ?{
" `: @8 L+ Z7 E%>/ H5 W5 J5 m3 m2 |: F- G: v* i
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>/ t( ?/ K  i  o. A4 b
<%# Z/ y4 b8 G" h
}
6 U( B7 ~: F7 W& T. G%>
5 l$ v& F" V+ d  </select>/ M% f7 D4 a" H% B( h: j, y
</td>
% E: [, T( C1 n: W$ ~8 f) ]2 O1 b0 K    <td>/ i  L5 @6 E& B7 E
  <select multiple id=city style="width:150;height:200" class="bgc">4 e4 \% y3 O, |6 K; U9 ^
  </select>. S% {7 o1 v7 i% {0 z! d7 O) V
</td>
% i- v; T8 v2 ]6 o% e5 s" `& h/ _% j    <td nowrap align="center" class="bgc">/ ?6 ^( j% }! Y. d1 z7 j# F
  <input type="button"  value="<<" class="buttons">
' M$ D- U4 f+ Y$ Q8 {$ ]/ j+ r6 s  <input type="button"  value=">>" class="buttons">. v" W4 ^0 O+ W& {8 @9 D( c! }4 p4 l
</td>) c5 P% u* s9 ]- N, ?2 t3 H
    <td>3 ^# v2 r0 n+ F5 j! }5 r0 @+ w
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
9 i7 Q8 ~7 s5 y. \+ b) D: L7 N% d% {  </select>8 P, o( j5 i: y+ m. H9 q3 l: k. B
</td>
0 r$ w( W0 U" r! O  </tr>' @3 S/ X: K5 r# [( {9 j# e
    <tr class="bgc"> * i2 f: e% @) Y! x4 {0 l+ {
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
% A2 F2 J; a6 i7 c; z  </tr>
' ]1 U. u: C  U" R' ~</table>
, S2 v! D/ D* ?7 A</form>7 I, N  Y, D( f4 `3 r% y6 Z* ~) k5 u
<script language="javascript">
% z- q, [! o' e/ C  M//人名移动
6 M' U% {6 a* a# u/ \function move(fbox, tbox) {7 `; k5 t, o/ z' U( U; h0 m
var arrfbox = new array();
6 S. n& ?/ d5 E* S) nvar arrtbox = new array();
. |2 o  K3 Y) o# N$ ~var arrlookup = new array();& G! `$ l+ c1 a: I( `! I# h: k, M
var i;* {% G/ P* D& s. J8 \
for (i = 0; i < tbox.options.length; i++) {% }0 e! F6 v; n( b
arrlookup[tbox.options.text] = tbox.options.value;9 [0 h9 I# n+ N3 ~8 @9 r
arrtbox = tbox.options.text;
1 |  M& t4 U- p/ w+ }9 R% Q! L( B3 W}4 S) m' \/ }- C0 A+ v' S; R
var flength = 0;
& _) l7 Z, P2 E2 ^var tlength = arrtbox.length;
& G; L' ?/ ~1 N% `* k$ f' g5 D0 p1 yfor(i = 0; i < fbox.options.length; i++) {
6 p3 C3 V% J1 b* x# ^, Y1 d. r$ darrlookup[fbox.options.text] = fbox.options.value;
4 [3 t( V9 D$ t4 d/ ?4 Z% Iif (fbox.options.selected && fbox.options.value != "") {
; q( }6 a- M8 `' ]7 X! Larrtbox[tlength] = fbox.options.text;' o: N% I4 g2 V. d5 ]' m
tlength++;
0 N9 [0 ~7 P5 l* Q4 S, d; u}
7 p1 t2 x  S, e% }2 ielse {
! K" D$ i+ ^1 |  _arrfbox[flength] = fbox.options.text;
+ O, I5 x5 r4 P1 |* p  y& Kflength++;: L+ w- e1 S* B  }% N; u7 _
   }# J& P+ d  J# R$ \1 o. G6 Q5 x8 \
}
# R! \2 r5 f- M5 Z: j4 D2 Q6 jarrfbox.sort();
7 ?* Z' o2 Y! F  B! \arrtbox.sort();
) g: p( b+ Y4 n5 N% `* K, f: D' o, G8 P) d& {# U
fbox.length = 0;
/ C7 }8 k2 s# Ttbox.length = 0;9 N/ O. l# B/ W% L6 k  T
var c;* Y1 E# t( e2 m/ Z3 Q! R
for(c = 0; c < arrfbox.length; c++) {
+ f) p+ F  e0 R8 K! \. F' Vvar no = new option();: @3 \! s( e3 V
no.value = arrlookup[arrfbox[c]];
! P5 @; [3 E* C5 z* y" A$ v% s! ?no.text = arrfbox[c];) r, X: Z+ e- L; ^: E* J
fbox[c] = no;
' _; p( U# B6 F- o8 k1 \' Q+ J9 ~}
/ Y" w5 H3 a$ |/ f& P0 E* k& S- [for(c = 0; c < arrtbox.length; c++) {
" B9 d$ R2 C- b  B" j2 i/ Nvar no = new option();2 T. k- E" P- ~6 L5 Z
no.value = arrlookup[arrtbox[c]];9 T# J' `0 a' A6 {" @9 v$ \/ z
no.text = arrtbox[c];4 C. [& J, D9 S
tbox[c] = no;
* m- v4 c  [0 N, W- S: p0 d   }  F) ?1 X( S5 K1 J- X/ O& E. L
}
8 l, }' l8 b- M</script>' c; P3 e( ^6 f3 p* m1 q
</body>4 G' M* [" F5 i0 r  y. N

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