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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"! A! G4 e2 c4 ]2 L- x
         c pageencoding="gb2312"
  `5 K0 C" d4 f- d% K  w%>5 q2 i( s* W  G( f4 R1 h) M) E7 Z
<style>
1 F% q, Z* d& u% g: h% O- i" T: ?.f9{ font-size:9pt; }7 [  U; G& a+ H, ^$ C0 K9 z2 B
.bgc{ background-color:#aecaf9; color: #0033ff }
7 h# ~; o- n  X% v" _( Y.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;! G8 Y7 C/ X6 N% q+ z$ _9 \
  border-bottom: solid 1px #4e7dc1;5 Z( Q; i: G) E
  border-left: solid 1px #aecaf9;
' M  v8 c: b; f) {. \  border-right: solid 1px #5679bd;" Z  J; X6 z' t2 |" x3 G9 y, F
  padding:1px;7 G4 h8 j  B5 L- ^& l7 g
  margin:0px;}* n3 ~& `7 |+ M  n' Y: @9 ?) S: x
</style>3 K- t/ z0 H( K* k% M" Y; w
<script language="javascript">
! P$ M! @, K) o9 U0 A. O  W$ m% q<!--) \2 O( n$ m6 \! M8 j6 l3 F& Z
function rv()2 c8 r3 Q) d& _) c
{
! q; p% Z4 ^  j6 m  var val="";  k  o) q. c8 ~- m
  for(i=0;i<combo_box.list2.length;i++){
! t+ D6 ]* }* ~: Q. l" H% Y   val+=","+combo_box.list2.value;: n, b1 E3 s4 e6 G; f* |
  }& d, L; i3 G6 n. M1 K5 o9 Y
  if(val.charat(0)==","){& s4 N5 m# b' A, t9 L
   val=val.substr(1,val.length);
6 {2 r! K* v/ N8 L& i9 L  }
* X# L/ `) w5 L( Z# T  opener.form1.frecname.value=val;# \+ W0 E3 g" [1 J7 n9 O3 W' O
  self.close();
: K/ M0 e$ O5 H1 x( q5 ^}2 f6 g* c) e# s6 D* p. e3 O; F
//-->
+ Z& X  M' O) k% h</script>
$ g# q) o  i/ R/ j0 n0 H% C<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
7 J% Y, \" S7 \. _8 W<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
6 v1 F; o& p8 |* g# ^  m" y$ t' d6 |<%  p3 Z, `% z/ L* e: y
  cdatasource ds=new cdatasource();  //数据联结bean实例
- N+ c9 Y& K! G* m. P  java.sql.connection conn=ds.getconnection();2 K; F7 m: M0 i5 I, S9 V; e" k! @
  java.sql.statement stmt=null;
