返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
8 y6 y  h1 c" M0 R9 d# e' M$ Q/ m! Z         c pageencoding="gb2312"
1 j( a) U# x- q% i%># v  {4 z  h* c7 @! |* ~4 `
<style>( ]9 a0 |+ _& N; I/ N1 H; N$ t
.f9{ font-size:9pt; }
* p4 M! d; J3 x( b5 ].bgc{ background-color:#aecaf9; color: #0033ff }
' K4 E) B9 ~( s2 r6 m( O.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
+ \: W4 u5 ~9 U7 q9 f+ ^, V  border-bottom: solid 1px #4e7dc1;# \# s8 L6 ?1 y9 q
  border-left: solid 1px #aecaf9;
* G4 U) {& z3 I. ~) C  border-right: solid 1px #5679bd;
. a6 O/ O- p. f/ _  padding:1px;& V, m( `% |5 @- F9 y
  margin:0px;}
9 ]8 e# F( }, u</style>
6 V0 Q% n% ]# B3 B/ k<script language="javascript">, v1 Q, c+ I+ X! P* t" B
<!--
7 J1 g7 f4 O1 {* tfunction rv()
( C& W5 m" ?, }  p  G{
) a6 Y0 _* r. Z  ]  var val="";
9 y5 x- y" u+ o. V# T  for(i=0;i<combo_box.list2.length;i++){3 G& S" h9 [% q) r) w9 i& O
   val+=","+combo_box.list2.value;
) @' g7 v$ w8 v4 N  }
% u4 s* ~+ R# p+ A  if(val.charat(0)==","){9 a+ o7 l" l" X. I: Y) u, Z$ H
   val=val.substr(1,val.length);
, f+ I/ O* j- a/ F  }7 s' M  U2 A0 g2 A2 c( p
  opener.form1.frecname.value=val;
  W  I" m, h% d2 f8 w# U$ i$ `: j$ W  self.close();
. I: V1 U4 X% L, P  G( c9 E}: k6 u8 I6 e- D  u7 e
//-->
' K, M4 n' k7 \</script>( N0 _- }: @  i8 P5 b
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
4 m8 y: l9 q, t9 P8 y: |<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
. H7 K2 q3 v4 v1 y. b0 |" E<%
; g2 ?2 N) z7 u/ H4 y" |  cdatasource ds=new cdatasource();  //数据联结bean实例0 ]- l- c/ V7 C
  java.sql.connection conn=ds.getconnection();) Y4 D$ Z' r% M7 }8 B
  java.sql.statement stmt=null;2 K: g( |) \# H7 S* c5 K/ V9 S
  java.sql.resultset rs=null;
