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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"  H4 q2 Z; {; m* B  l% y* c
         c pageencoding="gb2312"
4 j+ s+ \" w; v4 n7 m% Z%>
: [% r* S3 ^, f- T3 {4 `3 u<style>
0 g/ n/ R3 I: p# {+ y, J.f9{ font-size:9pt; }/ d8 Z, ~) n5 a! s; l
.bgc{ background-color:#aecaf9; color: #0033ff }
/ k# i5 @6 q  W! {.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
% A% l) l! S2 ^" r" j9 b/ N2 [* ~. j  border-bottom: solid 1px #4e7dc1;; ?1 L% p( x+ \. ~
  border-left: solid 1px #aecaf9;% B1 T7 ]' k3 X
  border-right: solid 1px #5679bd;, L0 R% y2 F4 q7 C1 t! A- g
  padding:1px;, q6 l$ L5 O  b
  margin:0px;}
" L" t/ p( C- S0 l5 ?</style>5 x# U0 y, m& h1 @, j( B' S
<script language="javascript">  y8 v, d& F; ]* Y1 h9 e
<!--
  X  X; F; l* J/ m; J+ g$ E! _( e  ]function rv()8 Y# A- m2 f% @
{
# l2 Y! ]* l* U% R4 Y) D  var val="";" K& L" y/ d. o1 _0 ?7 z
  for(i=0;i<combo_box.list2.length;i++){
- j0 M% [5 f4 p; }- J+ r- w   val+=","+combo_box.list2.value;8 i* }( q: K' t+ m  y* r. T6 b5 I
  }
# H! P+ [9 s% k& H  if(val.charat(0)==","){0 {% u3 r" q/ Q
   val=val.substr(1,val.length);1 m  {  D* _/ a- |- L
  }
& b5 i$ I+ m+ q$ p' K  opener.form1.frecname.value=val;
. |/ s; j9 H$ p# c) l  E2 ^  self.close();5 d. @8 @( o5 v; F- p; V
}
) b$ Z4 N1 U  H; P7 E; Y( r+ r3 m//-->3 v) ?! _: i/ c! E& V; [* P) ^7 v
</script>  R4 l0 o5 \* ?: y! i
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">, l! O) u# l/ w3 E0 d
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />+ A/ M$ W- e/ e7 m6 _
<%
: h9 {* l5 x% \2 J  N7 C# a( c  cdatasource ds=new cdatasource();  //数据联结bean实例# v2 T9 z, @2 o6 j2 B- u
  java.sql.connection conn=ds.getconnection();2 c" p5 ~) x) `! }) O5 Y! E  B* ~
  java.sql.statement stmt=null;
