返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
4 z) D( T9 i; H! b: g) I8 _         c pageencoding="gb2312"
8 A0 x; l6 `7 D  F9 ]%># [2 L) Q4 l+ E1 }0 l. }6 p% f
<style>
7 M0 M5 _0 H9 V8 N- u% t& z: |3 Q.f9{ font-size:9pt; }; P* P9 ~2 y; p
.bgc{ background-color:#aecaf9; color: #0033ff }0 B2 ^$ a8 u. u- S0 l: z, V
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
" ]3 K* X& \8 K9 [& M2 L  border-bottom: solid 1px #4e7dc1;
5 q0 _$ g+ [' a, c2 U  border-left: solid 1px #aecaf9;$ C! }$ R$ _; O+ q3 T6 Y
  border-right: solid 1px #5679bd;9 I  W% W5 z3 q# }( J  n6 @
  padding:1px;
8 x, ~/ D% W2 H4 e6 W  c2 m$ g* O  margin:0px;}
4 _2 f' |, ]  F3 U" T  d</style>
; k* R' g' T; ~<script language="javascript">% L( |3 y' s8 u5 }! R
<!--
- ~$ I+ e# W# y  S# `  w: Afunction rv()
/ t5 Y, i: ^/ v0 K{+ f& f% @- @& i
  var val="";
5 _) F! n6 H2 [3 Q! {1 m; u$ h  for(i=0;i<combo_box.list2.length;i++){* P* z( ?/ K  }) z& D" [
   val+=","+combo_box.list2.value;, z8 K4 s# z& W! D0 {
  }. B. R* q3 Y1 G& E$ N
  if(val.charat(0)==","){6 S3 j1 O" k: d) q% S3 X
   val=val.substr(1,val.length);& |) F  X6 m+ o9 x) t) Z% z8 L9 {* S
  }- d* P9 n; L# X5 v* S/ p
  opener.form1.frecname.value=val;
  n$ z6 x1 Y- j& \# j3 C  self.close();3 z6 y4 o! w2 C* ^; l! _, n
}
! M2 {1 c, ~' Q* ?' M" [, u- {  y- X//-->
" m' n  W4 R9 O</script>% F( V! L; Y: q; h$ u; P
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
7 y2 j' w) R' |<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
# Q* A  [, l4 Z+ \" ?" a- v: G<%
6 n, G& c, g$ s; S8 R6 P9 H  cdatasource ds=new cdatasource();  //数据联结bean实例
7 k1 o$ z* i* E% x! d6 u  java.sql.connection conn=ds.getconnection();1 F$ f8 p3 u" L% R; n
  java.sql.statement stmt=null;: b( m1 z! D1 i+ z
  java.sql.resultset rs=null;
, P+ I- m) _9 j. b& N" E  cdatacheck dc=new cdatacheck();. g' P2 Q3 ?0 T1 U$ O3 R
%>% o6 h1 h9 x- Z* r9 z, F
<%
2 `/ |* J5 q$ w4 p0 u# ^+ Wstring 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";
4 j4 y, c! o+ n8 f! O' Xstmt=conn.createstatement();2 [8 S# x) C% r' t  i; S7 j) g
rs=stmt.executequery(sqlu);: ~/ i! G6 H; v0 f  L9 M) r$ p
%>
& x4 [2 t$ k( n" y<script language='javascript'>& D' _  l! a. a5 l; d# K
arr = new array();
: ~8 Q7 n% M  G+ s3 s<%  int temp=0;
9 U. y* e7 i0 [( J% hwhile(rs.next())
7 O7 H* {; u: n  k" g2 p9 c% G{7 g( @+ }/ |& J; ~0 Q: \
%>
/ ]6 [1 A5 X/ E0 a6 p) Oarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");& {$ _. l- d: `
<%
* \# ^- ~  V8 a+ }temp = temp + 1;. X- P; [( M& P$ I5 V
}5 @" d$ D# [+ V) d8 y( D
%>
2 E, ~# a* N$ C" k5 d7 Xtemp=<%=temp%>;
2 L. a8 B0 o. N! u) lfunction changelocation(id){ 9 o! b1 t# u" X2 P, U
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
6 E- z9 ^+ v8 w" i( f! s' L& \var i = 0;
4 c8 Z9 ?6 D5 k  l* Adocument.combo_box.city.options[0]=new option('-------',''); ) k  A/ a( E9 Z0 ~
for(i=0;i<temp;i++){
9 q  S* M4 ]5 M$ r5 aif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] $ I: A7 s+ Q5 a
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
/ O! C# ^3 N5 H* ^} 4 G5 L  _( n& ]; }! F7 P
}
$ n9 l* I7 C4 @( M}
. I1 s# }) j9 f# S# {4 g$ g3 a5 t</script>. n, U, W' h8 l; d

+ _. L4 N" |( p: ^* }3 _, g<form name="combo_box">& P& h+ o& W( L8 b/ L8 ]" a) n$ e
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">/ r6 L4 e# j, {# g) \4 B) H
  <tr height="24">
