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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"% G5 _2 `4 C* l, l- f* i
         c pageencoding="gb2312"
9 Z3 J& D4 D0 J* J- i" S%>
6 D. o( o8 X/ I/ G  U  E2 |<style>1 j1 B: F0 L  n- b4 z2 K% {* s" b
.f9{ font-size:9pt; }
( Y, O) Z5 O% }# A5 E% v: E.bgc{ background-color:#aecaf9; color: #0033ff }
4 |! j( y8 G/ c9 E.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
$ ^/ @$ l; `  [- V) M" O( m7 e  border-bottom: solid 1px #4e7dc1;% \5 s" x7 e* |% _. S0 Q
  border-left: solid 1px #aecaf9;
/ E: J' \6 Q$ A0 @+ ^1 t  border-right: solid 1px #5679bd;
/ ~4 R. w. X$ g# h5 f, Z/ Z+ ]  padding:1px;
0 Q& C0 R/ ?" m2 [  margin:0px;}
3 G% h6 g+ `4 L</style>
5 l+ b/ d) X, y8 {8 U9 S<script language="javascript">
& T/ Z2 y8 O" T5 N2 V7 Y<!--; V6 R8 T1 ~1 M( |. T/ c
function rv()# R5 U/ t2 @/ @" i: d
{, }  G- t) A: k- H" B) J
  var val="";" d. e1 w+ G. J( F, q' v2 S- i/ f' g
  for(i=0;i<combo_box.list2.length;i++){* ^& j- d8 i5 B. G1 e) r) U
   val+=","+combo_box.list2.value;3 e- o+ e4 F/ P2 i$ e
  }6 b; U7 \+ Q1 [1 e8 A$ l5 j6 Z
  if(val.charat(0)==","){4 S9 w) U: H8 T7 m' B
   val=val.substr(1,val.length);
- N  n9 X$ \1 u! G# ?) n$ n  }" q$ L" s" N' x: R, d& Z
  opener.form1.frecname.value=val;9 @. G; W' a, J( _' Q: u
  self.close();
. b% {  o( ?% f9 n! F}6 h+ ?9 U6 _9 H) d$ |8 o
//-->
3 G: R( h8 v1 _0 Z  a% l6 ~& R8 F</script>
' C% t* S/ A8 s) b<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">8 X4 N7 t# l+ X" A1 _
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />5 s! A. {! l9 m" B  k
<%
! N0 o( A  i& I8 Z% i; K  cdatasource ds=new cdatasource();  //数据联结bean实例
7 w* O' c2 S0 ?; E  java.sql.connection conn=ds.getconnection();1 J& s6 m& W- a4 _' Y: z
  java.sql.statement stmt=null;
5 w+ h4 T# G( X  R! G  java.sql.resultset rs=null;) U3 j( G2 z: O( }6 N4 T& }
  cdatacheck dc=new cdatacheck();
: h% p" A1 x  t. O4 V& }2 d%>
9 s" ]& O# M; N6 i- S6 y<%
; \( M: B8 j0 w" f1 F. Ystring 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";
+ w/ D  ~4 E$ O8 F6 j9 S8 nstmt=conn.createstatement();  N/ T3 E# L7 B; W
rs=stmt.executequery(sqlu);6 [2 w/ u7 q# K; F5 v( z9 K# D
%>
0 T( u9 i' j# F6 i% y5 O$ P<script language='javascript'>
& P* o/ X4 `0 F, c& U% `arr = new array();; J' [* J/ k% ?; Q9 r
<%  int temp=0;3 X- F$ K8 P  X: p8 w& s
while(rs.next())! h. t6 B) {% E: y
{
9 Q3 M7 l0 S( y8 G* J. e8 ]%>
& A5 M6 f3 n1 b" A- Q; \$ Garr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");( L3 ]$ \5 j) D7 h4 S* }
<%
% Y! k! o! k  o, m8 ?temp = temp + 1;9 v+ Y+ A) e+ F7 J9 z
}  j- I: o8 D6 V. u6 C* h
%>, R0 j1 S+ I0 D+ e
temp=<%=temp%>;
2 n( b0 ]9 r9 pfunction changelocation(id){ 6 u6 a" @" q2 i9 j( F* ^
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 + U, w9 \# x) C
var i = 0;
6 P5 `. {8 [" t8 D, x5 |document.combo_box.city.options[0]=new option('-------','');
4 d5 Y2 `3 _/ g" @% U: _3 c+ ~+ s9 Jfor(i=0;i<temp;i++){
! R+ _3 x1 P* U0 Z- m; b# g7 Uif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] . c) }% A5 c- K' V) T; n) i3 t0 e
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
; L7 H- `: w9 I  F$ b6 J; }} - S8 n% K0 z- _1 \
}
- N; C5 n/ r, |5 h; R( }4 B} : I) |( C  z+ o# p
</script>
) l: @. y) |+ b5 w
% D5 w  B3 m4 ~" q/ k7 e<form name="combo_box">( M7 }, j4 G1 Q
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">- K- k0 q  ^' g8 M! G
  <tr height="24">
! p6 B- t) y3 p/ D2 X# \3 S  N    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>' x$ p" E. {4 J' y2 {
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>: z7 g3 S* t8 [% O; D2 l0 m
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>8 p: X  K' V; `8 ?$ ]7 R! N
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
  `% a; X1 v: C9 L8 Q3 J7 X& p  </tr>
  d3 n) b5 Z- Z3 D" ]  <tr>
' d5 X0 X) ^4 x% v& d: K( S    <td>
3 f# p( d  G( K& s; f7 f2 P; B& l  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">0 J! `9 T" K4 h
  <option value="0">请选择部门 ---></option>( j* v  c. W/ c/ k( m
<%) ]5 {+ B8 d( X8 c$ A- h
    string sqld="select * from tdept";
5 ]' Q( t0 I( z" G8 |, N8 Zstmt=conn.createstatement();
; _5 o  \3 J  K& p4 Xrs=stmt.executequery(sqld);- l2 V  x# B+ ^; L$ D
while(rs.next()). @# w9 X  }" M: l7 ]
{
& ^2 R9 M1 i: M8 S5 P+ t%>
, R, O9 y/ z% k( z: s7 o% x  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>* H: H* `$ Y2 ]" I" q7 j
<%7 [0 U2 K! @$ V1 ^4 S: x
}$ d5 y1 n! J' D: u: i
%>
5 h) V( N3 @; }3 ~  </select>
0 A% _! ^. O1 G4 d2 _8 Q' x</td>$ o; L1 W* D# x% u2 k8 f4 j
    <td>
4 G2 a1 v" _0 j6 b  <select multiple id=city style="width:150;height:200" class="bgc">
$ `2 s$ H' Q* I+ q  </select>, b+ E6 v" H* {" k* i( q
</td>, \8 K, e0 q/ N/ `4 c  l2 q3 H
    <td nowrap align="center" class="bgc">
/ ~6 e' w4 J: M% q  <input type="button"  value="<<" class="buttons">; d' r0 D( `4 k4 f( N* L1 r4 |: Q
  <input type="button"  value=">>" class="buttons">1 x! H, {- R. |6 ~
</td>
5 Z+ A& k2 m  v8 A/ r    <td>6 o" }- ], Y- H8 T6 M9 _- P# J
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
, }, d9 F8 `" t  </select>
1 y+ v6 w8 Z! k- X$ t% ~</td>
! J7 Y* P  b' n! K6 N  </tr>7 k" y: z& `2 V
    <tr class="bgc"> $ p0 i" _: g  e2 ^7 O( c
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>8 f. A( L7 ]9 e2 i0 @+ Y
  </tr>
. b1 T; w7 O# Q/ u  x. E; [( j, q</table>
, b3 ]4 D; I, c5 @4 f) H5 f</form>3 ]3 s) @( g: k
<script language="javascript">
1 M+ `4 x8 `/ [5 C//人名移动
7 ~% z) w6 y. }- F/ u6 ?0 wfunction move(fbox, tbox) {
3 o9 A7 [0 J8 w: @" Kvar arrfbox = new array();
' Q6 F8 D% Q# ~% g9 Rvar arrtbox = new array();
% {, b( Q% {9 ^; qvar arrlookup = new array();
6 m6 O" y! ~6 ?5 n' r) l4 o6 b' ~var i;
) f+ J) g! b3 {; c) |4 Hfor (i = 0; i < tbox.options.length; i++) {
7 r) u3 [& s( g% `: m: j, s+ e+ _arrlookup[tbox.options.text] = tbox.options.value;5 F- K+ i' I  M' j8 c5 r
arrtbox = tbox.options.text;. r% a! W' n; p! v
}
+ |8 t) g5 q3 ]var flength = 0;
+ H4 r& y8 y6 Z* A3 e, X% o( s  [var tlength = arrtbox.length;
! D4 }: `' s8 \) w3 S, B6 Qfor(i = 0; i < fbox.options.length; i++) {
* h( Q* U: l' S7 ^/ w6 n: p# oarrlookup[fbox.options.text] = fbox.options.value;( Q3 @0 d1 b2 {. y) ~( i' Q- I. L
if (fbox.options.selected && fbox.options.value != "") {! h/ U; N5 j5 ?8 |
arrtbox[tlength] = fbox.options.text;. l  a6 \7 X! P8 N* [
tlength++;
1 H/ p2 @& a5 s( N6 L}0 T6 ~. A0 }& y
else {
  l; i4 d3 U6 E6 R- O+ J) sarrfbox[flength] = fbox.options.text;
$ r" f8 z9 @' h$ x5 `/ w  |flength++;
2 ?( x6 E0 G6 F5 i1 c   }- B3 g0 L. {$ B& b, l2 z. D
}; w- G1 E7 i5 |" T
arrfbox.sort();
+ Q& N+ @7 P) R3 d, X" Earrtbox.sort();
9 Z3 v4 N; ]$ X3 |1 g0 P$ C5 S) Z; c& n" R+ |" R6 B  v, c
fbox.length = 0;+ [( I" `- a6 W5 s' A( t
tbox.length = 0;5 K- v1 f) S2 Z. \$ A! v4 n/ O
var c;
: Y# d# {9 I( l3 x+ E" Ofor(c = 0; c < arrfbox.length; c++) {
0 [( q, F3 U/ z* P% @7 Vvar no = new option();
% k( I5 a6 a5 o( tno.value = arrlookup[arrfbox[c]];
3 {) v4 Y( S0 L& h) vno.text = arrfbox[c];
/ }2 F" \, |+ W$ gfbox[c] = no;
# h- K# ^$ }0 `' T7 f}1 r/ }+ M, ~; |
for(c = 0; c < arrtbox.length; c++) {0 }6 m0 m# h/ t7 ]
var no = new option();, ~+ `. g) e% ~
no.value = arrlookup[arrtbox[c]];
( x3 k! _6 @! h+ I& E! f; Ino.text = arrtbox[c];1 K' D6 Y* r- O  S, [0 C, e
tbox[c] = no;
  g, w+ _$ P, y9 T: a   }
2 X$ k0 e. |" E9 X) Y2 Z5 u}4 {) P! N/ w3 Y% a* g/ K
</script>
7 F# q" Q" M6 ]3 G9 ^$ w</body>' t; F7 b8 s: A3 x$ W; B

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