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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
7 k+ b! v4 j/ E4 d9 q* c, D3 R& M         c pageencoding="gb2312"( T( `* h  C4 k" t2 Y6 v* J; t
%>
# `5 W5 F$ }# P$ y<style>7 C. o2 F9 k$ P! Q
.f9{ font-size:9pt; }
' z  Y3 v, p2 ]% T.bgc{ background-color:#aecaf9; color: #0033ff }
' T; V8 x( W1 h. n0 B4 Z: a; V.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;% \2 j' x4 l3 e! p
  border-bottom: solid 1px #4e7dc1;
# c* p$ o2 k7 r5 }( d- j  border-left: solid 1px #aecaf9;& I) `" n: @* p% \! g+ ^& a
  border-right: solid 1px #5679bd;& q4 v) D. H* E+ J3 s
  padding:1px;" f* f  n2 K, M& T7 p4 g  }: J" X
  margin:0px;}
: A( G1 u& G& H7 H: l</style>5 o9 @6 _0 ]  C- z+ v$ o1 y
<script language="javascript">
1 z6 b% z0 A1 v+ ]8 F<!--
* L+ x  ~& R% V% E3 zfunction rv()
8 @7 T1 O; O! }3 I# u1 }{
0 }6 X/ E  ~8 _/ e  var val="";
  F, H- v( J5 ?: e( G* Y  for(i=0;i<combo_box.list2.length;i++){
9 E: _$ o! j& T3 T1 R   val+=","+combo_box.list2.value;
- R" H8 @' A; e2 w  }% r1 P3 S  p6 ?1 r
  if(val.charat(0)==","){
  t7 Y6 M. F# w  Q0 O/ @( _  v   val=val.substr(1,val.length);
# \& K8 l9 M) R- R4 |  }
7 @2 @+ Y% T! j$ j  opener.form1.frecname.value=val;
2 h3 ]$ u) a) ^# H  self.close();
# y2 E" v- I7 K# I' M' t- [* f}
! ~) c( k& [/ v3 {0 r; h//-->& |" v+ Z" d2 s9 {' b- @" S  K
</script>
% n1 n: Q; w) e7 O<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
* Y: p5 u2 i/ g/ f8 o' J9 m7 D<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />2 \! Y9 T  J. S! x1 f- r
<%- l  L! Y1 i+ W
  cdatasource ds=new cdatasource();  //数据联结bean实例1 l6 q- t: Q* Z( Z! Z  S$ @/ L  D, I
  java.sql.connection conn=ds.getconnection();
- P# D" n1 F" V+ ]+ z, B  java.sql.statement stmt=null;- K6 V4 w& [5 t5 Q
  java.sql.resultset rs=null;3 C3 A* z* r2 e& o
  cdatacheck dc=new cdatacheck();
- E  `- k( f  q8 Y0 K, {, A! g! P%>
: {' l: v, j" G% l! U<%
* V/ Y5 N8 [) M8 Q' v% \$ Zstring 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";
6 b& H% K, Z1 s. x% _$ H2 astmt=conn.createstatement();
3 ^1 b" e/ Q4 r1 ^rs=stmt.executequery(sqlu);
; i$ h/ g# R5 z* M  @" J) Z9 v%>! I, M4 [7 \9 M+ g$ i7 }
<script language='javascript'>( Y2 f9 f- X! m9 m
arr = new array();
4 @1 @: A1 i2 S4 o<%  int temp=0;" H8 `) }9 r  N5 j2 c
while(rs.next())' F& P, |8 E- c1 Z) c
{( B" W! Z6 X2 R/ H
%>3 W( {! n8 _  Y5 @' v- i$ V
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");# \: [( u7 ]1 R6 ^; I" E
<%  H7 o7 G$ Q& j* V- Q
temp = temp + 1;
* p- i9 H" W* B! v1 B}4 g# S% x; L4 H* x9 p
%>
6 X! o6 ?* N6 R& H& W5 n* ftemp=<%=temp%>;) j4 C: B# k5 |6 f* }5 c8 W# ?% J
function changelocation(id){ 6 K+ V/ s, V. I; M. ?+ O
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 2 ?' \7 r* s  s# W+ W. j- ?
var i = 0; + [4 g& Y8 M+ V5 Y
document.combo_box.city.options[0]=new option('-------',''); 6 K& |8 q- _3 u& F3 Y+ q* {
for(i=0;i<temp;i++){ ! ~6 ?, {; G9 `7 C( }& f. ^$ G/ ]
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
5 @% e6 h8 w, _: X4 i) i3 l9 ldocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
8 ^) w+ D- V% ?4 q+ |- h) \} ) z6 v$ A; M' w) @
} 9 ?3 v- @, k9 J5 ?
}
$ z+ s/ O. w9 j& Z) S% _: `</script>: b+ Z3 b/ G) [. G% a

0 {: ]% i* O, p<form name="combo_box">7 |! N. R# w  I# W
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
, R) p& A( ~+ [1 O/ N' ~  <tr height="24">
3 u2 a+ m# T4 a; U) \  \    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>: l8 k# j" ^0 W6 `; e6 z
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
$ H& V2 P7 M2 S( s    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>2 n' j$ D) p, k. S
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
. L/ O  g) Z$ b! i* Z+ z& f' [, B  </tr>
" A; a( J' q# ~7 ]: {; A  <tr> $ J% @, K- H% x& p: f
    <td>( K; B) s1 E* B. {/ q! ?
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
) K6 P$ R- M3 Y4 F- R& V6 a( ]  <option value="0">请选择部门 ---></option>3 F) ]4 c0 }: K% ?) V& m3 l, q
<%
- q6 p9 u: N2 n, J2 N8 L- u, K; {" B    string sqld="select * from tdept";
1 v) H! O8 Q4 X& Gstmt=conn.createstatement();, U7 x5 ]# p' g. L( F
rs=stmt.executequery(sqld);+ p0 T9 u" {  F8 w; N
while(rs.next())
  m( V5 c3 J) K9 n  U$ }9 T/ P& q7 v{3 x  g- G9 z0 D! U9 g; f
%>
8 R0 f# s) K* T  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
( |% x+ M' d! @* t<%
; Q) |$ M' e! z% s}
4 s. J* ?/ n8 _9 D%> % @; X2 d1 ]/ n" F6 J1 i
  </select>2 R1 q" S6 y4 }2 G+ e
</td>' ~" b, T8 N/ j
    <td>
+ q- J) _% ^$ ~9 j4 v  <select multiple id=city style="width:150;height:200" class="bgc">
0 ], a3 d1 |3 C; s  Q# V2 k  </select>
1 V9 o! f8 b4 F0 N$ @3 }</td>
) a3 e1 s; x; @% W  z+ S* k. W! Q. p. `    <td nowrap align="center" class="bgc">
/ J8 c' a7 A4 [/ M2 n  <input type="button"  value="<<" class="buttons">
% D8 z' |1 I+ l* ]  A  <input type="button"  value=">>" class="buttons">- T0 r1 G. M. W+ X& x' T& V
</td>
6 E+ F3 {; r& d) x6 [2 l9 w3 L* B/ Z4 }    <td>
- ?' V/ V, o) N, J0 {$ E& K' \. y8 Z  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
2 x) |7 g7 r* K7 a0 t( a' d  </select>
* p# H: O& f% a' i</td>; G! N$ Y- L1 W6 ?
  </tr>
; g; M0 R8 ^$ k: _    <tr class="bgc">
: Z4 E) O: g8 ]5 x4 X2 @    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>" y% @! F0 {7 h0 @8 @
  </tr>0 d. C9 H5 P# f
</table>) g8 P* q7 u' H) [7 G
</form>
! H1 n" Z2 |, `& r2 Y  y<script language="javascript">7 R5 m$ [8 ~, Z# j& P% ?4 ~# I' |9 h
//人名移动
; M, {9 \% ]8 G0 t0 hfunction move(fbox, tbox) {
' R: f& j. E3 bvar arrfbox = new array();
8 |/ v0 U/ ~) d0 J, l7 r! dvar arrtbox = new array();
& w: x# }) n1 ^- D! f! \: @var arrlookup = new array();
$ I% d7 J* q7 Q  W, ]6 F6 dvar i;* D8 B$ b7 {. Z" E
for (i = 0; i < tbox.options.length; i++) {
4 z$ U# x' ~6 P/ ?arrlookup[tbox.options.text] = tbox.options.value;
- x% b& V1 }3 B, {$ u5 narrtbox = tbox.options.text;
2 ^+ F# B$ R; F' I}
7 z9 ?. T2 w# r9 M) _9 M' cvar flength = 0;
* o5 ?: |9 s% h# s4 ivar tlength = arrtbox.length;9 d) X1 n' S  z) H* M& d. g3 E1 z
for(i = 0; i < fbox.options.length; i++) {; @: E, q( `6 j( n" C' f; M: j; C
arrlookup[fbox.options.text] = fbox.options.value;4 |8 r# V0 F4 _. t- b) j% X5 j
if (fbox.options.selected && fbox.options.value != "") {; L/ g0 k5 e1 B+ y3 L9 F
arrtbox[tlength] = fbox.options.text;% J' i) @% w+ m7 F2 m2 y
tlength++;
: \1 s9 J; ]0 R7 b  K4 I+ ^}
4 p; p6 Z  x# E5 W% relse {% v+ I+ ~! N* O3 F! P  H  T1 P
arrfbox[flength] = fbox.options.text;+ _/ u: d+ b: z& x! y
flength++;6 c' v" N3 m0 r) Z5 C7 {* G
   }+ Q, @$ J2 C: E. @
}) d3 A3 K1 O: t& r, T2 F2 @3 A% o
arrfbox.sort();* P) Z1 N' a0 v1 P  i, n* B9 y& q
arrtbox.sort();  L/ F  x: F# u5 \% j
- R, l9 H7 V* Z- |# {+ y3 H4 t
fbox.length = 0;
% {" O& a1 M5 Utbox.length = 0;
. ~/ @- Z  Q3 q, r" p- U2 Bvar c;( K" H8 V+ S- T* ^
for(c = 0; c < arrfbox.length; c++) {) x, r0 |( Q) y4 o& B
var no = new option();
5 _' m: R9 M/ R, Z) tno.value = arrlookup[arrfbox[c]];. T) o8 T( S& n
no.text = arrfbox[c];
9 W2 o0 _3 p  tfbox[c] = no;
# T) @' d; Q; c, u# J, w8 ~}3 \% P. W3 ?) I8 e5 n: t) a
for(c = 0; c < arrtbox.length; c++) {
/ g+ Q5 Y, r+ B7 c/ Vvar no = new option();; n' z! q$ ^2 c
no.value = arrlookup[arrtbox[c]];2 n4 K3 `2 H" S' E. |* L* F! ~
no.text = arrtbox[c];* V) P! o# o5 ~# q% n9 B! @
tbox[c] = no;
4 q- H/ V: ^6 x! i; `% L1 s   }7 a! W& S5 Y" L5 ]
}( A" d5 n) e1 \* z/ y* B3 {
</script>0 a# c1 p/ y2 o
</body>
" F' W: b7 ^- X" I

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