返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"% B7 p2 _/ d& V7 C
         c pageencoding="gb2312"0 v8 V3 ?) L, i! r, [0 R0 E; e
%>( Q( \% W1 ~* s( L5 P2 K# z
<style>
) s. H& T- ~' \$ S8 X3 M8 y.f9{ font-size:9pt; }  o) H! P6 q7 S" p9 u. q! C5 B9 J1 h
.bgc{ background-color:#aecaf9; color: #0033ff }
, Q5 i; A" ~0 S7 h( ]7 |.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
6 t' S; \. b. J  border-bottom: solid 1px #4e7dc1;
# g& e( _5 l& m2 W  border-left: solid 1px #aecaf9;0 W2 w8 V' q2 Q7 d8 t
  border-right: solid 1px #5679bd;
5 @# U# Q! J# t! H  padding:1px;
( ]6 t" U6 F! A0 R6 y0 I1 u+ C  margin:0px;}
; t: [0 J; x! {( S</style>
8 U' B! }# u! a+ ~<script language="javascript">
. a" Q. p9 v* o' B& v0 W5 V1 _6 N<!--, H/ b$ Q+ v; D, j' U6 F
function rv()
8 o* c, m! ?7 j; J5 V% g# m0 k& m{1 u' T+ R% ]! x- m8 B) V# y* C
  var val="";0 t- B$ a. u. r
  for(i=0;i<combo_box.list2.length;i++){
( k$ `$ @1 n. a0 Q; @   val+=","+combo_box.list2.value;
3 v2 Y+ n7 T: `2 z6 U) e( Z  }; r+ R" G- T& b! \* V7 F2 l5 y
  if(val.charat(0)==","){0 M7 _$ H1 Y. l% X
   val=val.substr(1,val.length);  s% P# T; q) f5 O0 T
  }- H2 N1 J8 |6 t4 z+ o; ~
  opener.form1.frecname.value=val;
' @/ H/ a2 |. b; a; L( l' t  self.close();  {" {$ ?, g! p& e! l
}
/ x9 X/ G( e! j% y//-->
- M; C1 P1 k( n</script>% Y) R" u; V: A* w6 {
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
; d0 a+ i' u0 y( F( l<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
& R" p. }5 ]+ D$ d# N4 m8 b! K# b1 X<%( l8 z, E/ q& |$ h
  cdatasource ds=new cdatasource();  //数据联结bean实例% w0 X- ]2 W1 i* K# |! c3 t8 o
  java.sql.connection conn=ds.getconnection();  ~$ x  G3 T6 i* Z, k/ C) G, n  Z0 [9 S
  java.sql.statement stmt=null;, m5 ^3 g7 w# \1 d
  java.sql.resultset rs=null;
2 G, b/ \/ V; Q6 ~# \+ A! ~9 o  cdatacheck dc=new cdatacheck();
  b! L3 ]+ i, [  i%>
" Z1 o" q& w, G) S# A0 @3 w. Z<%; [1 e8 d' b' w
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";
6 E- \0 J  C" \' a$ E; a& y+ rstmt=conn.createstatement();
" U) F( t% l0 ars=stmt.executequery(sqlu);
$ ^' a: H. W: r$ c%>6 S7 k2 z3 `2 i) S
<script language='javascript'>1 @* _( y: h+ M; ~
arr = new array();
& U+ }+ ]# [: S2 G1 U<%  int temp=0;% A; ^. c9 L- n6 k
while(rs.next())% ?; T+ U5 f* g2 g. ]2 d
{
# d  j! ?' e# B& R2 _  Z- j%>
' T2 x' I. y/ iarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");4 M# e0 K5 k" K/ k4 R4 n
<%% r. b* Q; R0 F& G8 z+ k9 n' s
temp = temp + 1;  R) t/ A; A5 m! w- T
}
0 \+ X$ l% `9 p* d" M%>
3 c2 U" _% B' S( _4 V0 k1 ^; ptemp=<%=temp%>;
5 A- S) _9 b# |/ u  o9 n% F( }3 r0 tfunction changelocation(id){
' @* R) O8 }$ t% r& f. z- ?document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 + G9 w: X: U. X' q9 b' O' Q9 U
var i = 0;
, r+ y$ t( x+ d' hdocument.combo_box.city.options[0]=new option('-------',''); 1 d/ \9 k& C6 F; ^8 l; D
for(i=0;i<temp;i++){
& a. v8 K1 [+ Iif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] . {4 g4 l# v% T: o% i- L
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 5 {7 L" W# f' Q' O: @& }
}
+ `4 O4 Y' V0 f' W}
* V; y( S: y" F9 A0 ^* H9 S}
" }# h) J- d: w9 W  m</script># w" K) R* V1 A: V  h
) n# E2 j6 t4 _! y0 s$ ^) f) L
<form name="combo_box">6 b: Y: |: p/ {5 D1 W" \: a
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
  w0 z6 C3 M& J2 y8 B( K  <tr height="24">4 a4 l* q' s) b7 p8 R0 R
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
8 c, I% Y+ g, ]& O& T# I5 N    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>/ Y- a# |' g  N/ u
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
% _7 i/ j, w' J& ]" B    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>* _9 ^; A1 F; F) `
  </tr>
; M! ^: K: ]% F/ ~9 G0 m& v) v& L  <tr>
! q0 V5 Q! V  b( Q, u    <td>
) I& ?% q7 e. {- G' v) ]5 ^) ?  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
/ ~, {/ R) q# G- d0 u, b  <option value="0">请选择部门 ---></option>/ W3 c4 w4 S, D/ d+ Q
<%
" ?  \" t4 R* Z; F) o9 {& W    string sqld="select * from tdept";( A# g' Z" s" X
stmt=conn.createstatement();
- a! b* R; R) h: G1 _7 W7 crs=stmt.executequery(sqld);
+ ~2 `+ ]) ?* a) B7 N) Owhile(rs.next())3 G3 l) s8 U4 l# V
{
5 i) W2 f( e' r+ _7 z%>
6 b* s# M6 o9 C+ z0 P+ h  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>8 n. r# ?+ t$ p1 V
<%' L! b7 w/ {. K- P8 B2 N" P
}
$ {2 ?. c- o& P& V1 V# Z5 S, n%> 2 O- O; D: o! o- R% `# n0 ~
  </select>
, r% F% Y3 U6 V. d</td>
9 K3 F4 m/ k+ y- d6 Y9 _( d    <td>: c$ b+ g. n& I2 j2 K8 c
  <select multiple id=city style="width:150;height:200" class="bgc">( o( T. p3 J6 ~! e' h# x: @
  </select>
$ j( o( T$ |$ X% ?% h- N+ @, h/ Q, a; M</td>
, }3 E+ N/ c' L! w. J    <td nowrap align="center" class="bgc">* p) f- T, a: E: G4 @& P
  <input type="button"  value="<<" class="buttons">% K' `/ n8 e; l  x2 u6 G1 Z# u9 d0 ^
  <input type="button"  value=">>" class="buttons">1 x4 |# t; d6 {
</td>
' V/ E9 m3 Y* o0 u0 i    <td>
( r" ?$ r! d) x' U% C5 z2 `* n$ n; a  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
0 W! ~& p, i+ ~+ g- K- f: M3 C  </select>
% F- A* E, _$ @8 C/ D: U) n& P4 q! Y</td>
9 H7 w; A5 n# ?! O% _* }' R, t9 _2 d  </tr>1 w( E0 i/ [: P& c3 b: L
    <tr class="bgc">
/ c$ }% M, O3 H: Q6 L: t9 `8 V: S    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>! m+ @7 f( Y' H& D# ?  O
  </tr>! F2 D  x# g4 i9 m5 h- d- v# e
</table>- I$ B6 M7 t3 F2 ?* `9 K' }9 u0 b
</form>, `  u) l# I9 i0 P
<script language="javascript">! |! ]. G' N1 K2 g9 Q+ I, B
//人名移动1 e& @% u4 T' G1 _5 |6 ]" B3 N" l
function move(fbox, tbox) {
! \0 {% R$ w8 p" T* |7 ~var arrfbox = new array();
9 b# Z" o0 |( `2 ivar arrtbox = new array();) v# v, S2 f( j3 K# ^1 X
var arrlookup = new array();
0 Z9 w" A& |/ v. Q( ]var i;
3 T# O' j- N6 r8 Mfor (i = 0; i < tbox.options.length; i++) {$ Z, S5 }/ Q" P, o* [
arrlookup[tbox.options.text] = tbox.options.value;  W, F* B0 _9 X# x6 A1 {. m
arrtbox = tbox.options.text;
% z2 |: I1 A1 D1 K# G}+ t4 a% g( G2 F- D) P9 F
var flength = 0;
6 I/ H! h: l" A* a: V% B5 v- i# gvar tlength = arrtbox.length;; N) w9 Y* A7 n! y
for(i = 0; i < fbox.options.length; i++) {
' h4 f$ v8 [$ \+ Z( `+ ?/ b( S: sarrlookup[fbox.options.text] = fbox.options.value;1 _4 d7 o* p1 c9 _
if (fbox.options.selected && fbox.options.value != "") {
3 k* |$ B6 D) i9 p* I- sarrtbox[tlength] = fbox.options.text;; v2 i7 X) b5 n6 d
tlength++;
+ |* c* ]0 {1 N/ t7 L, o7 {, \}) @. ~" Z6 x% p& u
else {# V7 W: q! Y# ~. K
arrfbox[flength] = fbox.options.text;
% t  m6 b/ c+ l- kflength++;
: `" |/ m8 B# N   }+ l1 G! h4 ?* f9 Y
}7 g+ W; @+ U) R2 b& ~
arrfbox.sort();
" F! w; W# a  s' e, ?arrtbox.sort();
/ d8 P7 d% a' Z3 g: Z
7 ^$ y8 i# ]8 r$ Qfbox.length = 0;
) e8 W0 E0 ?* q  D9 Ntbox.length = 0;* y8 g/ L5 k$ C( d; m
var c;
1 u. y- T6 f& Z) Pfor(c = 0; c < arrfbox.length; c++) {/ G; `5 k7 w! d- [
var no = new option();4 Z+ f* \" F+ N; o; V0 t" g
no.value = arrlookup[arrfbox[c]];/ Y% i& U0 n# W( Q; G
no.text = arrfbox[c];  A! ^, D2 v5 [% q# a' Q% p
fbox[c] = no;
/ O! {* y' n5 d" B, \; b$ w3 W}
% k: ]; u- I  K; Y+ mfor(c = 0; c < arrtbox.length; c++) {8 I, L) C- s" s7 P* w
var no = new option();1 ~  T3 M% h: r3 H# E& f
no.value = arrlookup[arrtbox[c]];: O9 t8 a5 F+ t
no.text = arrtbox[c];
$ K/ o( M; }6 D0 H( G2 ktbox[c] = no;
5 I5 _% l& C, [+ y   }
% ^. ~" h+ g# U( C' g4 Z9 f# Z}
( q. [, H9 Q6 L</script>! n, P: G2 _: R0 [7 b+ x$ r
</body>
4 x4 k* ~7 H& G* _# Z0 ~2 S# H( D

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