, y. m' `8 D9 V! o- e4 z0 c    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>4 C$ w" G4 P+ c0 ^+ [6 ?0 _% ]4 V
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
/ r, m. X( @. t; f; @9 U: v% n    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>  w& M# q( G* r) D% B
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
4 S8 ^6 |, _* r: _( T/ O) R; }. [  </tr>* T# d- u# D) R
  <tr> 6 b0 H1 x2 s" Q2 X' N
    <td>) G/ @( L: p+ r
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
' P3 k8 G: |: B  N8 z  <option value="0">请选择部门 ---></option>
' r8 D8 H2 d% G2 x, @5 W3 l<%, @- l; p( z* H2 `8 A" ?1 u
    string sqld="select * from tdept";" ^3 {0 Z  Y/ o9 W  R
stmt=conn.createstatement();
: B. O% l3 S+ R7 r; d: Crs=stmt.executequery(sqld);2 _. a- u( _, c9 f& \) Y, a1 g
while(rs.next())
: c9 o! V9 W, f) E( S' V{' g' E- ]6 |2 J6 e# o6 x# C
%>
1 D! h5 r' o. [7 E2 U  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
5 k! }# O  j$ q5 p, d' o' l<%, J0 h6 T& \0 E# k4 H, F$ H
}
6 I' H# W* K: j1 J%> / k0 `2 H3 l4 R( Z% a
  </select>
: a2 z4 r1 E. E% t7 g8 Y2 p7 P7 Q7 m</td>
) ?* d& E4 `& D. _    <td>
. g, H; @& C. Q: V  <select multiple id=city style="width:150;height:200" class="bgc">' @1 y: U3 |3 V$ \6 o
  </select>
4 u, S' c8 V  _. Z/ L  P* b</td>2 T$ a3 U. o( D5 w
    <td nowrap align="center" class="bgc">" _( I! P/ T$ x! x
  <input type="button"  value="<<" class="buttons">
0 K' _0 e) F7 R0 @5 C/ f4 C/ j  <input type="button"  value=">>" class="buttons">7 g0 X% T6 ~; l# y) p* i# ?+ t& h
</td>7 L' B7 b' ^" F( x! Z2 t7 d
    <td>' n0 n( x& `/ [# A+ v% r
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">; b3 h: X$ n( F% w# s" l2 U
  </select>' x6 \  ^: x4 M% ~3 Q8 s( o
</td>
; \! K  a" `8 e" f  </tr>
4 j9 f4 ^* O: p2 y6 ~    <tr class="bgc"> ! Z' o! B, [# M1 r* O! p8 V
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
3 H8 b6 s9 E; x( [, D  </tr>
" a5 S* ^& b, y! y. Z  E! h</table>
* a8 ]  o" {2 Q8 ]</form>6 m  X6 c6 ^& M
<script language="javascript">
9 q" e8 X. Y9 @( X//人名移动
* p: o/ o8 R7 t# P9 w  Gfunction move(fbox, tbox) {2 l- M+ |. a' s# l7 ~8 x) n$ S
var arrfbox = new array();3 {* o- X0 U( r0 I5 x/ |+ D' P
var arrtbox = new array();! m7 u: S  V, L" S
var arrlookup = new array();* p; @  I$ x2 y# [
var i;
4 n4 l# [- b/ h- t, e! W3 Xfor (i = 0; i < tbox.options.length; i++) {
4 V/ y7 Z3 h; ]0 _arrlookup[tbox.options.text] = tbox.options.value;
- R# l2 }1 v& K! Sarrtbox = tbox.options.text;, h9 [( D& E* B2 p: i' z
}6 r3 K# d- @  v+ Z7 c
var flength = 0;* f6 r6 j: l9 R2 _
var tlength = arrtbox.length;
4 |" m, u( ~6 B) h2 I) hfor(i = 0; i < fbox.options.length; i++) {
# h+ _4 e- u7 |arrlookup[fbox.options.text] = fbox.options.value;# `; s9 m1 I" j
if (fbox.options.selected && fbox.options.value != "") {
. A* Y* V: Q& ~* }- x, ]arrtbox[tlength] = fbox.options.text;. O3 {$ s/ g7 E4 Q4 T
tlength++;
$ j# L; L8 Y. ?) B2 J' v* u3 ^}
" e4 i' \6 K8 }" E& F4 {5 r' lelse {
0 t. R' v: v2 M8 n5 w, Farrfbox[flength] = fbox.options.text;
9 s: [  M, E$ h8 B2 Mflength++;
/ b% v6 J: l3 m% R$ \( Y& ?: S8 Y   }
/ I# L$ Y+ u% M  {8 d' {, y4 `}
) t  W! d7 ~8 O. Yarrfbox.sort();
4 \) M5 Q0 M% U( X( y* parrtbox.sort();) ]2 ?" j7 M  M( W- H6 Z+ H

' T, Z: Y5 F' @0 X$ m1 Efbox.length = 0;( Y1 s! z' {1 K7 Z7 F
tbox.length = 0;. Q3 t+ Q; d5 @0 v: L! c* |
var c;* ?  Q. x7 v; F
for(c = 0; c < arrfbox.length; c++) {$ X- Y% E, W  |# Y
var no = new option();% \$ [6 v) i/ q+ g% V
no.value = arrlookup[arrfbox[c]];' @2 d( f2 _# F) ]$ O
no.text = arrfbox[c];, @$ v( K) |* I' o- ]
fbox[c] = no;
% u7 R, ]4 j; I/ v7 ~, a2 ?/ A}# u8 K- \. Z% F: S- }: q) z
for(c = 0; c < arrtbox.length; c++) {$ P, ?) n- ^: H9 [4 p: z) ^! u
var no = new option();
, N# ?/ S' [* z! k: N7 o, N  _. Dno.value = arrlookup[arrtbox[c]];4 I6 K  W& ^. b! l' b4 d" U5 D" Y
no.text = arrtbox[c];8 s" Q* D- p. q/ E. `; j7 F5 N8 x
tbox[c] = no;( {: D0 e/ T! v1 x
   }- i# r, z* A* ~3 u2 [: S3 n
}
! d) K$ c) C2 W- P3 Q7 W</script>
# K5 y3 ]. Q+ t</body>6 P8 J9 D  a: i4 c3 c6 C

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