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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"( W% C1 M* e; K( [" G1 G  S! b
         c pageencoding="gb2312"- L2 \+ ?$ s) J" a
%>
( T7 u; e/ g- y* J4 d* e  F% I- s<style>6 k, S9 N% S" U7 |9 O
.f9{ font-size:9pt; }
% z: @4 I6 Z1 H3 [8 K+ O5 Z.bgc{ background-color:#aecaf9; color: #0033ff }8 n5 h% s2 b" o3 O4 S0 @# p4 ?
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
( F/ F! U, k8 V- z0 l+ v6 Q3 u  border-bottom: solid 1px #4e7dc1;' \4 }5 Q: Y6 E3 ^4 D0 q2 p' B; A( N
  border-left: solid 1px #aecaf9;
8 }; ]) ~8 g2 }  p6 D  border-right: solid 1px #5679bd;
: m: F7 j7 a4 [4 q  padding:1px;
$ o7 K0 V- \9 q4 q8 S" s& L  margin:0px;}
# K6 S( S+ a) E4 d</style>
* ?1 h* y# A; T8 A( u<script language="javascript">: U( C3 L% `7 D7 W* I
<!--" N6 W0 O" ?) y9 T8 s
function rv()
: _5 |- F4 W" l{! u! K' k6 x. q# u$ q% e- u
  var val="";
