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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"$ s' o4 K  Z" h2 D" R% M
         c pageencoding="gb2312"8 X1 C5 m9 E; m' R3 C) f, ~
%>
8 K5 `: x' `% P" o& C$ L! O2 u- q7 W<style>+ X/ c! A& V' B8 v0 x0 [3 m, H$ c" Q
.f9{ font-size:9pt; }
& B  {1 @+ c$ p! z( }/ X.bgc{ background-color:#aecaf9; color: #0033ff }
0 T- N1 O7 n! T8 M.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
# Y$ w! b/ ^, \8 `4 e/ L  border-bottom: solid 1px #4e7dc1;
, ?* H+ P6 A4 h# m, }6 r  border-left: solid 1px #aecaf9;
0 b3 _  A& r' r; B  border-right: solid 1px #5679bd;, b1 m, Q+ e  S. H2 {
  padding:1px;
; C$ r0 e  E7 n- q: a5 {  margin:0px;}! E3 {+ o% v/ d9 ?9 w0 x- I# `7 `
</style>8 t9 e8 I% T8 o  Z) I
<script language="javascript">
; o# t- ?/ P  R7 q; u) ?<!--
1 M+ `! C3 G# e! t/ X; N2 @) gfunction rv()5 m  Q9 _4 ]. w2 H; d
{
" j0 v# A/ o' `  var val="";3 D7 H, j6 p$ C* s8 r
  for(i=0;i<combo_box.list2.length;i++){& b! q9 b- X- n) W) I( z# d) v
   val+=","+combo_box.list2.value;
) s, t2 R* G' D- N& l+ _  }
" G) }) n) K3 |1 H0 W4 d8 v! M  if(val.charat(0)==","){" r3 N8 Q) D( q  L1 I5 |1 A. n
   val=val.substr(1,val.length);$ J7 q3 p' S: G4 F
  }
4 [8 C2 A9 @" \5 j- B: n  opener.form1.frecname.value=val;
0 z, j. D/ L# b3 R  self.close();
2 N4 s& F- L1 R}
% o2 U! T3 k# B8 k" v//-->, Y8 \# l- N# v+ j( e! L  X
</script>+ N" d! Y! b3 \2 b0 G) H* {
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
- X7 [" s( Y1 @/ w, h<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />" t9 p# X: X# t
<%
% h7 Z8 q5 s( \. O" m4 X! S4 ?! _  cdatasource ds=new cdatasource();  //数据联结bean实例
% X- B+ |9 b5 n! r  java.sql.connection conn=ds.getconnection();5 N* B7 D* R* `! }' E- ]% F
  java.sql.statement stmt=null;" G" ]% p/ ^$ \& k& E2 K
  java.sql.resultset rs=null;
. {% K. d8 i+ w/ j# U  cdatacheck dc=new cdatacheck();
/ I1 L+ \+ R' u5 x, b0 L/ ]# o: @4 w%>7 e. G; x8 p/ @1 i
<%
4 u2 M  Y9 F" y- K% c+ D7 O/ t8 ostring 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";
8 l) M, ]# P  W- n$ Xstmt=conn.createstatement();
, f3 i2 G4 c5 C( s, ~, d. P# crs=stmt.executequery(sqlu);
' Z' |1 v! d2 A, H# [%>) O7 Y3 R! a1 |; ]* j0 `6 @! e" {& \
<script language='javascript'>. }) c! B7 U+ y
arr = new array();
( ]- Y3 |; A# f+ Z' \: p" u<%  int temp=0;
) O- D8 {. n0 Q: h* W7 m% gwhile(rs.next()), n3 Q( }9 w: A
{/ }' F) U# ~, S# R& h
%>
* W9 s! G; V( K3 l; s7 Yarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");4 D( m, h! X2 G5 W8 d/ C. ?: c# ^
<%
5 }' s+ E& M% C: P) g" W& itemp = temp + 1;
5 ?; i+ `% y8 i% |' D7 V5 C# u+ G}
- _" s/ `* N& b4 }7 F" ~  g. E. C%>
' K' G( F1 f5 @* c2 ftemp=<%=temp%>;
8 }- z' V4 ?1 m# j; h6 yfunction changelocation(id){
+ B6 H2 K6 b5 S, c$ ?! idocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 % k. k/ p: i4 k
var i = 0; 0 e* m9 `2 i  z1 `# B1 E+ t" x
document.combo_box.city.options[0]=new option('-------','');   E' J- y0 ~" z5 t
for(i=0;i<temp;i++){
: v: V: J! i" @6 z) U2 b% Y1 sif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] $ u; O! P7 Q% @* k2 ?
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
4 g5 Y( i0 \' |. e} 1 B  o$ {- W- c, M1 O0 E1 |3 T0 \
}
2 R: C6 D0 ^% F4 R& V; _} 6 ?# t" \1 Z9 a! q+ m$ K
</script>% R  o' q- u6 G* j

  O. }* H" e2 c7 |. N/ |<form name="combo_box">, n/ C( J: u1 R  O- v2 C2 K
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">: [/ B% W1 h- A9 \3 i
  <tr height="24">% H3 P  w( a& y+ i
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
% X* U; X2 E- P1 t; o/ C6 P4 k+ a! C    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>7 L; [% @% v+ `) w0 K
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
( ?; X; n9 C( D0 x, Y# W    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>& v% m6 I& A- k+ M
  </tr>
6 U3 L! I0 i' [. r9 i2 @9 s  <tr>
4 g) `$ ]# @/ O. I1 P( k# c    <td>6 _- L7 _1 X" e% h! g
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
9 {; r6 @. C- A; u/ ?  <option value="0">请选择部门 ---></option>
4 o' K$ N  B* f! b5 a+ S<%
4 Z! v9 O1 s* S7 A, ]- u    string sqld="select * from tdept";
3 x- e! K6 u8 }0 ~0 Wstmt=conn.createstatement();
& ]7 b) |: n3 z  C8 R* s8 prs=stmt.executequery(sqld);' ]0 Q. j' w3 `. E( J* H
while(rs.next()): I# D$ N& h4 d: X
{
' L* c; ]1 Z# Q$ G7 g0 `9 v. p9 T%>. T7 W. k6 ~2 _" k, H, P/ i6 S& X
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>' g8 m" B) l  |% D: G7 w
<%# W+ ^$ A1 U% m9 k8 n
}
1 Y6 v: z1 b2 I, k5 M; J2 n; c# ?%> 7 e) j. L2 ?: A0 A. y6 A
  </select>- n4 V( ^3 R9 O( t- g& H
</td>3 N( \9 U& S6 b" @. W0 X" a
    <td>
2 |1 B) M* d' p2 l  <select multiple id=city style="width:150;height:200" class="bgc">( u0 Z+ s) F6 r2 [- J& G
  </select>/ I' l) a& Y9 \4 c  L( q3 E* z# q
</td>
' |4 r# a- ~7 s, B    <td nowrap align="center" class="bgc">8 J+ y* g2 R  e# O- f- D# J' s
  <input type="button"  value="<<" class="buttons">8 m; d& R! }/ t6 E6 K' |0 C: A
  <input type="button"  value=">>" class="buttons">% C% e, `2 e- y/ D: v6 E- k# C
</td>+ u+ `- R0 U1 B4 |' q* u
    <td>
6 |& t& i- z3 n/ q' [  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">* N$ V$ q. l8 ]' e
  </select>$ q0 L3 c+ P( ?: K) r' A" {
</td>1 d9 c! {# G3 E7 E, D1 N' I) J
  </tr>2 d) g. r% m) y4 ?/ r- ?" H
    <tr class="bgc"> % s: ?/ ]0 R5 \
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td># ?! E. E. w5 Z; M9 B
  </tr>
