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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
& P1 c" {% |- l0 H: z         c pageencoding="gb2312"
3 a" w8 W! {4 ^) v+ y6 g- @%>
% r& o% l7 Y5 \$ |. m<style>
9 q, E5 h2 \: t) X! u.f9{ font-size:9pt; }
" z% T5 c- Y( x3 ~6 a9 K.bgc{ background-color:#aecaf9; color: #0033ff }
0 V- n/ E& w3 }# A" c" T# x.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;% |+ P( E2 C' W* m/ W
  border-bottom: solid 1px #4e7dc1;" l% _# y0 x1 U# J' C5 Z/ N
  border-left: solid 1px #aecaf9;) z+ Z* X# _8 ]/ T; p5 }
  border-right: solid 1px #5679bd;
7 i) Y& c  B; T  padding:1px;
, @: W: Q  C* {' v0 |  margin:0px;}0 D6 F8 ?8 u% P/ Y! d0 C0 I- Z3 c
</style>5 X. J$ O, N2 {" j. n' T" y9 v! z
<script language="javascript">1 H# P/ ]" O7 L2 O
<!--
6 B1 h+ f' v7 E+ e6 S- \6 Wfunction rv()/ k$ S6 C- f( v+ V! b; e9 _2 P& n
{2 q" F3 e- E! P. c  o$ b
  var val="";$ l! ^- f8 h" {5 j! i9 R
  for(i=0;i<combo_box.list2.length;i++){: L0 A1 O0 Q9 _$ L' m. U  J; ^
   val+=","+combo_box.list2.value;& M$ m$ I8 G1 L; Q. r
  }
  I7 _: e" |" U0 M  if(val.charat(0)==","){( a6 O- s: S- C6 Z( D/ V
   val=val.substr(1,val.length);
. t- I  j' T6 c+ {* h' v( V! I9 j9 ^  }
" _, y6 _1 J8 V- T, }# _( \  opener.form1.frecname.value=val;
( e4 h# P0 ]; f' C" g) H  self.close();
, |: C1 H( x0 J}
+ ~, {  g1 q5 O4 D) q% ]: Y, Y0 t/ q//-->. x  s, |5 q' U4 h4 @
</script>! K8 d, l" K2 s
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">  W% Z9 m2 @/ b8 `1 |/ G3 D
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />! b9 i1 a/ w- I! h+ W
<%" p) \/ T! a2 p& X, `$ p# E
  cdatasource ds=new cdatasource();  //数据联结bean实例
; G( u3 Y3 L; l  java.sql.connection conn=ds.getconnection();) P+ J( D, Z  B: z5 j  S3 h3 o
  java.sql.statement stmt=null;: _2 @& i  ]' s4 [9 I$ [; b! r! s
  java.sql.resultset rs=null;
5 F; X) T% d: Z0 [! [4 a2 n$ t3 s5 X  cdatacheck dc=new cdatacheck();
, v9 ~. V+ l! O( k%>" o9 V5 y5 [. u
<%* P$ q# }  i8 n) y; ?6 n; Z
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";+ K9 z3 q6 M  Q/ z3 e9 H5 p5 i
stmt=conn.createstatement();
' G% E5 f8 L# M% Q6 wrs=stmt.executequery(sqlu);
: p( b4 O2 g) I%>/ A. p; K: R1 r/ Y$ i/ e* E* e2 f# y
<script language='javascript'>$ ^1 S8 p8 A, B
arr = new array();* H2 }% w* w2 {9 X
<%  int temp=0;2 N$ g/ N6 A. y- m; R; y
while(rs.next())/ y" w+ k: b- O# d9 z
{# L+ ?% k- J( Q
%>
$ z& I5 P4 B% A! W8 Aarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
- T! x8 X' B- M: S<%
9 J  p# {1 w2 N- p+ c% A- xtemp = temp + 1;* j2 h& |& \" B! }  N9 Z
}
3 S/ d: c, T! ?+ G$ ~/ t. N# O%>7 p& v8 D2 D3 `) w9 _
temp=<%=temp%>;) P& j: T& d7 n+ d; F" w) {
function changelocation(id){
1 c2 N1 p7 E4 r9 H3 {document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 & y' y8 `" ~5 b% S9 P$ h6 {  V$ @
var i = 0; 5 b) b5 \/ R6 ]. H, C% Y9 y
document.combo_box.city.options[0]=new option('-------',''); ' u+ n+ o9 E+ d  |7 ~3 ?
for(i=0;i<temp;i++){ ' R$ Z  J* e6 v5 p$ p4 A& [
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] ; B+ e3 |- ^* O
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
  `% ]' z- W/ D}
) b- c$ B7 k) a4 l/ H6 U}
9 Q) p* m: Y' v9 k. Q} - M% W  L" U7 @) z
</script>: ^# t9 s. S( r
$ L) j3 z% v" U4 G/ x7 |
<form name="combo_box">$ P- W, b  f3 q/ O4 d! G
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
. n0 J' v# Y" ]1 }: j3 b& U) `  <tr height="24">
% f! |* d3 ?; P4 w/ N* D    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
$ _% a, \% `$ @1 l* m$ _5 l    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
2 ]' l+ k- W1 p2 R    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
4 `0 M+ Y+ O5 {: W' K0 Z" L    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
/ l4 ~" a1 v; o  </tr>) F8 S  C0 ^. M5 Y5 x
  <tr>
4 ?- U: g- k) N5 ^; X    <td>1 y3 y) h- i' c: N9 M0 p
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
( B3 j, E9 F, [2 b% s  <option value="0">请选择部门 ---></option>
7 C: u1 T* _, ~9 m- F<%; x8 k+ A8 l4 @" s9 u6 }: f
    string sqld="select * from tdept";8 |  O) X& ^7 N; M% Y4 J; ]
stmt=conn.createstatement();
: C% ?/ k- Z+ h5 x( \7 S" Brs=stmt.executequery(sqld);: U7 k( B) p" @0 l% X* `% J4 \
while(rs.next())
) M) K7 b+ f% H) _; q- D: O{2 S1 f" p0 D3 e& ]8 w' ~
%>9 J8 o4 _# z2 M5 q
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
+ _) z- o, @2 z+ O7 R1 {: o<%: {6 e1 K6 P0 ]  s3 {. g
}
. y8 |6 r( G. E$ D2 @5 O( a3 Q%> . P3 F0 @+ }, d
  </select>
% u$ F$ m$ C- z3 j</td>$ x4 j( d5 j1 @
    <td>
2 [! M- e: C2 x- q, A  u  <select multiple id=city style="width:150;height:200" class="bgc">
9 {' B1 U- [% k0 f- \  </select>
; x5 @$ a: O; O+ R. w2 g</td>& S5 u4 h4 K6 {2 P4 i$ ]7 A( B0 a
    <td nowrap align="center" class="bgc">' g, u8 V2 t: b6 T, S; s
  <input type="button"  value="<<" class="buttons">8 [, x5 F* c0 i5 D/ u
  <input type="button"  value=">>" class="buttons">
" y" H4 p/ i- \# F</td>. b. I& Q; E4 @; h
    <td>
# a; u* H8 V' ^  c7 b  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">: A+ n7 t( {4 k4 \4 y/ h. a
  </select>
7 q! v  W1 z6 g% l& e</td>
  L: a' _- c( l. _: ~& s  </tr>
! S! `: ~9 f2 n4 {    <tr class="bgc"> # m- p" ?6 t6 m8 e
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>8 ?3 I6 ?, p* k5 V2 N
  </tr>5 _) D% k9 U) p; X! i' d
</table>" P2 I5 r9 k) I+ u( X" Q
</form>  N3 D% b. X8 I- n
<script language="javascript">
( [' U3 T8 n" e) ~) m+ X) M//人名移动0 J( y+ U- z2 q0 Y+ Y! m
function move(fbox, tbox) {
' @5 O6 f2 F7 Z9 e) Gvar arrfbox = new array();. j, V) k+ a+ o/ E: t
var arrtbox = new array();
" V, A+ y' [# ^/ T3 x/ u: d3 Qvar arrlookup = new array();* P3 M/ i! S2 k6 S
var i;: U1 H% Z( N5 S. B' Q* C; R0 ?
for (i = 0; i < tbox.options.length; i++) {
; X- d/ @1 z& x* [6 W- n0 T$ qarrlookup[tbox.options.text] = tbox.options.value;
+ g# z7 \3 [6 @! P( Darrtbox = tbox.options.text;
0 O# L; V! H& W  d}
  P% o* S; y7 p! Z6 ^9 f9 G& fvar flength = 0;
* k" c; k+ h! O' n/ r* O2 G8 Q: wvar tlength = arrtbox.length;  {* ~, j% L' T+ x! c) I
for(i = 0; i < fbox.options.length; i++) {
+ z/ c" |2 B) \8 {* [' u4 m" warrlookup[fbox.options.text] = fbox.options.value;
" v) w" v7 C7 \if (fbox.options.selected && fbox.options.value != "") {
  b+ Z7 ?+ _7 ^: T# qarrtbox[tlength] = fbox.options.text;* [5 ?8 Z. g8 I, n: T
tlength++;5 d- W: q: y+ i3 s3 z" J' i
}
$ y% d  c! c/ Relse {
3 z# M# D" D& v6 x# ~7 larrfbox[flength] = fbox.options.text;. b" C; m$ f7 v0 c1 U
flength++;
  [" o) r% ]' I7 j; P/ S2 @   }
" C8 B# D5 j- r7 a( U0 w}- Q# Y( w& h) S( A* [# Z6 m
arrfbox.sort();
2 L. l3 s, ]) Y1 z& t0 T  Yarrtbox.sort();, o# A( K; m8 G9 p' @, K

$ P* Y+ Y  a; ]8 d8 W+ yfbox.length = 0;' X+ q& V0 x$ r! G; B
tbox.length = 0;" @8 w) }. `) M" W; m8 @& D
var c;
9 m6 e$ s* T, `7 [/ @2 Ifor(c = 0; c < arrfbox.length; c++) {
' z8 r9 v) N* w8 b$ D. n- lvar no = new option();7 G( Z' I- b# Y! v- z
no.value = arrlookup[arrfbox[c]];
0 G, f" y' V7 [" s7 f4 _, Ono.text = arrfbox[c];$ L3 K% }' I  s
fbox[c] = no;
  r: ^; I' ^/ g9 N3 Q7 p' t: U}
, t9 v4 o3 ?  L9 hfor(c = 0; c < arrtbox.length; c++) {2 ~# E( ?0 w4 v! x, m, A7 k& w% g
var no = new option();
6 @3 b2 P/ J% eno.value = arrlookup[arrtbox[c]];
, {7 D% {3 Q4 {. Y# lno.text = arrtbox[c];2 S, j+ q" Y' e. [1 s
tbox[c] = no;
4 ^8 |7 Y: ~) \4 _& a9 ?- h: e   }* t% K. X# L/ i# I. b! P
}
6 D. {0 w: c  p0 _/ I</script>% z- s7 Q3 [3 ?* [3 C" n
</body>( j5 W" {1 j" Z) k$ w; U" C

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