/ S+ {0 D8 C# @! ]) X6 k3 j  for(i=0;i<combo_box.list2.length;i++){7 G- O( H% i* V  Y6 S1 w
   val+=","+combo_box.list2.value;
" H" g' r! a0 D! x( [8 T5 Y  x& h  }
/ f; N, m1 V! b6 h  if(val.charat(0)==","){$ u8 U- _5 {# N. ~
   val=val.substr(1,val.length);
% A8 k, P+ _+ z  Q4 I2 D  }
6 E3 y7 l2 Q. {" h  opener.form1.frecname.value=val;: R+ z8 T  S. A
  self.close();0 _+ V' `' _9 J
}
0 j- p3 X- z7 p2 a+ n//-->
* ?8 a# \- ^+ E6 V! m2 g0 C</script>! d- r7 G4 S+ ]% g% n" |
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
1 `& k$ n/ Z0 z5 c, x<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />7 u+ N* H& z& w7 h3 e8 H3 `
<%
# a" m+ |, r* e6 D4 L' r5 H9 d  cdatasource ds=new cdatasource();  //数据联结bean实例4 Z2 J3 q* a# m( H% n5 T  r# o- R
  java.sql.connection conn=ds.getconnection();
3 Q: J/ b. S; D3 t( g8 g; q  java.sql.statement stmt=null;
  u; U; V( x7 ]+ [" l1 y  java.sql.resultset rs=null;
6 z4 l/ ]3 x2 [! ^. @. \) y- D; F  cdatacheck dc=new cdatacheck();
% \+ U+ T6 f' Q/ K2 U%>
' q8 b0 o" f" l1 H2 Q<%2 U6 m& B6 Z# I5 A
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";
% N$ }2 }  p* Y1 u/ Dstmt=conn.createstatement();( ~3 ^8 A+ G3 p" [2 q( ?/ a
rs=stmt.executequery(sqlu);
0 |" o) i) M8 g' `%>
% P2 n. d8 q- W9 Q9 V- }$ U2 @/ ?<script language='javascript'>
* F/ R) J) G+ B( iarr = new array();4 O% {9 H# p/ h& g
<%  int temp=0;" Y7 i2 X: Q+ V- W6 A) H$ R
while(rs.next())4 o; o5 y0 @4 j3 C
{% t+ Z' x& x6 J
%>) X5 s. K3 b1 t( F# ~- f! s
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");- ~' D/ ^( {* E2 V% N7 A
<%
6 n' x& \) f5 h+ A, @temp = temp + 1;5 L* N3 t+ m) v) P. Q/ F
}3 B3 w7 r+ T; K9 s" R; c0 O
%>0 _( e8 x; g) s
temp=<%=temp%>;
( w; B, Y; r% s# V; @8 }4 Pfunction changelocation(id){
  d& L  T% ?  ]; Adocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 & t* H: F/ F' _) P$ f" S
var i = 0;
/ k+ ^' b, n$ f% o5 T+ E; }" Edocument.combo_box.city.options[0]=new option('-------','');
% W$ V/ m) ?1 M$ P% N3 D$ Efor(i=0;i<temp;i++){ 4 S( f: D+ C- `+ e
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
$ m% R9 v4 x. d, C2 Vdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
$ q% \: h& I3 n} / ~) x8 p* I  E6 V3 k4 o
}
$ P" _0 q2 M' _! [/ Z* L1 v- }4 p}
5 I# j2 ~( _) \( l( o% G</script>2 G0 m$ S4 [4 m4 g, z4 D. j9 `4 s
7 x- j4 z+ N: n' I, l: m
<form name="combo_box">7 G0 _* A- k" S5 L; A
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
% E0 f4 t- W- W# A; F  <tr height="24">% S1 `, J3 y) L- d, n6 J$ V  ?& B: {1 I
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
( H7 h+ {3 U, s+ T    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
! Y+ j- K7 _, |5 L; k8 J$ R0 T    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
) B: m3 L7 d2 Q! A. [    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
; |. u9 e5 h1 B  m7 O; u  </tr>
. L2 S1 Z0 P. M, K0 G  <tr> & I: C% P0 X7 u2 O  T) E' s
    <td>; y: R4 c$ l/ L1 B
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
9 s  m. C$ g9 j4 r) o' [- Y  <option value="0">请选择部门 ---></option>
) S# |& P& V0 L5 L" D4 @<%
- |& I% A. A  X& l    string sqld="select * from tdept";# X* C: N/ o: ~! j# }/ _+ h
stmt=conn.createstatement();5 s2 v' c8 i5 k5 s! s7 ?
rs=stmt.executequery(sqld);' o  a4 B7 {) J5 C5 E
while(rs.next())# P  s7 k5 V* o
{' @  G' t# T* `: |8 a
%>
- o7 q1 O5 ~0 h. Y1 s  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
: M- c1 V6 g" ], t  R" V<%
- Q- h# {$ H8 ~% s}
0 Y1 j, k% l$ v  @( F%> 9 u: @3 F( }# x* q' Q
  </select>; U+ W6 q  ~2 b" i* P5 `
</td>6 ]0 D5 D( V' z% `/ N$ t6 [
    <td>% t, ?3 ^% k. b  b- v( ]
  <select multiple id=city style="width:150;height:200" class="bgc">7 X. F4 A* Y$ \" G+ u7 A
  </select>
! Y5 O, }0 w1 U4 [$ v</td>
* x' I3 G' L9 z( v- x    <td nowrap align="center" class="bgc">: X& x# s- I7 w5 e
  <input type="button"  value="<<" class="buttons">  R+ Q/ U+ f& L' m7 u! k! i
  <input type="button"  value=">>" class="buttons">
1 o; u5 m( P/ M5 U- {</td>5 H( \6 e: M4 @7 v$ \
    <td>
; I) |" ^! r2 }: ^; R3 G9 Q% d0 W  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">5 N3 O0 P' I% \- S( Y  ~4 b' u. A
  </select>* @1 [; U3 b: b8 p  _# E
</td>
2 g. ]! w4 e2 i2 g2 `; I% O0 R  </tr>
4 U" t* q' D+ `) _( s: H    <tr class="bgc"> 5 D) u  b# N& J5 f; P8 @4 h
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
: N$ Z' z& z/ a( Q. }  </tr>" _8 r; c& P+ o( \! z
</table>4 s5 U3 h6 d6 k8 P. \; P- K
</form>. I2 P2 c/ X) |4 R$ }8 e
<script language="javascript">0 Q, f4 B: O; }0 p- {
//人名移动
/ z# q: I$ [# yfunction move(fbox, tbox) {8 Y6 `$ p( L  @6 B
var arrfbox = new array();/ k! \1 y/ S9 S2 I& m
var arrtbox = new array();! Q- d7 l% s2 N
var arrlookup = new array();: U4 d5 {9 Z" P+ O9 }) z# X
var i;; I: q8 n: c1 G0 x8 ?, R  t
for (i = 0; i < tbox.options.length; i++) {$ z7 S$ Q" j- a% g, t% V, }
arrlookup[tbox.options.text] = tbox.options.value;& B) W  p" M5 }( L2 L
arrtbox = tbox.options.text;; o: [$ e4 h( R; m
}+ [& B# r1 J+ E
var flength = 0;# R; ]% Q& }( C% E  s
var tlength = arrtbox.length;
" A2 K: }6 |$ v! Cfor(i = 0; i < fbox.options.length; i++) {+ _! X2 A1 J) _7 p1 ^
arrlookup[fbox.options.text] = fbox.options.value;
% U0 o7 n" m: r3 Kif (fbox.options.selected && fbox.options.value != "") {7 o/ y. D9 b! ~4 @
arrtbox[tlength] = fbox.options.text;3 W5 q( s% `  Q0 Y  q( \& b
tlength++;
. e; A; B% }% N}  D+ s7 d1 a) n
else {
5 V4 v+ r  b4 g* yarrfbox[flength] = fbox.options.text;- }# ]- ?: e& q8 J
flength++;
# H/ f- d7 A% i8 }2 c; X   }
, d1 m2 W& O, n) D7 r5 Y5 Z+ T}
) |( n* ]% |. w$ Carrfbox.sort();' `- _6 w6 ]) @# }7 I
arrtbox.sort();/ q( U* v/ {3 f. a
- M0 H5 b: n$ I0 K4 z; V
fbox.length = 0;
& e$ o3 e( D- itbox.length = 0;
2 W/ ?! V) J& D7 Qvar c;
$ y  F0 k# u& ?' r% m$ D9 _for(c = 0; c < arrfbox.length; c++) {
' e5 f& ]! R- G# a% F& I& svar no = new option();
: L. J7 m+ W( ^) Rno.value = arrlookup[arrfbox[c]];
/ Y1 E' g+ s# A8 ~/ G: nno.text = arrfbox[c];
6 ]3 T8 X! A1 C, z* ofbox[c] = no;
6 _/ b/ I4 @" g2 G( Z3 [}
! s6 G. Q$ V0 }8 `- |: mfor(c = 0; c < arrtbox.length; c++) {, L( ]! f! d6 w" r$ J3 E: }3 o  I
var no = new option();/ p5 v* O/ s" R" m: h1 K
no.value = arrlookup[arrtbox[c]];. w2 k1 X; ]0 }. N& q1 b. \; X
no.text = arrtbox[c];
# R2 ^* m4 L, N/ h; j5 Etbox[c] = no;* e1 d8 e; y; P9 k* p: y& b% l
   }
& ?: d2 B* z" t% P8 w}3 C& Z: M! ^. N, S) L
</script>% j6 M+ K7 Q2 A* \* r9 f. i
</body>
' R$ j! j0 i* J3 N3 A

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