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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
" @1 F( u; h5 F         c pageencoding="gb2312"
0 o' J: e- B# A" a( f; D; {1 k%>7 ?( d- g3 n5 ]2 A
<style>
# Y- z' n1 Y8 G6 d: f) b1 \: E; u& y.f9{ font-size:9pt; }
3 U7 x# w1 j! e3 D" ~1 N.bgc{ background-color:#aecaf9; color: #0033ff }6 Q) |# `1 g, ~1 x9 E1 H( d
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
5 }' H: I$ i8 D' v5 T5 [) m0 T2 L9 y  border-bottom: solid 1px #4e7dc1;
7 T' q+ Z/ m1 X+ c% K1 H3 `  border-left: solid 1px #aecaf9;5 J' D+ X$ s+ E9 R8 l
  border-right: solid 1px #5679bd;3 u* h* Q  [7 W0 c  `
  padding:1px;/ _; S! V* h) x7 |' P& O6 ?
  margin:0px;}
* K+ u9 v+ r% t2 Z1 _% s  C</style>
3 X% q' a8 u. O  w" @  O, y' V. y! p<script language="javascript">
1 T: d2 i) s2 L0 O* k  S5 Z- ~<!--
% I& l5 l; z% a. n2 j- rfunction rv()8 i% ^0 S% W% |1 b
{7 v8 p: c9 c5 y% m3 ^' v! d; ~
  var val="";6 ^% F% ?: D$ Q* [  E6 m. i0 f* H
  for(i=0;i<combo_box.list2.length;i++){
! d- L3 H3 z0 k  z% p   val+=","+combo_box.list2.value;$ V; T+ H( w( z! _
  }" U) e  Z2 @0 E( m
  if(val.charat(0)==","){. B5 I+ f+ t- t. M3 O
   val=val.substr(1,val.length);) ^9 T, c+ \( p
  }
! L$ E+ Z* h" b' M  opener.form1.frecname.value=val;
5 |+ O, X/ V" t( t4 f; d- `  self.close();( @; [9 O5 m" Y9 w, K8 ^7 \
}2 N- p' t5 f0 y1 t
//-->) a* ]9 C% x9 a" o6 Y
</script>
- v$ W; Z" t0 ?<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
, ~8 o9 v. m$ s& ~<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />% L2 F9 z! n! s  n7 I9 K
<%# ]' C2 [' l# ]; B; @/ S+ _2 R' i6 y& y
  cdatasource ds=new cdatasource();  //数据联结bean实例
* f9 P5 K7 |5 N  Q- t5 c  java.sql.connection conn=ds.getconnection();
+ C) |9 Z$ L( ^0 b: G0 l5 L  t  java.sql.statement stmt=null;
; h! N* ?+ a8 [  t6 }4 S  java.sql.resultset rs=null;6 Q* p/ H$ P6 K
  cdatacheck dc=new cdatacheck();
3 h+ e1 i7 n+ N+ ~( |( r%>5 H& W, ?: y& n* _
<%' X/ A( k9 S3 Q6 W
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";; `7 |; N  U* F5 c
stmt=conn.createstatement();' D! P& P* I9 R0 e
rs=stmt.executequery(sqlu);
6 ]( w. w  A7 C' o%>
; {" x- W8 H% S. V1 X<script language='javascript'>' w" D+ U, ~) P  L1 _# W
arr = new array();3 W7 z2 ~. t2 X# Y' M& U2 {0 D
<%  int temp=0;
; I9 [# a/ y, m: l5 swhile(rs.next())
: e/ ?4 y4 w5 V{. K7 L6 U; N$ Z0 v  f% u5 I) R
%>
, e; \# l5 V+ N$ [" }" @- Sarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");3 I7 F! n! t& K
<%
+ d% f) ?2 Y7 }temp = temp + 1;
9 x% A; a0 q- y! o( P7 @  K* m}  \7 s+ |1 c% z2 O+ X- V9 N1 F
%>
) O+ H+ l3 q7 Ltemp=<%=temp%>;
' A, w+ x1 |0 Q4 `$ V* b& l3 afunction changelocation(id){ ' F8 F( f: b: v' L& B" q
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 # n9 T4 e" I5 @7 L0 J
var i = 0;
& S( ^6 j0 ]* l/ a  r" a  p$ _document.combo_box.city.options[0]=new option('-------',''); # M$ N2 a2 _- p& \
for(i=0;i<temp;i++){
0 P; L4 O4 U! Q0 R4 Vif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 2 z5 ^8 E* G0 k7 M
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
5 j4 u6 B$ q: |} , q/ h, l) J) {3 f5 l
} $ U, D1 v- j# i9 H3 w, Z; A
}
6 m7 Z) H# ~- V9 ]/ J% N' }</script>
9 P1 X, H$ B; n2 M9 m
. I3 m" o4 I& f! P<form name="combo_box">
5 C: M# _- @5 a, h/ Y  a! b. B& X<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">! o, }9 V& Z8 x$ P
  <tr height="24">$ ?0 U2 J3 O1 e: `1 w% E
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>* d- H+ W9 s( q. l: D' S
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
" n4 H; E) p4 S# D3 M! t    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>8 B. f% D2 K3 E8 N, R
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
( j" W# C9 C$ ~3 j) |( l4 g  </tr>
. ], E$ l0 k8 y4 m4 _0 V: r+ G  <tr>
3 w+ f3 t" e" b    <td>
3 K% Q9 c3 F5 A' g( M3 f  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">6 g8 x2 g! q6 M: c+ d0 |
  <option value="0">请选择部门 ---></option>
' `% Q# i$ l2 e* x! e<%, V( V, _3 _9 ]$ G4 b
    string sqld="select * from tdept";
