返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"/ B: K0 b+ U) ?' S6 _: b
         c pageencoding="gb2312"
, v; m$ i0 q6 ~4 Y5 O6 x% Q%>/ t7 v2 g+ p- f& @2 ?$ q1 s2 J7 C
<style>: R1 P& z: _, o7 W( H# n1 b
.f9{ font-size:9pt; }& S( B* n  z- p: }# F) h' d
.bgc{ background-color:#aecaf9; color: #0033ff }
( S( r' m& m$ L! w; Z.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;2 P* S2 W7 ^0 }
  border-bottom: solid 1px #4e7dc1;
1 I" T. E- I) i- Z, F  border-left: solid 1px #aecaf9;  Z% P& v$ N# D6 ^9 p2 F; X! A! V
  border-right: solid 1px #5679bd;" {1 @5 z% Z; I
  padding:1px;+ ~; E& V! b5 M$ l
  margin:0px;}" \* r6 d7 G4 y+ J; L
</style>8 `" P& ]4 d& t! c- H1 I- O
<script language="javascript">6 l# g2 S4 t1 s4 I2 Y2 M) w
<!--8 k# K7 P( X5 ~
function rv()
( Y) ~% ]: G5 ]{1 w3 ?3 `8 [$ m$ l* p6 S2 O6 v' p
  var val="";
, \# U: L* }7 i( Z! n) d  for(i=0;i<combo_box.list2.length;i++){7 C6 P2 h$ i2 X: G, p
   val+=","+combo_box.list2.value;
9 m/ u* J& x. t# I! q  }
8 k2 X+ d8 L  O$ G" v$ }% ~8 [" s$ U  if(val.charat(0)==","){, o, E0 ?, X7 z! g- l8 h2 m3 H
   val=val.substr(1,val.length);
& M& q% ~3 d: o2 ~  J& o  }, A' M7 o3 h3 p. m7 X( s( K! v
  opener.form1.frecname.value=val;' c  r+ A; j, Z  E7 x
  self.close();4 l( k! G) x8 J1 K
}
0 R9 q1 ^9 \3 v( B; Y: E$ M//--># M$ v( Z3 {8 Y/ {& o. f
</script>) w* n" O( @/ S( u* F" O
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
0 U3 u! E+ h( H9 n<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
! H5 A1 L) U% y<%* ~, K( H* C* q
  cdatasource ds=new cdatasource();  //数据联结bean实例
- M4 s/ o& O! M0 H  java.sql.connection conn=ds.getconnection();  g. T5 j- _& H& H* {+ v9 i, ?
  java.sql.statement stmt=null;' i2 ]& ~- ]& |- W
  java.sql.resultset rs=null;
; m3 H6 G1 }3 Y1 P  cdatacheck dc=new cdatacheck();# k: K1 r0 r# P
%>
& F6 R3 t2 Y& u; H1 w/ p<%
8 C2 y- V& t) ]( P5 A, hstring 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";# M8 W, Q, K& T9 G- x; N) g
stmt=conn.createstatement();
% v9 a( F$ s2 K- C6 ^; P+ Lrs=stmt.executequery(sqlu);
! K' A; M) h& j# e! {%>1 X0 r$ u: o1 p  i+ v9 c7 U/ D
<script language='javascript'># i7 E* l6 e; I
arr = new array();5 e( Z3 S, x7 W
<%  int temp=0;8 S' n9 I6 n9 M' l) o
while(rs.next())
4 s4 x) F7 U; f9 ?, e{2 G7 v; L5 v0 e1 I7 U( ]8 ~
%>* I3 W% A' {6 Y6 l4 m
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
( Q6 `4 ^; x! ~4 {* l8 o. ^& \<%
& \) U* s0 G4 j" O( k  ntemp = temp + 1;3 z1 F, D6 `9 H
}. x& a7 G8 G  n" O$ U
%>( n& L& I. x. N
temp=<%=temp%>;
1 E. n% @' I+ C' x! k2 {9 s4 P1 Cfunction changelocation(id){
9 l0 c/ G9 F; R; u9 r' Hdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 & r8 \: @& m6 f! y- g
var i = 0;
: L) ]4 E, Y7 x) H- M6 E( f( ]& ddocument.combo_box.city.options[0]=new option('-------',''); ; c: `6 |4 R" v, H4 ~- B! q
for(i=0;i<temp;i++){
6 f: B/ x! _7 d4 X2 F/ pif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] + D$ K  P! x" I) y: F
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);   I4 q$ d. V- U) x9 F1 d- g4 I' v
} 1 G4 s( ~; {; p/ A* V5 W1 j3 D1 q
} 1 o: a7 S) w- d/ \( A" O
} ! V" D, u9 ^: O3 ]2 ^% q  A
</script>% ]; [2 ~' M" L9 W

+ ~1 o& Y+ W( e- w' u! Z1 V, K<form name="combo_box">
" l9 V% B7 j2 j/ x" _9 }+ L<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
) L2 P: j1 c# O  <tr height="24">
7 n, o% d+ [9 d, ~  v# Q% }8 Z  d; m3 X    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
2 ]0 Z0 b- q/ j* t4 q    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
5 a1 r. P3 _! L    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>) p- u: t% q; E2 y7 l/ \( {! `3 N
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
' Z8 w: J9 K8 y8 H- Z% b  </tr># y5 H; e# ^; {; w% h3 B8 [
  <tr> + E: ~8 y' J+ F
    <td>
) C& `; G0 h$ m, u' L; o  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">7 l) N5 F7 R6 F' b8 h
  <option value="0">请选择部门 ---></option>7 O5 |& Q  C5 t: y4 D4 k$ s9 M4 |
<%
2 D5 W) E  g! w+ W" X    string sqld="select * from tdept";3 f8 t1 r0 ?, Q9 n  M/ O8 l
stmt=conn.createstatement();
2 _0 a0 E, E5 s  e7 H/ krs=stmt.executequery(sqld);
% l6 p5 e, a& o8 x$ F$ Mwhile(rs.next())
: c6 H+ T8 I2 O- D0 `8 \{7 @' j/ Q' `: R: x' q# i
%># O; N& f% [% Z0 ?& M# f
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
' Y: K$ u( I; p% Z& Y* W<%8 \$ J' t/ Z+ h) @- e1 |
}, T7 W4 z' e  g/ B+ p1 _6 E9 {
%>
/ \" Y8 \: C/ W. \$ ~, s; C  </select>  j5 Z& r: K3 g! t, \- d
</td>/ b! o1 b6 {  T9 Z
    <td>
- k* i1 H) n; v- J9 E0 y: S  <select multiple id=city style="width:150;height:200" class="bgc">
7 m2 ?& v% B) T2 h# f' |  </select>
0 d* Z2 B1 ^9 e8 n' c' Y</td>9 Q# [6 V3 ?+ \8 u9 u
    <td nowrap align="center" class="bgc">
  [; F  x* Q' @1 Q7 m* I) Y# z  <input type="button"  value="<<" class="buttons">0 d6 X) |0 S, e* n7 A: J. ^
  <input type="button"  value=">>" class="buttons">
& p0 g1 l4 C/ F) ~* ]</td>3 d6 h0 N, c, y- \6 J2 `
    <td>( a- C6 i; Z* g1 [
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
) C! E0 }. k9 v5 g7 G7 P  </select>  s8 g2 [7 \/ @. D2 ^
</td>& Q, P; Q8 d3 T% n/ j
  </tr>
$ |1 P9 ~+ ]6 ^& X! k) s4 `$ b8 {    <tr class="bgc">
$ W0 F- j* d& S    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
: X/ x& F7 N4 a, V  m, y# |  </tr>
6 D6 b/ l- t* H* [& a7 r- e</table>5 e8 m3 W- Z4 P! r) C0 v
</form>, ~! {7 P* E1 Q$ d
<script language="javascript">5 ~; r4 K2 V0 Z) n) R7 T( l4 l" U
//人名移动
! k  |: P. E) y$ M2 v* H( r/ e% Kfunction move(fbox, tbox) {
7 k* c- k3 j0 Kvar arrfbox = new array();  e5 X$ U; r& d, R1 h0 e. P
var arrtbox = new array();
6 R# V) W& f) ]var arrlookup = new array();  X' k* Y) _6 P0 ~& G. q! H8 {7 ~
var i;
# I, y- d. R7 \7 @6 L- Vfor (i = 0; i < tbox.options.length; i++) {
3 |0 J- p6 Z. w4 q. R, ^9 jarrlookup[tbox.options.text] = tbox.options.value;' [! Z  i& @; y( a# M2 ^+ {
arrtbox = tbox.options.text;8 d9 Y) \( ~( y) q* i8 E
}
4 A" H' J& C; pvar flength = 0;
2 K3 e( ~# Z! y+ q, G, X* Avar tlength = arrtbox.length;8 b; w; D; I" P/ t% z. E
for(i = 0; i < fbox.options.length; i++) {  ?9 `+ L, H8 @, l& v2 o
arrlookup[fbox.options.text] = fbox.options.value;- P2 k# v) F$ Q
if (fbox.options.selected && fbox.options.value != "") {% F8 l5 O/ @  {+ Q6 ^
arrtbox[tlength] = fbox.options.text;
. q9 M# v) Q$ p* }* u1 w$ ?tlength++;
) I2 Z, {" N+ a9 K3 `; _}
* J4 g. N. F6 s: Qelse {  c" e# u8 ~" }* ~( s: Y: l# G
arrfbox[flength] = fbox.options.text;' R, a- @+ h9 t. r+ V) `
flength++;
& b$ ?; I3 J3 T" T$ l   }+ b  m# g9 Q; |0 p8 l; t
}
1 ~/ H: f# s0 Y9 m9 G4 j" @arrfbox.sort();0 C' P/ R; G* t" Y9 q/ V5 C, @
arrtbox.sort();
( U. k9 H6 [) h) M" ?; H4 s0 `/ E) C7 ^. p% d2 ^3 P! C
fbox.length = 0;/ }/ p8 [3 O! u7 z6 E: f
tbox.length = 0;
/ g! `' ]) M% h' U. ~# a4 ~var c;$ y  x, X* L2 e" @: U1 y8 w
for(c = 0; c < arrfbox.length; c++) {
: i; h) _' D: j" V" Xvar no = new option();
2 X$ U- z0 [+ Bno.value = arrlookup[arrfbox[c]];
0 ]+ X3 t+ P0 Y: Dno.text = arrfbox[c];8 W! ^9 B: p7 t' T3 I# {  @0 \
fbox[c] = no;. |3 j1 ^& s0 G9 w! y
}1 J: a5 N2 U; I% g1 h( Z7 M/ \
for(c = 0; c < arrtbox.length; c++) {
) S/ ]! v$ Y" {8 t$ Ovar no = new option();& Q7 {( n7 {8 G+ v
no.value = arrlookup[arrtbox[c]];
+ s/ i1 S: d, z0 Q, fno.text = arrtbox[c];
. G3 J7 [1 h$ z( P$ ^+ p& v* Btbox[c] = no;
- X! l5 s8 E1 |2 x; V   }
3 H* m& _3 V/ M& k7 y9 p* ?) `}0 r$ g/ \6 a! }$ b6 W0 H1 }
</script>
1 V5 h  e8 `" B</body>
2 [' e" p5 M0 \. i0 p

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