5 m  {  U. _( e, _4 e( X  java.sql.resultset rs=null;: R( o0 b8 d8 x# `
  cdatacheck dc=new cdatacheck();2 a# D! E4 |+ ]+ B$ ^
%>$ W1 a& I; r/ p$ T$ ^1 Q- f0 X/ O& H
<%
% e& v" X' S3 Z- L7 d% C3 z$ Wstring 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";) ]+ F3 {* J; _+ z% B6 L* ~3 A
stmt=conn.createstatement();
! v8 B  u8 u& O, Yrs=stmt.executequery(sqlu);
1 b7 H/ D2 D) ?# ~6 q! Y%>
! s4 F! A" F+ e<script language='javascript'>
- g/ A# M1 b$ `  C% A* O4 xarr = new array();
3 m9 A5 M3 F- v<%  int temp=0;
* d( m  T' J$ l% z0 M% l8 Dwhile(rs.next())6 Z4 Z8 B' U0 ]. q2 H
{
; h8 t( M4 N* B9 W/ X+ u! _%>
! h; ?- a" w1 f# {3 Karr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");5 Q* W, h/ Y& K% D' T- h
<%
7 ]% Q/ \9 E% }$ w& G/ @temp = temp + 1;
1 ~" N% v- I4 l8 ]}
0 _; i  x& V6 ]* {5 k' Q5 z%>0 n3 d/ T* h6 I5 \& y3 U* m: o
temp=<%=temp%>;$ I7 p7 o7 Q2 k
function changelocation(id){
& P  w4 r$ k& p9 Vdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
  @% ?: W0 i) E$ J% X7 w4 fvar i = 0;
4 w$ R# h) U! |2 Odocument.combo_box.city.options[0]=new option('-------',''); . z: A* u7 P! ~$ H) M) y, B6 c
for(i=0;i<temp;i++){
+ K( a* J& h0 B. a6 N4 Q% Y$ A& `if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 4 z6 B9 n' n( B: a/ S0 H
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); ' f8 t9 O  `2 K) P0 k" x; K
}
. S0 C' J* B5 r% S: v} 3 f! L' {5 @8 ^' H, j: s9 e4 |' z, f
} + z/ u2 \$ K9 q  C
</script>+ i1 j" D- G  J- y6 Q

, n% ]! O5 c* t5 I7 o<form name="combo_box">8 Y% `  B1 i, ~  |$ u1 P/ z: t
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">$ g$ b: v& d* t' J$ }0 l
  <tr height="24">
+ p* h( q" }& M  b# }    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
. o& e- F/ |& h6 U: @( [- W    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
" ?. `6 L: f2 B8 ]* K! L  d    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
) n+ K% e: U' v( \    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
+ E' F3 [* g8 {+ ^+ |( e  </tr>
/ C! f. K1 d( v, _( `) n  <tr>
4 H; C0 W$ y) x' j    <td>
1 i% d/ h) V( P% p0 K% B7 q) C+ B6 ?  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
6 ?  H4 R+ i8 ]6 V3 P# m/ f  <option value="0">请选择部门 ---></option>
6 w/ O- N7 x) v9 C<%
. G+ Y9 D" \  z2 e7 A# O    string sqld="select * from tdept";
4 o* E8 H! S; v. @stmt=conn.createstatement();6 [/ J7 y# y# j: E, }
rs=stmt.executequery(sqld);& E3 N/ }/ p5 _$ I+ I# W* G
while(rs.next())
! Y( c% x% u' u{
% u! y% c* c2 r( E  t- c%>
$ D+ U) @. W. O: S/ m3 w& t- X  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>9 Y3 v+ \9 y0 i) x, u+ U
<%
1 W0 ?8 C. [, B7 G* D! w4 p0 r( }}
7 I" n' S9 v" r( n%> " c* d; ?6 d3 B6 ?: n6 j7 i" x- K
  </select>  d/ }+ l0 k; p* R6 a
</td>) O# W8 H6 }5 ]5 I, z& z7 a' J
    <td>
; l1 i/ v- W& G  <select multiple id=city style="width:150;height:200" class="bgc">
# O4 M9 D, n* \  N( ^  </select>0 J. g7 G2 B: E+ Q
</td>* j1 _3 }4 f% ^+ S8 a
    <td nowrap align="center" class="bgc">
! i' j0 @4 L( d  ^6 J. j$ ?" A  <input type="button"  value="<<" class="buttons">
5 L6 I3 Q8 U& f3 Q6 ?  <input type="button"  value=">>" class="buttons">
  Q. k; ?! u( f) m7 h) ?</td>1 b0 `8 k, m$ u5 c3 S2 _
    <td>% s, f( X3 ~7 ^) _3 o% s/ B
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
9 u- A' l0 w  f2 z  </select>% w  ~: D0 M, ]  V8 ^  `
</td>3 A3 ?- m2 j+ |/ v& n6 s; `
  </tr>* ^# _" p: f% X% D$ [4 Z
    <tr class="bgc"> ( p! A2 @( b  @
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
; b  O  i0 i* y$ ]6 p' H- x  </tr>
! O- R2 H4 N$ J: `6 f</table>
+ \5 Z) e( l+ v/ t- @2 ?5 v' M</form>
1 p5 T: ^; X9 }+ g( P<script language="javascript">; ~$ Q( m9 i# R9 z2 C0 G
//人名移动
, `% J5 J3 H* k5 |( y$ dfunction move(fbox, tbox) {1 `; p! y/ g0 }2 I& F- D: B6 T
var arrfbox = new array();" Q3 _3 `% H& o/ z
var arrtbox = new array();
" D+ x7 \& }0 [0 {) Uvar arrlookup = new array();8 O1 R7 y, _1 x; ]
var i;6 R& p; n' ?6 L' b" e
for (i = 0; i < tbox.options.length; i++) {
$ ^& K$ I$ I0 q9 g) Oarrlookup[tbox.options.text] = tbox.options.value;; I) s+ n7 U" @9 Y# r
arrtbox = tbox.options.text;
7 T8 `- `1 E$ O2 Y5 H$ r0 }! N}" e- v# j0 ~7 l0 t! \" Q
var flength = 0;) T& i& p3 X- t: w8 a( J, u2 J5 q
var tlength = arrtbox.length;; r- H- n  b( D- K8 t, B8 b' _) o
for(i = 0; i < fbox.options.length; i++) {0 E; w, B2 A; y, v5 ^( a
arrlookup[fbox.options.text] = fbox.options.value;
+ s5 h' d- Q  R6 Cif (fbox.options.selected && fbox.options.value != "") {' a" k% w2 w# {& U$ T" T' W
arrtbox[tlength] = fbox.options.text;3 ~  p( t/ W  P1 P, ~/ _+ U
tlength++;
* R0 I! r: M3 ^: w+ R- j: E}# g. @( o& Z8 _
else {
+ ]' M5 s$ G% ~  Karrfbox[flength] = fbox.options.text;
& C8 \& V& `1 w8 i8 zflength++;
" t9 O1 E1 l; v3 T  Z4 \  G/ }% S   }& H, f  h, C7 Y0 O5 t
}: L: O+ j6 G* Z- E% c+ w2 O
arrfbox.sort();2 I. W% m3 j+ d- t+ d3 z
arrtbox.sort();
6 t$ _1 R7 t7 q: O+ [7 g8 n, X+ w( |1 y& Z6 C6 j: a3 C
fbox.length = 0;- J7 v3 ~7 h* w7 \, c/ a
tbox.length = 0;
4 P' D0 y  }& e+ Wvar c;) k. J8 t  \9 T. D
for(c = 0; c < arrfbox.length; c++) {0 c3 i! @3 D8 \  ]
var no = new option();% y. M* U; f! x2 M7 }# f
no.value = arrlookup[arrfbox[c]];
0 S5 }: p! B6 H. S5 v0 Sno.text = arrfbox[c];) _0 F  ~# R/ K' I7 z  {
fbox[c] = no;4 j: A8 V( h8 h$ z+ ?1 p
}6 ?; Q' l" B; G) s
for(c = 0; c < arrtbox.length; c++) {8 K9 v2 C0 C1 K  c
var no = new option();
; u) r0 y! `( F* ?) G7 J/ uno.value = arrlookup[arrtbox[c]];" n9 D0 H1 g- y# H7 I2 Y
no.text = arrtbox[c];
) o: L6 H2 R. |tbox[c] = no;
0 P, X0 `3 r+ ^: B; v3 A, C   }
  W2 K& t6 u) X$ N( z% K}! U! N6 P! `/ \( j& q) k2 P
</script>
2 p  p& w! `/ \' |6 s1 h2 J</body>
# H0 F% J% o8 S4 h: ~

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