* q, g5 L1 x: [3 \: Z) o+ l) fstmt=conn.createstatement();
" R2 E# F0 d1 @( A5 d- Trs=stmt.executequery(sqld);2 k# ?( Y: K9 E2 j' K( {
while(rs.next())4 L$ b6 W  \$ ?
{. c9 u1 c& R( {. ^% p
%>
6 O& J" v9 G8 n# B3 ?& [  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>+ V# g4 R2 O3 s' Z" k5 `
<%
0 Y' a$ ]& ]- z) n" a7 k" }# h}
& j/ a' Q( l$ q; n9 j; x%> 0 L& p# b; D) ~$ [- M7 B1 p
  </select>' ]3 p2 x! r* c, X- b
</td>
( O& g5 ^/ q9 `    <td>3 T+ d, R0 Q6 \  b6 ^1 u% N$ T
  <select multiple id=city style="width:150;height:200" class="bgc">1 P! L7 v2 v2 x6 _, L' V4 K. b) \
  </select>
+ A7 S% B, g5 Y* d; R</td>
" h! v' b6 ^5 B2 s' F' f0 }$ f1 |    <td nowrap align="center" class="bgc">
, _+ U* C& u1 {. c8 ^. r( W  <input type="button"  value="<<" class="buttons">
) _# U5 N% {0 N0 l) D  ~% X' S  <input type="button"  value=">>" class="buttons">( T* V8 D4 I! f! K- O3 R+ i7 `
</td>' h) X5 k' M* R- C7 H4 q# e
    <td>( m5 N7 l3 v1 ^! X' ]. k
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">+ o5 @+ V% p( I- {1 y" J
  </select>
8 z. {2 R7 ]  U</td>
& K) B& N5 ~) S( `  </tr>
: {) U) ?* l1 K( m+ g5 J% t    <tr class="bgc"> ( j& v9 P4 d0 d- F( S) O# X
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
6 x7 `: b" Q7 s/ K6 I0 z- T/ N  </tr>; W1 H, T/ D7 x7 @* i
</table>
  g7 G* Y5 [6 e, B4 C, x# d</form>' t9 j7 D5 t/ P6 _/ f
<script language="javascript">
; c- z( D+ C7 s0 ~3 W/ c: F//人名移动% e2 p& `: a) E8 M5 O
function move(fbox, tbox) {
$ w. A1 b% j) P8 Zvar arrfbox = new array();$ w$ Y2 V3 o7 r7 U
var arrtbox = new array();
! }( G' Z1 \& Evar arrlookup = new array();
8 b* [; l3 q) r) `" L7 xvar i;
0 |$ T" U/ T- ]. i+ Sfor (i = 0; i < tbox.options.length; i++) {
- \  X, j& Q3 Yarrlookup[tbox.options.text] = tbox.options.value;/ C- w# S4 p- _  q$ t
arrtbox = tbox.options.text;9 X/ [; F; k& e- |' ]5 d% m
}; e7 x0 v& p5 i, G! m7 P6 a+ o9 w! p
var flength = 0;
* z! P0 {1 q# T8 Nvar tlength = arrtbox.length;
1 g; p6 v% z$ {( L6 D3 v3 }0 Kfor(i = 0; i < fbox.options.length; i++) {
/ x- j: Y2 b2 L2 Carrlookup[fbox.options.text] = fbox.options.value;
2 y& x% W! q& e# x; k1 yif (fbox.options.selected && fbox.options.value != "") {* X  d1 c/ l) e. `6 n% r1 c& Q; y
arrtbox[tlength] = fbox.options.text;+ ?* ^) z, ]" L' \) H: m
tlength++;' f, p2 G1 L  F
}
" [9 `8 \6 ^4 J1 L2 ^4 aelse {
  J3 G" s6 ~2 o* n! l# H0 n- Qarrfbox[flength] = fbox.options.text;
! c% i8 s8 v! u0 X; `6 T/ Y# h3 Eflength++;* M' Y' L' A1 `9 z8 h! C
   }
+ W( {; H2 @) c6 S4 O  ^0 }0 G+ }}
( M: J# _& ^9 o: @5 C* L- xarrfbox.sort();
0 b  v* {+ [' U5 o. Uarrtbox.sort();7 Y$ a7 C% \# Z+ z& i+ S! A
, H$ D% e1 u! _4 T* N0 B
fbox.length = 0;9 {7 q0 m0 d8 q) ]; q
tbox.length = 0;. y; a8 j, y. n% z! h3 q
var c;: P1 a- E" j; O7 r$ F' [4 c+ e
for(c = 0; c < arrfbox.length; c++) {
- F( I. f" o3 @! ], \8 Y, dvar no = new option();
: n( A' r/ U. a" T$ M0 N4 wno.value = arrlookup[arrfbox[c]];
" M3 k8 l4 U3 N% v# }no.text = arrfbox[c];; Q% w; |# t1 l; g
fbox[c] = no;
5 i  i6 j7 P3 G1 N& g9 F}
7 N. `9 h7 N2 g  Qfor(c = 0; c < arrtbox.length; c++) {! }3 W: V( A; P
var no = new option();. Z1 V" H" n2 M0 y% L
no.value = arrlookup[arrtbox[c]];
. n  n) t$ W7 F3 T, pno.text = arrtbox[c];- U1 C0 s; \$ w
tbox[c] = no;/ n1 O. o$ K' K- ~
   }
' j( {# Y( C+ F- t+ a}  z1 T! q% j+ L0 F# D0 m! k
</script>! O- S6 M0 r' W% t5 B. h
</body>% V" k1 {9 ]5 Q( M

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