" Y" `/ D+ v# ?8 m, W8 E  cdatacheck dc=new cdatacheck();# N* I) Q  v' S7 Q) M) s& A
%>; I2 V8 A# X3 i  ~$ t/ ~& m" o
<%
' o( M8 p4 D, s: ?# q3 j  `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";5 c. ~  v$ X# ~
stmt=conn.createstatement();
4 Q3 C% J# p8 i/ @0 f& j' E3 C$ urs=stmt.executequery(sqlu);
+ `8 m6 {+ A" d2 C( f* O%>
+ F% d! P" q9 v/ m<script language='javascript'>
+ Z, x7 V" v+ Z- R) garr = new array();) w% r3 A" K' c; O- j- t
<%  int temp=0;
' l  R( z; R. |" D8 Qwhile(rs.next())
% H; M% z* I) h{# ?6 {( s/ e* \" w- \% D
%>7 A  K3 k; ?  L9 j! {
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
3 O; b/ A" ?: _5 f  Q) S<%
) K  O. B; g5 ftemp = temp + 1;& Y( P  w" S% U$ z" V8 s
}
9 f1 T9 p3 O( d%>
, L- I: o2 z4 K6 @- {temp=<%=temp%>;
) J% O, c5 `9 \9 cfunction changelocation(id){
! F% g0 p3 a* i6 p; adocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 % j9 Q* c# `2 N- Q1 m: L9 x
var i = 0; 4 e' j# E. t  K
document.combo_box.city.options[0]=new option('-------','');
* Q7 c4 ^* z# J3 [" b* _, }for(i=0;i<temp;i++){ ; i; r4 _2 h. P2 h% Q
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 0 G1 F# s7 i5 F' b+ S
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
: ^+ r" u6 f0 t8 e} # b2 Z4 O# I- C! t) M3 `0 f
}
5 B/ ?7 C: F. J  L  h$ F% F& T5 u}
* a6 T  V8 {# S7 q% `/ d</script>4 w7 G8 O+ c1 n* {- X0 F( S
. l5 k* H9 e. ~# o5 ~& O
<form name="combo_box">; E, m0 a# }1 A- H* s- g$ T; ]7 y
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
8 Q( U: C* M$ p  <tr height="24">/ l4 @+ M- ~1 O! ]! W, f
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>$ v& {9 |) g, T
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>' h! b  V$ E$ Q' O. w
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>: @  d# y& c4 K! {/ Z
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>! G4 ~& b) Z& I, c0 |5 v
  </tr>+ D) l7 v6 R" |
  <tr> 3 Z% g5 ]( w6 j1 m8 Y0 V7 |! Y
    <td>
8 L! I4 Z+ q# b. N  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
2 x% i7 M" ?  d# i  <option value="0">请选择部门 ---></option>" J0 V2 T  z; b/ Q
<%$ p) `/ }7 x" j$ i4 N8 h5 M
    string sqld="select * from tdept";
' H( \- L! i. i7 A7 R! D7 l3 astmt=conn.createstatement();
8 d$ k% ~6 k6 l1 H" C& E! g' I5 P0 trs=stmt.executequery(sqld);! U4 T+ t( w5 N; n2 V- I& g
while(rs.next())
( e1 |7 M; u8 }6 A{6 O* t1 a) J: Y; V& \/ k
%>; d8 g9 |2 n7 Q$ A  n/ V- R" L. f
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>1 C# e& p3 R7 x0 c* x
<%
9 O, k3 j5 L- L}
9 ~( }6 s& ]3 v" t" {3 h7 f%>
" R2 A( p9 L7 A8 ^9 d3 ^( D% e  </select>
; p" T5 F, l; ~1 X# f% K+ p2 K</td>+ K5 H' ?* y/ ~  G+ d
    <td>
6 t4 i: L) [) R) f8 }  <select multiple id=city style="width:150;height:200" class="bgc">
, L) I! x7 ~5 X5 t/ X' b  </select>7 H! H7 O- g7 S9 c7 n# z% C
</td>
: x+ ~# Z' k6 D. P  O1 Q    <td nowrap align="center" class="bgc">
. M( j; y! Y3 P0 ?  <input type="button"  value="<<" class="buttons">0 S+ y1 r, Z% A5 t7 H( C+ U5 ]
  <input type="button"  value=">>" class="buttons">
! U% E7 T$ K1 ?</td>  s$ G& l/ X* O9 Y" l( S
    <td>' X* w1 G9 ?& p- X6 D8 t
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
1 x) q( l6 z1 G  </select>& ?- T* X/ W$ `6 P; \
</td>! l& U: t! Z$ |6 z5 {, m8 R, [
  </tr>3 z1 Z; z% x3 g9 T5 n+ b& s5 c/ y+ V
    <tr class="bgc"> - u+ @/ f8 j! V% U4 r( A! v
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
4 C$ s8 f. M1 E* @9 o  B  </tr>
6 R) a! w. j! }; J+ v</table>
! O$ Y8 V4 U  e; o, \3 ]' ^1 a</form>
: k# N2 M4 ]! j# n! r# M& u. P<script language="javascript">: l, k2 ^0 }. [7 r* c
//人名移动/ X! q5 A. I! u# s% \5 V1 K1 T, \2 o
function move(fbox, tbox) {! w) H% k) Q! w) j; N! P5 L& w
var arrfbox = new array();
" ^- T& f/ b9 r2 _var arrtbox = new array();
& A) C- r2 k; E* I  \var arrlookup = new array();
, \" t- U2 s' Z6 |% pvar i;( j& y+ N% }( [" v% ^
for (i = 0; i < tbox.options.length; i++) {) q% W' |$ p/ h1 f
arrlookup[tbox.options.text] = tbox.options.value;
0 M" R7 R9 @" ]6 qarrtbox = tbox.options.text;; I5 s. ]4 v1 J0 ~0 G7 b
}
1 F: s: P5 s+ [' ^var flength = 0;
' X- @4 R5 \. I; n5 K3 nvar tlength = arrtbox.length;& Z5 M6 A) E. i; e( m
for(i = 0; i < fbox.options.length; i++) {5 I2 Z0 K- e  F4 k  {6 U! d
arrlookup[fbox.options.text] = fbox.options.value;7 D5 w8 B; u6 t% V* K- N
if (fbox.options.selected && fbox.options.value != "") {+ ^' N( Y, P  k( \
arrtbox[tlength] = fbox.options.text;
' O7 ]5 B) S7 r4 M5 [tlength++;! `0 x) R6 ?! v, [9 p* |( B
}2 X9 m; c: M; y) u+ _' g' f0 k% }
else {$ n$ P5 |. z1 ?, `
arrfbox[flength] = fbox.options.text;
' `: {0 ^8 I( rflength++;
' z4 n: r, M( l) z   }4 ^& U( a& @; ^
}
- H+ l% @8 U; `* W6 |arrfbox.sort();
, M+ Z' {0 q. j9 K+ q( o5 g* Rarrtbox.sort();
5 P1 j: _. T! p- N6 S
6 ^6 |0 [! f# `0 Nfbox.length = 0;
$ A, i% i6 c3 t' `) p# Htbox.length = 0;
' T7 ?) N$ ?7 \3 T$ q7 Kvar c;
% W0 F& U+ q" M0 d' `5 z" Zfor(c = 0; c < arrfbox.length; c++) {
7 Y6 h; V0 I! U4 e! U( q1 v& i5 a; jvar no = new option();& ]% s, u7 x! Q8 v5 {0 q
no.value = arrlookup[arrfbox[c]];* z& A7 |- D9 H9 a5 _" a
no.text = arrfbox[c];6 [+ M0 W; Y$ L& x6 _+ A* p
fbox[c] = no;
5 P+ g$ \% B2 j  {; G}
% S! n# q3 X' g2 v& D% pfor(c = 0; c < arrtbox.length; c++) {
6 {4 J  H! y. x: u) fvar no = new option();
  h# H; Z% e, H. |- l5 Z0 b0 o! bno.value = arrlookup[arrtbox[c]];- S! G" e9 x. ~* x- I
no.text = arrtbox[c];0 C0 r& _: ^# B5 z/ V3 O+ l- o
tbox[c] = no;
( F# x7 S7 F- N" v. W   }
1 d) W, N; I& X+ S6 |0 f+ B}0 G3 _- z4 N- w- l7 ^- ?& u
</script>
+ z) R4 M. v% o* Y' _7 x0 P' B</body>
) y9 v- ?* k& p

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