返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
* v/ h9 B& D3 N% G! z         c pageencoding="gb2312", Y6 }2 U3 T# }+ ?
%>
) W' ]3 B) D/ ^5 ]<style>
- g" _8 E2 Z# c7 q5 k5 {! U+ L1 p; v.f9{ font-size:9pt; }) @$ j7 f' v: a5 b: I
.bgc{ background-color:#aecaf9; color: #0033ff }
, w- v" }( _& D5 _( Z5 c.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;; G+ i9 T% y0 r' j% e+ a
  border-bottom: solid 1px #4e7dc1;
; w+ Y: j8 t. W; Y1 g$ P$ c! ]  border-left: solid 1px #aecaf9;' q9 |9 y; b& W$ N& Z' `$ P
  border-right: solid 1px #5679bd;$ ~, n! k+ W- x. x* d
  padding:1px;
9 |9 c$ Q' J" V  Y. y( \  margin:0px;}" B: n( C& \$ U7 Y
</style>+ Z0 q0 Y; B0 }
<script language="javascript">* w, @9 J8 G- g: z
<!--5 c6 m6 @: e9 E- h* B
function rv(); J2 h# [5 d( G2 `( Q. d% b
{" z( Y7 H3 i. }# s5 i$ T1 W% q: W
  var val="";
% X, _0 r$ H9 |6 ^! }" p; E" P: T! |  for(i=0;i<combo_box.list2.length;i++){0 _; R5 O3 ?, d
   val+=","+combo_box.list2.value;
0 s; S6 v" ]2 K6 V9 b& |$ U" r  }' M% X9 h+ Z6 B* d% ]; _
  if(val.charat(0)==","){& x; E  o. j) I- |
   val=val.substr(1,val.length);
0 _$ u7 p. h) ~% f  }
" u6 Y( f* Y- C8 F  opener.form1.frecname.value=val;
, ]" N3 D. o4 h5 ?5 `  self.close();7 _1 x9 J+ h) T8 v/ e
}
* x! w# E, H0 k+ ?& S//-->- m! ]0 x2 d( O. Q7 |
</script>7 Q3 W/ j; {. U7 H8 m% d2 I
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">5 q! Y9 _! @% V" K0 l$ f2 L
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
* v+ w$ n4 C$ ?5 F* F<%
: y; @9 n# H, W/ U# t" v+ F$ S  cdatasource ds=new cdatasource();  //数据联结bean实例
; f% U$ a* X4 C  java.sql.connection conn=ds.getconnection();
) K) {& |# i; ?" s0 @  java.sql.statement stmt=null;
% @' R* i- ~% a/ |) p  java.sql.resultset rs=null;
/ \* K3 N2 x# l5 e# M* K$ S  cdatacheck dc=new cdatacheck();* J% Z" W8 T& o9 p
%>/ G  ]( \( K$ S5 W0 T! l9 }  V
<%
0 G2 `/ g- W1 f6 g4 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";
- E( H  ~* O5 k: D4 M8 f, o2 Jstmt=conn.createstatement();3 x/ J; U6 t7 q" _  Z5 t! {* [
rs=stmt.executequery(sqlu);* w6 E( V& E$ q6 C* Q- \
%>: x# ?5 n5 P) m4 N7 m" o
<script language='javascript'>
; {4 L3 J! v, ~/ s- Z4 oarr = new array();
! X) w7 f& y; _% P( B6 t<%  int temp=0;; L4 y6 U* o2 L! D# s
while(rs.next())
3 ~' N% T. A6 K3 S9 W7 ?{- C  [6 G" o5 {2 b9 n& D. j
%>$ v$ T, x8 U4 T# r( a7 M! W( c8 B
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
( z9 G( C4 O7 Q- A( ^<%; p+ N5 i6 K. x0 p) A, Y* _. e9 k- C
temp = temp + 1;/ h" e& A. j, p5 h8 U! e
}( ^$ \+ f4 ]; [6 X
%>! ~6 R  \! y8 ~* Q+ l. Z0 D; Q  ^
temp=<%=temp%>;/ R5 V9 _/ W/ L6 k, F
function changelocation(id){ 2 h  I8 f8 T- R& H# w- Q5 u- {
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
, i0 I# J) U! Y- G4 G6 E! vvar i = 0; 7 [* H# }5 X) d2 [# C
document.combo_box.city.options[0]=new option('-------',''); 3 p; B7 r& v/ X. U
for(i=0;i<temp;i++){
5 v2 h) o, u% K3 f: Jif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
, ]5 q' S( j* u+ V4 _7 @document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
2 ], w1 k7 C7 Z0 h$ G8 l* f}
+ ~3 f7 [( P1 m  b0 m} $ @& N8 g  S1 k
}
2 b9 _, r+ x( z! @' J8 X! n</script>! R; j& h- Z7 p' _8 S. o
3 O6 J! ^% h4 C, T
<form name="combo_box">
6 J7 h" X9 [) _! t1 ?<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
8 h- w% g* @. U/ `% K& F  <tr height="24">
2 K1 e5 p  o) b9 I, V+ d' Y7 o0 I; u    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
. W6 `' m' y, h# H  m    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td># k% x( S) n% R. ]! l  l/ C
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>  l0 o6 _' u* `% Z$ b/ L' Q/ v
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
7 g7 h3 ]. B7 l  </tr>+ A6 ^& e, r: I: W: }3 k7 W2 [  y
  <tr> 2 T% F, Q* Z* B  q1 y: I3 _! c
    <td>
2 J. |& K' p. H2 E7 \' |" E  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
: J8 n. W. D- O6 c" R# U  A' ^  <option value="0">请选择部门 ---></option>
8 Z* L9 D0 |: P& }. ~2 X% R<%
# L  z3 H0 G$ J. [    string sqld="select * from tdept";" R/ Y# k! c2 F6 M; x
stmt=conn.createstatement();
5 o5 N" t1 `* ]: nrs=stmt.executequery(sqld);; @  D; D' v( I/ G1 E  T' E4 `
while(rs.next())0 @. P" N' `& E/ i4 _
{
( |' g& j4 Y% ?2 h%>) p1 J( i. W: d6 B
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
3 R4 r) H! ?# r& w% q1 E<%
( U& Y% l2 @! O}
% ?9 G' ]! L$ y6 \7 v0 H3 z%> ' V( f, Z) O5 {  {+ P
  </select>7 V5 V* }* x5 K* }8 I9 I/ A  R
</td>
6 |: s7 z% U4 q9 Z/ e    <td>. y& @) q0 O' z% z1 X  T
  <select multiple id=city style="width:150;height:200" class="bgc">/ m4 n$ J" P, @2 g& c
  </select>
