返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
% J* F- ]4 c1 _/ c+ K. K, r# L         c pageencoding="gb2312"
4 G0 R9 r) N4 p; W( z! \%>
* F6 Z( V( L% x0 u6 y8 N<style>
# K, T$ d! c, }) I& ^  f1 k.f9{ font-size:9pt; }
( A" D* I) o5 E$ o.bgc{ background-color:#aecaf9; color: #0033ff }
. {# a' \, }+ F& G) K% G.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;& s9 l% J7 w: [# W: w4 i
  border-bottom: solid 1px #4e7dc1;
9 q7 e7 h) X8 Q) G* L  border-left: solid 1px #aecaf9;1 S% n3 i  ^! e) R* i
  border-right: solid 1px #5679bd;* x/ j* k, y$ `; Q7 w+ D' S# _
  padding:1px;
! |( M# |, I/ d+ L7 O# m) c+ a  margin:0px;}
1 `& M: R0 H" y</style>7 |; n7 {: P& Y! y- G% _
<script language="javascript">& H: e% P! C' [% w
<!--
- f3 x! Z. O6 |: K# Zfunction rv()4 D" q4 _: _, [6 x6 V8 g
{
" j  B5 U, r8 o1 P' f0 G1 y  var val="";
1 g, f" Y- G$ f4 Q* f! ]  for(i=0;i<combo_box.list2.length;i++){$ E# |; x9 g: J, ~# ?7 D5 A
   val+=","+combo_box.list2.value;
% u8 {" Q: r& O+ G; Y  }
$ i# m  U7 \* }4 R8 o4 G  if(val.charat(0)==","){  o6 r; K; Z: E* n/ `" P6 |2 T3 g" _9 L
   val=val.substr(1,val.length);: M8 Y" ]$ k  x" W6 ~
  }7 X# E, Y7 ]+ e! h0 C* B
  opener.form1.frecname.value=val;5 f9 V. Q- N5 Z; u% t
  self.close();
- P& D" P4 ]' T2 u}
0 O; s0 Z" m, c/ Z: e7 V//-->
7 T4 [3 Z: z+ O- G</script>
. O/ y7 y6 K, q# c<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">! x" O2 J3 t4 P& k8 M1 d; }& R
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
+ P+ M- e! {7 g8 q<%
/ b" d1 a& p* W4 w9 m' V, i  k& m/ ~  cdatasource ds=new cdatasource();  //数据联结bean实例
5 L7 J" i7 S; g1 l( G! v; ]  java.sql.connection conn=ds.getconnection();
2 W" N. Q# {; S  D  java.sql.statement stmt=null;
+ U! ?3 X1 w1 v0 [& g  java.sql.resultset rs=null;6 b: t+ c  M$ c0 y% }9 f* M) X
  cdatacheck dc=new cdatacheck();
+ F. {* Y  t# Z: u* X%>
& _( N* ~  d9 @& y" h( Y<%
: h  W0 J( y! N  Dstring 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 }8 \* Y* v, A' ]; Y2 `
stmt=conn.createstatement();
& J# I3 R& a" r6 M; Yrs=stmt.executequery(sqlu);) S: R) F, {* ?! v& I7 C& }2 k. |1 N
%>
' h- L" \2 h$ P+ L0 o; u' ~5 H<script language='javascript'>* D( N+ B% E8 }+ f
arr = new array();  \+ E5 R8 X/ S/ R! X# o) h
<%  int temp=0;! @+ ~$ b: q; J, S7 C7 g
while(rs.next())
. L$ N, d. V2 W4 _3 s  x, @/ d{" w/ \, M& o7 n, p; f7 `
%>
3 J! s1 W& v3 u( E' oarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
  U( J% P( s/ x<%
, r" J# N  K% L) `3 Vtemp = temp + 1;
( \0 ]: n/ Y; |! W}
' y4 F7 C, L' ?/ C( X/ t%>8 h4 r' D" v2 u- C; B. u
temp=<%=temp%>;/ p& ]8 R! S3 E  j$ C- r# H
function changelocation(id){ " y/ Z& U8 M$ `! U/ q
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 # y8 r! S  q( D% ^5 W
var i = 0; 7 |; a- D" r, w: Y6 ]7 o
document.combo_box.city.options[0]=new option('-------','');
2 D9 z: {8 A6 e% x+ }, Zfor(i=0;i<temp;i++){ + p  {4 W% b1 n4 _5 k
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
4 w$ f6 X+ t6 f6 ?document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
0 i& ~  b% t# H( p& a} 9 ?+ d& ^! K( v0 q, p9 O: `: w
} 3 @  {. x8 L7 @% w0 y1 |
} ) w1 B' k) ~$ [$ m
</script>% G8 r- w( _: T" M* v5 ]! N

4 U7 t2 E% X, p4 e<form name="combo_box">
7 x2 O8 e( Z0 @1 e5 p/ w<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">( S* \6 ~! K2 N! @/ g4 j
  <tr height="24">
! u9 X3 l/ ^5 F; c    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>! `3 T) a9 w7 [
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
1 [- M- p$ d! J" ]5 f5 M    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>. z! W) x  K, @$ X0 ~
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
) m4 c0 M7 h) h7 J  </tr>
1 f1 |: A$ t+ E+ I9 P  <tr> 8 [) e- t4 B7 Z  m' P
    <td>, {9 B3 D4 [: Y- O+ t# D# ?
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
- I2 f' `; U! a$ w  <option value="0">请选择部门 ---></option>" i& w+ F8 {2 f3 s0 ?; R4 a( i) `- @' \4 U
<%! O6 r6 C! _0 I/ c# _( p
    string sqld="select * from tdept";/ |, ^- h( _7 ^
stmt=conn.createstatement();+ _1 y( X6 e$ m! c( J- y7 e
rs=stmt.executequery(sqld);
. y0 y9 u3 o$ A' a% E0 q* y/ m" f2 _' swhile(rs.next())# p& R5 J% H- z6 _# C) B. P+ A
{
4 P. t4 U% v3 K3 ]2 G1 C%>* b. H5 \5 n8 \+ _3 l' L
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>& U9 z0 r/ ^$ P; m7 D# l
<%
" r" o1 Q% X* ]3 `}
" Y$ O, h: P/ s# p) \4 B%>
2 Z4 b5 i" X5 a  </select>( v- q7 u) z2 k, l# X
</td>& j2 o+ |$ s* s7 _3 o
    <td># ]8 y  F5 e% o  t1 q
  <select multiple id=city style="width:150;height:200" class="bgc">3 O( \9 ]/ g7 ^+ `% Z0 ]
  </select>; q) n, x: @) B( N, F+ J+ C
</td>
' C0 A% K; u& X" {/ ~5 a8 T    <td nowrap align="center" class="bgc">
1 u" t+ L4 }! ?- |% ^) V  <input type="button"  value="<<" class="buttons">3 Z5 t+ m' F! F
  <input type="button"  value=">>" class="buttons">* i/ v) c/ R2 [! ^6 g! N
</td>
: x6 ?; V3 b0 f# E    <td>
: C! b/ @0 d6 \* f  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">: Y  J- f2 n- G: V0 s
  </select>
6 C, j& d! [; t6 j) C0 O' T2 ]6 e$ s</td>
/ J9 |& \2 |4 z% I$ g0 p  </tr>
/ @, K5 t! H; R! _1 l" n    <tr class="bgc">
! m0 G' k: o9 u# E: y& P7 t9 f: N    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
; Q0 ~) C, n0 f8 q+ ^! J  </tr>* E! A& y( e+ Z( m& _2 @& X
</table>
, ?, f+ Q! E4 \! S</form>
- x1 ~& _  I2 o4 \  ~: |( C+ Z& E- x<script language="javascript">
7 Y0 O1 M+ B8 Z7 P//人名移动
' m# D0 b% W; E8 B7 Ifunction move(fbox, tbox) {
3 ?- H' E: M8 X* N! fvar arrfbox = new array();( b! T! o; b/ j  b+ e5 P5 f
var arrtbox = new array();( Y0 W$ U/ U/ w
var arrlookup = new array();
2 L# l) [$ W" H1 J, g6 h* Xvar i;2 S8 ~2 h& F# Q' z
for (i = 0; i < tbox.options.length; i++) {
2 `* ]9 S3 `  b/ j/ k% oarrlookup[tbox.options.text] = tbox.options.value;
3 K' w0 y! f/ q4 ^- P. tarrtbox = tbox.options.text;  [5 q5 A1 f" y& ?: d& Y! C4 v9 k
}
# N# d- \% V5 [3 rvar flength = 0;
* x; ]% H' K$ @% l$ o8 [$ {% Tvar tlength = arrtbox.length;
8 |$ B* y; ]1 v- A$ M% k% l# H0 [( ifor(i = 0; i < fbox.options.length; i++) {
' r1 u9 g, ]1 X$ ]) c! L' u1 X" }arrlookup[fbox.options.text] = fbox.options.value;) p8 ~! f2 p6 U' g. u7 ^7 O) C+ P
if (fbox.options.selected && fbox.options.value != "") {
* S& T7 X, }5 p: Zarrtbox[tlength] = fbox.options.text;+ E* R. B$ g6 i4 z) G, X' y
tlength++;7 C5 p+ V! ], n+ b. I2 [
}
- k4 v; u2 }5 t6 t3 E; H+ lelse {
& Z/ S6 L, g% i( x9 |# t. O8 parrfbox[flength] = fbox.options.text;  F6 G' q$ ^+ p" s
flength++;
1 K( E$ W9 Z- U1 _- x8 u   }
% y6 m% I7 p( Q; o}  v3 [! L0 q, [# w. j. O
arrfbox.sort();
7 X! x+ J( g+ f  |- Oarrtbox.sort();+ V: _5 z& k0 r. c
2 D  Q" V5 f. [. d3 ^
fbox.length = 0;
. o' x# o2 A- n0 Otbox.length = 0;
5 J, h! N# p3 e" C) [) Svar c;
* Z9 E; @+ |4 K/ Sfor(c = 0; c < arrfbox.length; c++) {
; Y, [- \6 j0 r- ovar no = new option();
: b9 ?! O4 n8 q  Y, X9 P8 ?+ b# Z" hno.value = arrlookup[arrfbox[c]];
% q4 z& n7 J1 C: ^7 h) m$ Lno.text = arrfbox[c];& o" J1 c$ u# I  w4 `0 [- |# m2 y8 X
fbox[c] = no;
% F( C* Q6 X  {$ m" Y+ R}1 l4 J" l/ @. o( N5 a
for(c = 0; c < arrtbox.length; c++) {
! \# o7 ^# W: L* \var no = new option();( I+ X* ?# h5 @
no.value = arrlookup[arrtbox[c]];
* ^3 z  h+ c# ^! @" w6 V2 w4 gno.text = arrtbox[c];1 M. f! F. ?. c# ~2 e* `: \
tbox[c] = no;! {( F/ P7 f5 e$ q" P  i/ y( h
   }
6 Y+ j0 e2 [7 S5 h$ q8 Z! Y1 w5 y}
6 a/ G( `, v7 t1 F& s  G) \</script>1 a3 K& w- O; R, a: W4 O: F
</body>
2 `/ J4 D2 A, |0 d2 p. `

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