* d. O: u* M( v, W</table>
& L: R7 X$ S" W</form>/ C4 A  M! X$ y( j: K/ S
<script language="javascript"># Z' V) d0 J' v
//人名移动
, D4 r/ p; ?( R$ P( Hfunction move(fbox, tbox) {8 r1 L0 `9 T# n6 T/ @
var arrfbox = new array();
. [/ {5 s. F6 T8 h) F4 Gvar arrtbox = new array();5 }! X. Y7 ~" F: y/ \: l
var arrlookup = new array();7 Q; _% F2 o- Y% D" C) M/ M1 ]
var i;. |# g: k* b. G5 j
for (i = 0; i < tbox.options.length; i++) {
, F) O- k  k6 p7 U: oarrlookup[tbox.options.text] = tbox.options.value;
) [9 ^" y' z- X% Q3 g$ Iarrtbox = tbox.options.text;
/ |. h6 N0 ?4 q7 |4 w. _}
4 R  s. M$ L' }/ M8 `3 }4 i' ~var flength = 0;
2 t5 v2 Q7 V( |5 v2 pvar tlength = arrtbox.length;7 \& A  W/ J7 O, p
for(i = 0; i < fbox.options.length; i++) {) _) B% x7 ?" m1 ]9 z
arrlookup[fbox.options.text] = fbox.options.value;) u) N- T1 Y+ j2 L' O4 C3 a5 n
if (fbox.options.selected && fbox.options.value != "") {7 o) ]3 `. |5 `. {5 L% P# X
arrtbox[tlength] = fbox.options.text;
2 G4 g+ x- U, W/ ^tlength++;) z& _% b0 D9 \  m& W5 W% ~
}# z' I( Q/ T3 w( k$ t
else {
/ W2 a1 y5 z( varrfbox[flength] = fbox.options.text;
, ~7 W4 Q' g! g9 y4 Nflength++;" A( {; i0 c, Y, W6 Y8 t
   }
3 C$ V/ ]9 j+ J- L8 n) O; k}" D# Y- j/ T) C
arrfbox.sort();% |* [7 m1 ?4 X0 n
arrtbox.sort();/ o# \4 x- p6 {( a- ^3 s

0 x( s! }( O/ D! Tfbox.length = 0;
, ?7 Y! _% L5 T& I) Y+ ]: d. _tbox.length = 0;  t( c5 q' B8 \- v) I0 D7 c. f
var c;
7 ^! g+ N2 N1 \) `+ D1 Tfor(c = 0; c < arrfbox.length; c++) {
0 e! j# Q& _/ d4 }. X: h# dvar no = new option();& X. v: m% F, u
no.value = arrlookup[arrfbox[c]];
! D9 V' a6 `, }9 S0 l3 Qno.text = arrfbox[c];
5 V, l3 f4 w# y$ G: Gfbox[c] = no;( d! T  `" {0 q, K
}6 F9 `6 a, I4 i$ q7 S( ^$ V* r
for(c = 0; c < arrtbox.length; c++) {
& I" ]! }" G. a4 F4 @; n- p+ Jvar no = new option();+ ?& A7 j5 ^8 c# }6 c7 j# x
no.value = arrlookup[arrtbox[c]];
' ]% h+ C% j' @1 u: Y% `, Sno.text = arrtbox[c];
- E; `5 e* D6 g$ c' N, ~" b& @tbox[c] = no;
* _8 e7 W$ ?$ A( K8 {' F   }
: k& C0 h3 K  q$ `$ l}
' n+ S  t$ [3 |# e$ J4 L; r2 x2 _</script>! j, C* \: ?! ^2 K& z+ C, h
</body>: _6 d6 t, k% r  K

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