5 |& j+ J! f. ?/ H/ |( ]  java.sql.resultset rs=null;4 N3 C4 q+ s& V5 c( m8 F
  cdatacheck dc=new cdatacheck();( u: y3 y8 ~& ~/ E  Z4 L* H
%>, ^8 I, k; n' ^- A
<%
7 l5 p& L/ E- }& Z5 i( X' L! ^+ istring 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";
0 s" O; M1 D, c* `) f* L, {5 ^/ w) dstmt=conn.createstatement();
9 T1 D) T, `- x7 t, c3 M9 v, }% x0 lrs=stmt.executequery(sqlu);) h9 X3 M' a( R# f1 K8 l: {
%>" h( N( o: Z( d: ^1 Y! x, n$ a
<script language='javascript'>: Z% }2 Q) x+ X8 b
arr = new array();; c$ }0 G- z4 T3 P# H
<%  int temp=0;$ K- E* f- @& l7 Z3 l
while(rs.next())
: Q# \! J1 d) J{
/ h! m- H. l5 N  }# @: H/ I3 [9 Z%>3 ^! K, j( M! C* Z
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
" a5 {. @# X. H<%! \+ p( g6 P1 w- P3 ~* @" H+ H9 h5 s4 V+ \
temp = temp + 1;
- r7 Y8 y* m& f. D3 U9 s, y# @}
+ T% {; C. E5 o% [0 s%>6 M; |) A4 V% j2 _* ]
temp=<%=temp%>;
+ G9 U- O9 M) tfunction changelocation(id){
+ l# w! Q  u" Odocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
0 t# Z) n1 }" j3 S, a& F5 `var i = 0;
1 F  S4 U5 c! v5 C7 G9 d/ _$ edocument.combo_box.city.options[0]=new option('-------',''); ! y. \5 c! _+ R% O7 ^5 s
for(i=0;i<temp;i++){
/ c! i9 ~$ W( U8 O" [6 oif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] & `; i1 A9 i+ S6 g" B. `% y
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
: D, O, j0 ?7 D  O# r}
: S; H! B4 \/ @8 j) t$ A8 N}
$ L8 |9 e$ E1 z. u9 J6 C+ J3 A. `} ( R( [  R9 g- t/ D
</script>
4 {# o$ k4 B; r$ A* u; i1 e2 g" Z3 l0 f, }% ~2 c! T* v5 {
<form name="combo_box">+ \2 T. T3 V% n
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">- v+ h- U& R$ E5 O' s$ R+ S
  <tr height="24">' H, y& |9 m5 G7 l8 k% s
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>- n& H/ c  t, {' k, L  w
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td># V4 O! s8 R. ^
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
* |. q* J. v2 H; z( E: y    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>+ m2 A' ?  `: I9 w
  </tr>6 f1 K6 T' m8 Q$ K" j+ I# r
  <tr>
$ S; h: `0 o# Q) A    <td>8 q9 t3 z/ S$ T+ g* u
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">/ S$ g9 B1 f2 _# l
  <option value="0">请选择部门 ---></option>( z- c' q" n- S
<%; ]8 }6 M; N9 i2 U" A7 ^! ?3 E
    string sqld="select * from tdept";
3 G4 B% V% Y. i  c; ^  xstmt=conn.createstatement();4 L* S/ t. y4 a' H
rs=stmt.executequery(sqld);/ [. K5 e. v( m! u7 P- e. X) `+ i7 A
while(rs.next())
) W$ R! p$ k) I$ `& u* h+ r{
" K9 t& R8 V6 C6 `%>4 V6 w  l+ l) {9 }. w7 t
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
. K/ V- C2 L! G<%2 Z- x! J" k$ ^. B; R8 f
}
# V. C: i1 s! L2 O* _%> 1 C( I' j7 Y' {! i# ], s
  </select>$ t0 u: ?; S- i- J# _
</td>4 \$ ]! V( w9 i% U
    <td>
% @# x/ {4 Y' ^! U  Y5 G  <select multiple id=city style="width:150;height:200" class="bgc">+ k$ Q. b5 T: X9 L5 `+ r, J' G( ]7 c
  </select>
" |3 v5 W9 p7 y3 R: z3 o</td>
7 B$ k. E+ u6 O% W, N  x8 B. @    <td nowrap align="center" class="bgc">5 f6 Y- ?0 M) D& V- H0 m
  <input type="button"  value="<<" class="buttons">
1 T/ I0 V) M' o& B& N& c+ X# l+ |3 n  <input type="button"  value=">>" class="buttons">7 [% ^7 a4 t+ A
</td>/ Q$ n$ V' G9 @" m7 q9 f0 X& Q8 {
    <td>& i. `, w& a# p4 I* ?3 W
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">5 k2 y. T( `2 s* Z+ v- d
  </select># F# F* `; ~" q$ m" e, p' ?* k- @
</td>) e; j! A) e; q) {
  </tr>" ^8 E+ j& h0 F
    <tr class="bgc">
, ~1 q( ]/ E. t( Z8 T* u: `; h" i    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>3 F* L* f: i& a' |
  </tr>4 d: _# X9 j$ \; u" [4 `! }4 F
</table>8 L- T9 W/ C' {7 r% Z
</form>
) Q$ m9 \, j5 g7 C0 y% g<script language="javascript">, b. J  x. W' o* l; S
//人名移动
! {4 {9 C* r% r4 S7 }% Pfunction move(fbox, tbox) {
) ~4 E2 N* l+ a; h0 `4 Wvar arrfbox = new array();
! M3 ~) a6 m0 z5 `var arrtbox = new array();# _8 }5 J3 X3 N2 ?: r" s
var arrlookup = new array();! F" t  Y  a: Y! H  b) ^! z
var i;" Y: K% R5 N. U7 j
for (i = 0; i < tbox.options.length; i++) {* J7 d! m. L( V7 U& r4 u$ l
arrlookup[tbox.options.text] = tbox.options.value;
4 `1 ^7 r" ]; R5 I6 marrtbox = tbox.options.text;
/ H+ H+ b; `( X, s' D5 J}
" O  v( q0 Q- u  C0 Pvar flength = 0;
. U- m5 d8 }: Zvar tlength = arrtbox.length;+ p+ L& i8 M, `
for(i = 0; i < fbox.options.length; i++) {
( C$ T/ L9 l" ~/ T/ Garrlookup[fbox.options.text] = fbox.options.value;' ~2 e9 a- N( B2 r: t9 Q
if (fbox.options.selected && fbox.options.value != "") {
# f# Q, u7 K7 M: Qarrtbox[tlength] = fbox.options.text;3 m$ o9 n6 V6 O( p* P
tlength++;
1 A9 A, p3 t3 J4 H' ?# x# ]}( T  U- V& u1 v2 X* O. u, L
else {7 L( j% O# V; b
arrfbox[flength] = fbox.options.text;
) F* U6 A4 K; oflength++;8 |0 _$ N. v% w; d/ q$ g2 y
   }
+ ?- j+ K! L: s}# W  t2 j) U8 C. t
arrfbox.sort();* s4 [6 j7 C8 F. i, J
arrtbox.sort();1 F+ E& @1 c, T( c

- g5 r1 d" O! f' ?) m/ [0 u4 w5 yfbox.length = 0;6 j6 {7 d  |# V& ^! q) q8 H
tbox.length = 0;
9 @" I1 S* b3 g" k" ]: O! N9 j! Rvar c;9 S: M9 x! n, l* ]
for(c = 0; c < arrfbox.length; c++) {
- c' B' P6 ]" C0 Z9 D7 Avar no = new option();' a: s* P6 p5 r% ~! g
no.value = arrlookup[arrfbox[c]];
4 T, A# w2 A) F  rno.text = arrfbox[c];( |: Z9 R' K4 q' [, [2 r- R- `
fbox[c] = no;
4 J8 k0 p' M4 }, P% d}: ?7 a+ U* b( J! L
for(c = 0; c < arrtbox.length; c++) {
; }! B; x  ?/ B1 Tvar no = new option();5 Z" X( ?4 l: P: \8 _
no.value = arrlookup[arrtbox[c]];
  ^& N/ d" G0 E$ [' S+ _7 Fno.text = arrtbox[c];! I2 x- Z+ |) o) `  ]2 l
tbox[c] = no;
1 |  p. R9 @6 A- J4 M   }
# h+ N/ f: l1 Z- C}
: X; E4 E6 Q, C3 u) z5 u0 t, t1 d</script>
- l3 u  [/ k6 c. d' {</body>
( f4 a. X5 f; G

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