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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
6 k2 r! T0 @5 q         c pageencoding="gb2312"+ ]4 l. n4 N! _& B9 ~, d$ ?
%>1 S' y7 k9 ~# f. h) j' y
<style># ~7 l$ T1 v. `, O7 o4 x0 Z
.f9{ font-size:9pt; }' K% J- D4 C' `$ E* K
.bgc{ background-color:#aecaf9; color: #0033ff }$ S* V7 ^( x8 d+ w
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;: \  e  F2 d# a: |. @; S# [8 X9 N
  border-bottom: solid 1px #4e7dc1;% o' |  I9 D1 k3 i( u9 G9 b
  border-left: solid 1px #aecaf9;0 [6 O8 l7 O! W" i, |! }
  border-right: solid 1px #5679bd;
3 B" Y4 i6 o, y  padding:1px;3 w' K6 t+ R& D8 S
  margin:0px;}
& f# a, ?0 i/ l& \* o</style>
! V5 V9 Q& W2 g! v6 X5 C4 M<script language="javascript">, s6 n3 b1 ~6 X
<!--
" H( A! Y; U- l; N$ [function rv()% c) n  @! c' E5 P, D
{
- m: w. {! C2 j; B& X9 u+ p  var val="";- O: L! E8 Q2 f
  for(i=0;i<combo_box.list2.length;i++){
# G  j! ^2 h; l8 d* \! z" m   val+=","+combo_box.list2.value;. D4 y  C# w* Y$ R0 O
  }2 l" z* T* g% l$ A7 T
  if(val.charat(0)==","){
. M5 I+ b( M6 l8 G4 A   val=val.substr(1,val.length);8 c/ _8 i1 K6 j7 j
  }
& z' h$ W" i" `. t4 E0 j  opener.form1.frecname.value=val;" p* P7 R1 ]0 `7 @5 I9 A& R* L; G
  self.close();, z3 t; C$ J2 f
}
8 I: X; l. }1 R! G( A* y; Y5 o//-->, U2 B! Y. e% a* [" k& g, b
</script>
$ a+ h& `; Z* f0 g* K/ {+ _<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
& j  s$ e# }& f! F4 L# z<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />6 ]7 d* V1 X5 I9 ?& P- \
<%
1 D( x" m# T7 K, e7 Q0 R' y  cdatasource ds=new cdatasource();  //数据联结bean实例. }  L$ h! y7 s9 h
  java.sql.connection conn=ds.getconnection();
1 L# ~/ }( c( f0 `! _  java.sql.statement stmt=null;
( B; ]% e: Q, R7 V% ^5 i  java.sql.resultset rs=null;
. k* H$ o/ F; o( Q  cdatacheck dc=new cdatacheck();
1 i* E7 G( P8 P: O" G- A/ K%>' D" c/ l7 E5 w3 T- }
<%
% @0 v* H* b$ R8 Y' |) Tstring 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";) Y  \8 _9 b- q
stmt=conn.createstatement();0 ~$ H- w9 B; v
rs=stmt.executequery(sqlu);
9 v7 t( P( @9 V. k%>
- |  U* }! c* Z: [$ A+ \<script language='javascript'>
  T7 Z: d. I, X) V* d% darr = new array();
" G$ n* \( C6 @- ?$ u<%  int temp=0;
0 J' H9 p: [/ F* ^; C, h, Q5 Xwhile(rs.next())
" }& m4 _& \8 A, L5 r' I4 S{- d- w7 g/ s' w  U
%>8 [0 r3 M. W& n3 D( h
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");2 s  s0 y: E" D, Y' H
<%0 w2 e+ |5 O$ M( {( ?5 h* D# [
temp = temp + 1;7 M" S) [2 A1 n9 }7 T
}
1 r* j, a% d1 b8 c8 b. v5 o4 h: }6 y%>
0 R5 {; N4 q2 q9 stemp=<%=temp%>;
, n1 o6 Q: i1 J$ efunction changelocation(id){
, R0 _3 I/ L* D) Zdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 8 F8 o6 q: B' _, Q$ N
var i = 0; : b3 {4 h8 J5 t2 F  L! O
document.combo_box.city.options[0]=new option('-------',''); 1 O6 E) L0 C& j( [
for(i=0;i<temp;i++){
+ e* I9 s6 U$ \$ m5 x6 P4 e4 Z0 [6 lif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 2 R2 \  I) \: o1 B
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); ( L" f- K! {4 q: G% i/ \' @
}
  `7 p; D# t) n7 \}
: _, s8 H7 [  D# N} 1 t/ }6 J7 R2 K0 n' N% i
</script>' d% {& Z9 M2 P+ }
3 N1 v0 W8 n" x. w1 ~9 J8 g
<form name="combo_box">3 E" K) n- g+ u! U0 u1 y, h- T2 `4 n  h
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
1 T- P/ D1 x2 u) S' c5 _$ T  <tr height="24">
; k( r5 W1 C" j3 u    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
- v* T5 W8 @: Y8 G) M    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
! N6 r1 E1 |7 L/ _* G    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
# l" C0 c3 z# `- i$ r  P8 l    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>3 H! c0 |. _' w, W
  </tr>
) }: X4 ?2 t, g* M+ b3 g  <tr> 1 @3 D) E8 y6 b- s+ r+ a/ L0 \
    <td>- v$ z2 \6 D. ~0 X0 y
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">$ D. N  g% N; E% h, W$ b# |
  <option value="0">请选择部门 ---></option># B+ ~( x* E' [; I
<%7 C1 U( n* k' [5 w/ |0 p
    string sqld="select * from tdept";  f/ u" h% q- l. g4 `
stmt=conn.createstatement();
! s4 F  n6 q2 f9 ]/ Q  N5 Prs=stmt.executequery(sqld);
3 c- w$ u2 ^! _6 y% I( Wwhile(rs.next())
; E% L) y% S7 [& l  P{1 N( S$ L: x4 d/ q
%>
4 q( i  K: c" q  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
" \$ L! S. }( t<%  Y5 z" K$ m1 ?0 f3 ?
}" T5 _& }. u3 t4 W, C  C8 T6 H
%>
& P) u$ f0 P1 O! r. e  </select>" m) F, a3 Z$ u# L
</td>
( Z% J# V: m; p" d+ N    <td>
7 T% J+ G; @8 q7 w' K) L7 a9 D  <select multiple id=city style="width:150;height:200" class="bgc">
2 Z# e3 H* z* L& @  }6 J6 n  </select>
3 t! d% @% _4 p</td>* j+ ]$ L5 s* u2 [) R! l5 U
    <td nowrap align="center" class="bgc">& j) g3 Q2 x+ j/ R: `4 W  v
  <input type="button"  value="<<" class="buttons">
) o. X9 ?  U9 j. l, N% b! z6 Y( Z  <input type="button"  value=">>" class="buttons">
( O) H9 f1 s5 N1 z</td>
( t1 h% J- b& J    <td>
; I: s* y; a3 F+ _3 M  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">! c: l: D! h$ `- T/ F) j6 `6 ~" |: L
  </select>
& E3 q8 g, ]+ \2 @# h' e</td>1 A6 f& x( p- u
  </tr>7 U( Y$ s+ B; _$ H8 V# v* e
    <tr class="bgc">
0 Q2 I; s2 _3 z+ M    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>8 @# C, s' T( i; \: g" O& k3 k
  </tr>, U; K# i; Z% B: e% T- i
</table>
  ~) V  r" v, g$ w</form>
/ o- S: x% c+ N9 I- f<script language="javascript">2 z3 C" V, c& Z; T- p+ x0 N1 A
//人名移动
4 ~( R3 s* j+ R5 t+ p& Wfunction move(fbox, tbox) {1 Z7 G% a3 W' P- W3 l
var arrfbox = new array();, t/ n% J9 p+ k4 d) q+ o/ v
var arrtbox = new array();/ J: o8 J6 Y7 Q
var arrlookup = new array();4 C3 v2 r2 `! ?7 e
var i;
' ~4 Z- y" q9 F) T: L, x) ifor (i = 0; i < tbox.options.length; i++) {$ t2 f2 N& U: T, ]: `
arrlookup[tbox.options.text] = tbox.options.value;
- s5 t  S' }0 m1 F4 Farrtbox = tbox.options.text;  V! u( ~) {' s7 q7 _) \% t& o
}2 ^' x, t8 t2 L% g, j) R
var flength = 0;
. G1 t6 C; `# X. _var tlength = arrtbox.length;# D- N0 W2 P$ ?3 ^% ^( F
for(i = 0; i < fbox.options.length; i++) {
* i$ W% I) P$ L# `arrlookup[fbox.options.text] = fbox.options.value;
) a5 F" H: K8 d5 c6 y/ Cif (fbox.options.selected && fbox.options.value != "") {& W' Q5 F' L! b1 E* x. {# p8 F! w
arrtbox[tlength] = fbox.options.text;; i" f: Q! t5 ~' E9 c6 ?
tlength++;
1 D( {2 S) y# C}
- U$ K+ g/ m" V3 J4 Y4 Pelse {
( F) U; K* r8 c6 n' |; ~  ]arrfbox[flength] = fbox.options.text;  G2 b5 \1 c, d* g4 M1 {* T
flength++;
; L' x- _. m: M% g  y   }, N3 T! o8 }, @! b* U7 ]4 M' l
}- H3 e8 w6 T, F/ l8 n, g* \0 V
arrfbox.sort();- _  c2 V/ L0 p% _7 X
arrtbox.sort();
5 E8 H( T4 _( S5 ~3 x
. l9 R. A6 ]6 r. @# k4 R3 xfbox.length = 0;8 J" L3 F; s* {/ P& c
tbox.length = 0;
9 n* _, I* z! |# t9 z% q5 `6 ~4 Tvar c;
0 Y3 N- F$ B" y0 U9 f2 rfor(c = 0; c < arrfbox.length; c++) {
: p! _1 I% c0 Y  z( t  i- y& j& \var no = new option();7 J3 u4 x' [  ^+ c
no.value = arrlookup[arrfbox[c]];
" ~; v0 }, d( c, ]no.text = arrfbox[c];
+ O! ~0 d5 ~5 @0 c- {fbox[c] = no;  p8 c& O: X0 t" c( I1 |
}' R$ \. Q& k# z: }2 y! e
for(c = 0; c < arrtbox.length; c++) {. x' ^( S- S& |; y0 G" F
var no = new option();, ~% u) w& ?5 [
no.value = arrlookup[arrtbox[c]];/ }6 y: k+ o* \7 I  N
no.text = arrtbox[c];# N1 ]& s/ b! C4 ]% m  V
tbox[c] = no;
8 Q+ L  E8 z$ T, l3 _   }3 _; v8 A& x; C
}
4 a( u. r0 y! ]. x  B, ~! B; U5 h/ [</script>
# w1 W# E  M8 B( `% R, T</body>6 `" R. K# S9 t

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