9 y# R4 n7 p4 N) W</td>
& ?! A  J* c* O    <td nowrap align="center" class="bgc">
: v6 Q5 \/ h6 ?% X% b( j" q" x1 a  <input type="button"  value="<<" class="buttons">
, g1 M  V9 b" `, O( u0 U+ v0 {  <input type="button"  value=">>" class="buttons">2 p) B% G; j  `" L$ f' \
</td>
$ }+ m( u+ ?, h( _' ?- t$ r. b    <td>7 V  u- y/ N+ b% U6 d# X
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
& ]0 t% t5 V$ \+ L( w  </select>
* p4 y, L: n) _</td>; e8 F7 ?; P  N
  </tr>
7 z3 S6 p+ e! _* B* X    <tr class="bgc">
+ Q, t, @: C7 r, o! f    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
4 R9 C& F* P1 {9 j  </tr>" R, A7 j. Q4 x- f2 l
</table>- N* q0 @' ~( c" P$ g! O9 q7 ^
</form>! z; v, P4 N, y0 z; P4 |, y
<script language="javascript">
8 j) }9 \) N2 a3 B5 M2 N0 c+ {" y7 u//人名移动4 a& E, n' a1 I& C
function move(fbox, tbox) {; A6 j0 R; K# ^" N
var arrfbox = new array();9 Z' K  K$ O) v6 G+ Z- A9 ~& E
var arrtbox = new array();/ m9 }9 _- |/ V: R, n* W7 \
var arrlookup = new array();
: Y3 \# {$ ?8 _" C( r7 M& I* X) gvar i;1 n5 v% r7 a5 S1 K; @6 d
for (i = 0; i < tbox.options.length; i++) {  J; B6 x# ?7 J" R. c$ o9 z, s
arrlookup[tbox.options.text] = tbox.options.value;/ [: N9 B9 L. t  n
arrtbox = tbox.options.text;9 q* u5 V9 C. |4 d7 f# |
}
0 W) @7 X% |# \var flength = 0;
; D: `: R5 c- ]$ P0 avar tlength = arrtbox.length;; t, w3 K9 P0 ^: Z, a2 b* K1 y  H" }
for(i = 0; i < fbox.options.length; i++) {
1 ]! _2 X; U3 I& h+ u+ sarrlookup[fbox.options.text] = fbox.options.value;
  J* Q7 X7 T3 {  rif (fbox.options.selected && fbox.options.value != "") {
: v7 I  K7 v$ \. I; F1 }arrtbox[tlength] = fbox.options.text;
( q( J6 Z2 [0 C1 gtlength++;( B* U8 x) ], t8 Q
}3 I& j5 w) O* w* {
else {% I- r' M( L/ f( J
arrfbox[flength] = fbox.options.text;
! Y8 S& H1 S9 @2 ^+ d+ Vflength++;
8 b5 I5 B% Y; E8 S' Y" T2 Y7 l+ _   }% M- o, G1 a* n, U3 P" p1 o9 [
}; L" F$ N$ ?* Z0 @! {* l
arrfbox.sort();, c" `& j# V9 D# N
arrtbox.sort();& O3 F7 H% k1 C/ q2 @2 m7 }
0 I, {! V" R9 j
fbox.length = 0;
" j* N+ m1 W! y! u$ B' m2 ltbox.length = 0;! Q# L- a# V$ Q* X4 ~
var c;
; R% x+ b3 ^+ F& E9 w/ kfor(c = 0; c < arrfbox.length; c++) {
8 h  E6 |. k+ hvar no = new option();
" K1 S" u$ I0 G1 `no.value = arrlookup[arrfbox[c]];6 d: x. d3 J+ g( h1 Q% w6 x8 t
no.text = arrfbox[c];' H; a$ I( y+ E" _2 z! w! G
fbox[c] = no;
! k) W8 F9 `! E9 C, Z}; L$ s# I; O( R* y& R/ V
for(c = 0; c < arrtbox.length; c++) {' L+ m  I9 p1 U4 Z6 w! G% U. c, R
var no = new option();
  |8 b) l  {3 Cno.value = arrlookup[arrtbox[c]];
1 W  _  m; R# R) Wno.text = arrtbox[c];
  G- b, N: e0 Y; ctbox[c] = no;
/ d4 k2 P0 z0 B5 z) s  C6 J   }- D8 t+ E; {% w) @4 J3 |! T% B: o+ c+ F
}
9 [6 `2 w4 J& C3 w0 W# |</script>" W. R) z% Z4 @' |  x5 z( d+ ?
</body>
6 a; q/ `  r, `9 e7 M9 [

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