返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;": j- H- F5 _. x1 A4 ~3 A) v
         c pageencoding="gb2312"
2 j- X9 O- N5 w%>
" `% F5 d5 c$ f1 @9 _<style>
% t$ e/ n" u( L) f" ^.f9{ font-size:9pt; }# P+ g% c/ X5 f% E5 |- ]5 C
.bgc{ background-color:#aecaf9; color: #0033ff }
) N4 g; T) B2 f7 j4 H.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
, [2 Y  T/ j. Y" z  border-bottom: solid 1px #4e7dc1;) E; |; h. L2 {& d
  border-left: solid 1px #aecaf9;
: F1 r/ d- }7 S1 o+ b  border-right: solid 1px #5679bd;
/ W9 V% R# r; z. F  padding:1px;/ D8 L! ?6 [1 x$ W2 ]
  margin:0px;}1 U. p+ E$ l, H
</style>! W! D, c+ Z" V! |$ c. D. X& M
<script language="javascript">
0 V8 R* @1 o& y7 j, {2 m<!--
  s  [$ m' w9 kfunction rv()
- ~% U4 z& i3 [. q5 \' Q{. k3 s  \+ h( P8 ^$ P2 z
  var val="";
; D; j( G# r2 P5 f( f  for(i=0;i<combo_box.list2.length;i++){2 h! b$ {  |/ C$ ^; L5 c
   val+=","+combo_box.list2.value;  F/ N6 ~) `7 ^$ `
  }
& F# K7 T& o5 R* y  if(val.charat(0)==","){' J& U: x! l4 n
   val=val.substr(1,val.length);# {8 @+ a# Z9 N2 v1 ]0 M
  }% X4 h3 b! R% e) l0 B) w
  opener.form1.frecname.value=val;& g4 s7 [) E9 `% L( K1 {
  self.close();
, N. b+ A' m; v6 c7 }4 g}
, v8 t& Q0 h( n6 P5 f//-->7 l5 J0 @% w* ?; l
</script>
9 P  {3 [; o: L: _8 a5 i% T# I+ x2 G<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">1 a/ ^6 Q* \1 K
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />! x5 e, E- V8 i2 ^( d
<%0 _' n8 ]0 A9 e0 A0 |3 E8 I5 S
  cdatasource ds=new cdatasource();  //数据联结bean实例4 k8 }0 s- G0 O5 z
  java.sql.connection conn=ds.getconnection();
  A& K+ C7 a; s7 h( E: h% ?9 X9 Q  java.sql.statement stmt=null;
4 e5 ]  }9 C9 }9 \0 _  java.sql.resultset rs=null;
' E) A2 a/ i3 }4 T) F2 `% _  cdatacheck dc=new cdatacheck();! Q  A  O: n) r1 C* v( s
%>
# N2 h$ [$ F' i<%
  G( @$ e+ I; r1 C( U( V7 ?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";
! H% o2 ?3 |, i1 _# Hstmt=conn.createstatement();
5 q% k. ?4 Z0 y  u! C5 H# Zrs=stmt.executequery(sqlu);
& T% h2 x5 c# c/ Z) O4 j; P%>6 C9 \* H" }, D2 C" H
<script language='javascript'># C5 J' Q7 e9 N; k; m: ^8 Y7 R
arr = new array();
+ b3 e% B6 s* p. G$ @<%  int temp=0;" \, S) D5 B+ x" T. M# N
while(rs.next())
2 k9 K4 ?* @5 k; G+ H" o{
6 C" Y9 u+ Y) e$ ]%>: L, h3 C! n: y4 t
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");4 d4 I( y) T9 j3 Z* e& v
<%
3 @3 N9 {0 L) utemp = temp + 1;) x: M! _: x+ f! u' Y! l6 j$ E6 d
}
# i& H" \; l5 w1 z%>; Z" W" a  N4 I- d4 h/ F" A/ n4 A
temp=<%=temp%>;; v+ C& N5 x7 K6 T  {
function changelocation(id){ & q+ j" H3 N# B9 \
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
/ Y, a/ X+ C# ~4 Svar i = 0;
, F7 K: o4 N; g7 `# Vdocument.combo_box.city.options[0]=new option('-------',''); ! V) g* c0 C  r" O" u  ?5 |' J
for(i=0;i<temp;i++){ 2 X* }* [0 j4 z& _. r6 l6 n
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] % {: x" t0 Z/ L9 S& s8 P
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
7 m! A& L& b$ G5 M}
  R7 u- h% B7 P/ L} / @) @& K( j, ^0 x0 ]  e; I& f0 w
} ( o7 ^% S$ ]% K5 r) v2 }# K, t
</script>0 |4 J4 N8 C# J0 D' D
8 x& _. h) d" W7 e7 u- H7 ^
<form name="combo_box">  c# m1 }+ T/ d. L4 k/ U5 M- B  P2 G
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
) d# ?! @4 L" i0 d: N1 ?1 w  <tr height="24"># b4 k1 ?+ z/ q% H* F, k' E0 \' q
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>* G( W, y4 }( h' D
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>1 G5 L% t5 O0 \
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>% B' @( ^" E1 I8 }6 g
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
0 e0 u2 j, f2 J" o! h  </tr>
/ O/ f5 ^$ [- U  <tr> 4 B9 G9 v& E6 A
    <td>
+ h, {: Q. W( B' h# u  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">% T( v" c3 n. b
  <option value="0">请选择部门 ---></option>
6 J/ y! F1 K; o, v<%
  ?$ G- |& P* e- M4 w    string sqld="select * from tdept";* L" y" S; B& U$ `+ Z
stmt=conn.createstatement();
. Q  r7 ]7 G6 {4 N, L$ Frs=stmt.executequery(sqld);
: J# K" r* s" f& n- mwhile(rs.next())6 E, ^  d! y+ x: p% T# u3 f2 b
{2 I7 o& v8 [7 v0 [8 U% a
%>
' ~" M# t, u1 A% c; z  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>2 I# R( b$ e# V' ~3 Y, ?# r
<%# M& w5 j, ^* y8 t- x( H; I. p7 z  R
}6 Y! e* u2 B3 K
%> 6 P) ?- X8 d- W9 W
  </select>  n3 R% f% j7 Q' z5 Y
</td>
4 r' ~- W  N' v& G    <td>7 @: ^" \3 {( D8 E8 C/ X+ Q
  <select multiple id=city style="width:150;height:200" class="bgc">
# e8 `# \' ~2 @6 X+ O; s  </select>
1 a8 `% u1 ^" M1 Q: N</td>
: h3 w2 g. S$ \- C    <td nowrap align="center" class="bgc">+ d2 M3 V& g1 \" s/ z
  <input type="button"  value="<<" class="buttons">8 f' u% \3 P. v4 q
  <input type="button"  value=">>" class="buttons">
% F" n. \6 n+ a8 c2 U1 S</td>
3 _" ~8 r  c2 I8 ?. {    <td>
0 U4 V; @6 A  k% U& o  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
' n5 B$ v% g0 P: y  </select>/ d9 W" F0 k- l! ?- A: ]9 `: }
</td>- Y* P( A0 H3 p
  </tr>  v3 g* I( y+ o0 h$ y5 v; w/ ?
    <tr class="bgc">
: Q- I0 ~0 n" Q2 N+ e    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
+ J: o- f* ^& [( M  </tr>( K& N6 y8 I# E2 T# {  K0 y3 Z
</table>2 @2 Z1 q+ d- `) @$ P- ?
</form>3 \: K1 s  K& Q! b
<script language="javascript">( ]; n3 I' I  Y2 j8 ~
//人名移动
' ^& M) @, T8 e, l  r6 d  ~5 efunction move(fbox, tbox) {
- |0 E) p' P1 z6 H; Z  qvar arrfbox = new array();5 L3 [1 Z" D& u. r
var arrtbox = new array();
! p! [# M" n8 I3 T- S9 B8 x/ dvar arrlookup = new array();
( ]/ t5 r- s: q9 c; s4 W6 ^3 cvar i;
3 D' K  Q% b; O8 U% vfor (i = 0; i < tbox.options.length; i++) {
. ~' s0 N& Q! }# {" f" q1 @arrlookup[tbox.options.text] = tbox.options.value;+ T  \4 I+ F; q: L+ _' Y
arrtbox = tbox.options.text;5 P) ~  k* }5 u* N) l& W
}
0 }4 @! E" H7 ~/ l/ \! wvar flength = 0;
6 B! j" _0 u5 Nvar tlength = arrtbox.length;
% c8 P, R, ]1 ^- W$ hfor(i = 0; i < fbox.options.length; i++) {
" _7 p: `; v; W# ]' l% sarrlookup[fbox.options.text] = fbox.options.value;7 G6 h/ V0 o4 w' ~* v
if (fbox.options.selected && fbox.options.value != "") {
4 @4 ]' L: F& T2 karrtbox[tlength] = fbox.options.text;
$ w/ t5 H8 e) ?7 u" qtlength++;
& {2 n2 `% `: |; m1 _}
+ \. s: t1 i" y+ m, E& E. e6 helse {* [, V9 h2 m3 ?8 k, Q4 w
arrfbox[flength] = fbox.options.text;" i. E% o. P3 k- p. n
flength++;" {8 {- ~# k& z3 ~: r) T  V! l
   }2 @0 e/ H. n  `! x9 o
}
; }% w3 W: A9 Farrfbox.sort();9 ~7 k* [1 d7 ]* Y8 }6 }5 ^* l( B
arrtbox.sort();/ y* }& V( `/ i! F

) g  _9 s) M. j! Tfbox.length = 0;
1 q9 R6 F/ [- T' q* F$ [tbox.length = 0;
% S0 r" P+ |6 ?/ |var c;
5 F" j# k* Y: D- o0 f3 _6 kfor(c = 0; c < arrfbox.length; c++) {9 k; M6 Q0 b: H5 f5 T/ H) J- e; t
var no = new option();
7 y% h- q* q+ A' v* m* Ano.value = arrlookup[arrfbox[c]];) ]% {  j# \7 I+ e& i4 a1 ?
no.text = arrfbox[c];) M% Z, e( R7 E1 ?4 M2 I. ?
fbox[c] = no;
6 t( Z% m4 H* ^}* _2 H" d! Z1 x$ A3 N4 a) p
for(c = 0; c < arrtbox.length; c++) {3 ?1 J8 u# x. B7 h/ B) G' V
var no = new option();
- |2 \6 y. P# T: z' u! F- Mno.value = arrlookup[arrtbox[c]];3 o5 a9 L" I1 a! l% z7 @
no.text = arrtbox[c];0 d5 ]4 J1 N2 t/ H
tbox[c] = no;5 w) S! Z- y0 B/ F
   }
% ]& t( B+ m3 q* d/ S  H}9 N/ v2 T0 S! p
</script>3 ~$ N, P0 i- t2 a5 w0 D( k
</body>
; S3 |# g: x9 N6 [9 b  F

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