返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
( s: k1 s0 K  m- V         c pageencoding="gb2312"
$ v6 [# `# x0 f, S$ e# a' x- Q8 M%>+ h' @. Y) ~) h. F) ?
<style>' h& W2 v- a' G  X9 A7 o
.f9{ font-size:9pt; }6 D& D/ g& j; g/ R
.bgc{ background-color:#aecaf9; color: #0033ff }' f0 z& I/ u7 n5 k
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;, _- c3 T' l6 p3 ^; G; w
  border-bottom: solid 1px #4e7dc1;
; w! U/ L5 [7 I' j/ R  border-left: solid 1px #aecaf9;* q# x# Y' P# M2 b* k
  border-right: solid 1px #5679bd;
: r8 R/ z2 {& K1 D  padding:1px;# @4 q9 f1 T) B& \1 J: D4 U: ^
  margin:0px;}
* f! r; c! Y* D; I* ]* X* h</style>3 l, Y8 |" k: j
<script language="javascript">4 z1 k: j( I$ G' {) m
<!--
4 A0 X# R8 g( Kfunction rv()5 q$ e$ X- ?  G/ q
{
; \' @7 ]3 s: T3 i6 g' W  var val="";
+ \( Z9 D; x7 `: G1 p/ d  for(i=0;i<combo_box.list2.length;i++){
5 ?7 {2 e/ q$ e* k& ?   val+=","+combo_box.list2.value;: ^7 z/ ~3 V4 `3 s$ D( g
  }
! Q0 H2 Z. W1 A' r4 G& [* ^7 x, F  if(val.charat(0)==","){
) Y( w2 }6 m" L# v2 T   val=val.substr(1,val.length);
1 Z. o; v+ I! q/ G  }
; }3 N+ u. E7 J8 J  opener.form1.frecname.value=val;
, L( h3 i" i0 ^  self.close();( y& S% B" ^2 b+ Y1 U
}
& {& W2 [- f( D% ?% T, m9 i//-->( `  H5 c6 D- a& Y
</script>7 A6 i4 a1 {9 e* U
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
2 N  R/ F; `- J$ M7 a& s<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />! s: v% S+ Q& A7 }* }
<%0 ]% q' Z" C2 Y
  cdatasource ds=new cdatasource();  //数据联结bean实例
$ F6 r% `2 E/ S1 \% t/ C  java.sql.connection conn=ds.getconnection();
7 L* l7 P5 H1 d) j; l, S7 w1 }3 ?  java.sql.statement stmt=null;
# V- N# j" B7 O  java.sql.resultset rs=null;
5 k" @) q8 s# {$ E5 T/ x  cdatacheck dc=new cdatacheck();& M: ~: [, L. E  a5 H
%>9 |8 ^$ v  k/ n/ W# l+ z% e
<%
5 c$ F# e' M. {; y  L; D5 Estring 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 Q$ }* z, F% z9 x2 k7 Kstmt=conn.createstatement();
- _0 @1 W4 \) P; c8 q  Wrs=stmt.executequery(sqlu);
- y/ ~1 i- [$ }, g6 E; Y7 Z%>
" f* S( n. T# n5 m) K/ S/ `0 r! I<script language='javascript'>
6 ^* u  B- b$ T6 ^; F; c( p7 \5 F9 Varr = new array();, u3 r! d/ a: q8 ^
<%  int temp=0;
: ^" s9 A- h$ x3 g) i( @while(rs.next())
* T. Z; L6 d" t% \{
# T2 ?& m- |% {' |+ y%>
1 i' _# Y" D3 t) g* zarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");( t4 G) K2 W4 m( d+ D. J
<%% M4 x; t% x. E, `
temp = temp + 1;
$ Y' w0 X4 o% d}
! ~% l% m" a$ A( c$ \7 [%>
# E1 x: l& W4 A. q2 O/ J5 i! F, |temp=<%=temp%>;: h$ d- \! U, E, e/ G- V, W
function changelocation(id){ 2 H% y4 d# t. r( l! |$ X
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
) `* ]. ~  V. p8 w) }" [var i = 0;
9 o7 R, \: Y5 p% W- y- Adocument.combo_box.city.options[0]=new option('-------','');
: o& P: ?7 |" H! S/ tfor(i=0;i<temp;i++){
; {# E) _/ g+ c! A7 Q, e) I/ Gif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] % ]  a8 {: L" r
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); : g% v  s& c9 Y/ t$ N
} 1 T0 l6 d5 T4 f+ o, H
} ! ?; Y1 |) D* ]
}
& s/ i+ o( G7 J8 v0 Z4 t7 N0 G</script>
. R4 q# r/ t, \9 C( n4 E! r) K8 K" a
<form name="combo_box">
2 h$ S& b6 X4 L, x( Z<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
! l$ a$ v4 y. f2 {  <tr height="24">( B2 w: ?" T; q* b$ _
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
7 r/ O: s& p* |5 s6 G* r, R    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>7 j) R/ d% t: \( A  J
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>+ p- \7 D8 E1 R  {9 T
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>, X* Z! u1 H3 D4 e
  </tr>
! J. K- h8 f: ?  <tr> ; A( ?: X) A4 u- r# q! D$ N
    <td>2 i: v, x  H0 ]8 g3 O
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">0 g) P* k6 F$ Y, n# H4 H
  <option value="0">请选择部门 ---></option>
  G+ j  O: A. b, Y$ \1 ?+ e/ `<%
! z8 U# p* D- O8 M6 E    string sqld="select * from tdept";" \& \9 S3 n' W+ C+ r! b" N3 _
stmt=conn.createstatement();# j% @/ z: n6 O5 D
rs=stmt.executequery(sqld);' ^6 q( D( l9 J8 \( C( \& t. S
while(rs.next())
; x9 r: ?3 y! K5 K6 X{
* {) \+ r8 B5 [3 O: ^$ ?%>. ^1 w" @$ t3 ^: j: B8 H
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
$ z; f' s( s5 V3 B1 I9 D- n<%# A2 s2 E4 F% U& ?$ C
}3 n1 l- j$ w0 f: E( z! w
%> % `! o% u  R7 }, W* e7 S2 ?$ R
  </select>: \6 ?! b3 c  d0 [3 L4 o
</td>
' i, [! n- [% R0 \: A    <td>
0 C* h) F7 s  p. y0 X7 E  G  <select multiple id=city style="width:150;height:200" class="bgc">( A- q3 }0 I9 n' N- N" H% J
  </select>2 i, n+ |! M( M% x* Z
</td>" x5 l, y; w4 I; y7 A' }* `
    <td nowrap align="center" class="bgc">" O: i# z0 z$ [6 ?
  <input type="button"  value="<<" class="buttons">$ Z# g1 }1 N+ p4 m5 A6 t8 ~" `8 n
  <input type="button"  value=">>" class="buttons">
; _3 I0 w6 e' c; D4 ?0 P</td>
* s1 P3 x7 g; y- l! p; h2 ]    <td>% V& D1 b4 b) \. S+ u1 W
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">" x% Q& N; s- |6 m
  </select>* w# Z4 }1 @. n& w! l7 Y7 E
</td>
* |- H$ O8 Q9 ?8 r) Z. [* h' v* M  </tr>$ ?' J: N6 k6 G0 A# A8 R1 T8 F5 K
    <tr class="bgc">
% O% r* A' @6 d% o3 F! U    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
7 \2 b$ J9 k  P% b8 R! q  </tr>
+ f8 _" O5 o( d% z7 F$ N# n</table>
/ c$ a/ q0 @6 y( A</form>
7 R/ ~0 Y4 f5 Z<script language="javascript">' [- t8 V' U; n+ `& \& a
//人名移动
7 x6 n4 p& y/ V) ?2 ufunction move(fbox, tbox) {$ q3 M9 A7 q7 F$ D1 V
var arrfbox = new array();" Q* {) F% x! w/ r  z# ^. P/ U
var arrtbox = new array();
6 _- P& s; K, i9 n1 P! o2 s6 \var arrlookup = new array();% G- t' a$ D% h( Z4 V0 T1 m
var i;* G0 F, }1 G' K' c- p8 |) l
for (i = 0; i < tbox.options.length; i++) {
# s$ `8 v+ E: {! harrlookup[tbox.options.text] = tbox.options.value;
6 T9 T' v& ?% ^7 n6 yarrtbox = tbox.options.text;
5 ^! j: e* F3 r( ?}
, ^9 _* h1 y1 M/ f+ o! @var flength = 0;% i+ g  M+ J5 f. H# k9 @( t, t
var tlength = arrtbox.length;
! y) V, u. e' E- K* V- Nfor(i = 0; i < fbox.options.length; i++) {; b1 H' h: `( n
arrlookup[fbox.options.text] = fbox.options.value;
9 a- B5 ?* z# t* T2 g* _if (fbox.options.selected && fbox.options.value != "") {4 E& J) T) r& p' w% K% T% y
arrtbox[tlength] = fbox.options.text;( Q3 ^3 b& R: R9 U8 m6 |* @
tlength++;3 O5 ?# [/ X5 G: L( d
}. U7 ]. A; b5 R' C7 T9 T) Z* {
else {. f7 H. `6 r4 x$ {7 U
arrfbox[flength] = fbox.options.text;3 W- q9 h4 c( W4 S; C
flength++;
- |2 H) }9 h! x   }6 P& H# H. n5 g$ w
}
, f. K% A/ D* r4 narrfbox.sort();
( m9 \* h6 s' U5 }arrtbox.sort();; v% [: S9 Q, S, i$ h
4 L! ~" c5 F# }! R
fbox.length = 0;* d: D0 N8 Q, }$ G
tbox.length = 0;8 S- q; q$ v9 @. Q# S1 m
var c;7 e  K& _. N' p9 k9 w
for(c = 0; c < arrfbox.length; c++) {
- I+ v% C; T. K4 L7 d) a, c5 wvar no = new option();
! Z: P0 e: j5 [! _( h' U( lno.value = arrlookup[arrfbox[c]];- n9 o8 S" L, X( y8 X3 v  }
no.text = arrfbox[c];& Q; f% g" }& Z; [" \+ A0 K9 o
fbox[c] = no;
% l; X" I5 o. D1 e" g+ v}
7 U3 h% ~8 _2 Z; @8 wfor(c = 0; c < arrtbox.length; c++) {, ?+ J( n" L! {+ v8 N
var no = new option();' h; [+ z' m+ N! H: G5 f
no.value = arrlookup[arrtbox[c]];
) @$ R+ a; P# h1 L: C3 X5 g! l" ?no.text = arrtbox[c];- y. p& }1 v& c5 S  J! T) @
tbox[c] = no;- G/ `. n& x1 C0 I0 f2 j- w/ E
   }
* w' ^) M) F0 d) u& n' t( p+ J" @}, J" c- [1 g5 {, i' h  [
</script>8 L( ?& ^1 h# U  [+ Z. i! M
</body>- E) h9 x  y6 X

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