返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"  u; a; Y6 h9 Y8 x
         c pageencoding="gb2312"
- D% c8 D. i' d' d5 \  K; c7 |) D%>
0 p% f/ w2 C1 {' ]4 B/ @, s. l$ ]<style>
- n+ M$ {4 X) \$ V* m3 V3 h.f9{ font-size:9pt; }
. Q# C8 T$ K6 W% ^: ?- i.bgc{ background-color:#aecaf9; color: #0033ff }
# a2 D, T$ Z& o1 i: v2 r2 G* w0 _.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
6 t" t, }/ C2 g. A0 z  border-bottom: solid 1px #4e7dc1;$ \- u+ G& G" q  l
  border-left: solid 1px #aecaf9;
! y- C: n5 k% A1 g7 O2 a' r  border-right: solid 1px #5679bd;4 k! l- t2 `$ G- ?( I+ F6 a
  padding:1px;
+ U  Q& i; L5 f5 H) N4 g( S  margin:0px;}
$ a/ q" W6 ?3 ]4 I$ q: ]+ z  T</style>
: ?, |0 B0 ^* B4 P0 g<script language="javascript">3 A( G/ `9 a9 ]" a. ~: P, h' w5 H
<!--
4 k, h8 o. R  n) rfunction rv()* I6 i6 E  N  y: H% u, X
{5 a- `  Q. ^# [) m  G; ?, b% F
  var val="";
2 A6 `6 B' T; H, a% b  for(i=0;i<combo_box.list2.length;i++){
# \8 J9 i: Q7 C   val+=","+combo_box.list2.value;
4 M: C: O/ |" J* Q  }
! H7 }9 H6 F- a6 F  if(val.charat(0)==","){  n+ X6 O" G6 V! G0 o' V" J
   val=val.substr(1,val.length);/ Q# M4 n5 r, n9 J- A# w( Z2 X
  }) N& L1 R7 I  H0 ~
  opener.form1.frecname.value=val;
- q0 U2 H1 I( a& C  self.close();
) z( n# w5 U/ R}$ h) p4 U% G$ Q& N9 N
//-->
$ V4 v' B/ W. m' d  I) e) ?</script>
5 k  c2 V! F1 l<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">& R0 U3 K1 H- V0 i; c6 ]
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
2 C8 \' J7 O/ H4 X  c) S<%
9 ~% D0 k% Y: D/ T+ J" B5 n, _  cdatasource ds=new cdatasource();  //数据联结bean实例
( ]; Q7 M6 a# w  java.sql.connection conn=ds.getconnection();
! d9 l' N3 `" l- Q4 W: i  java.sql.statement stmt=null;8 R6 m3 ~+ ^, z* n
  java.sql.resultset rs=null;
  ?  x4 ]9 _* \, W) _# z( P  cdatacheck dc=new cdatacheck();
7 l4 @7 X+ {( n2 ^) n%>
6 F% \( @! e; @" ~$ K# z9 T4 M<%  O: ~: j. }2 ~3 O- j  P
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";% D) X0 _* u6 v# E3 w
stmt=conn.createstatement();
& M0 u3 k/ E' A5 x/ trs=stmt.executequery(sqlu);
# J1 }3 F* Q1 {( a7 a& L. Q%>
$ a2 [4 o8 D$ [8 b<script language='javascript'>
3 E1 h+ O3 W3 n# W& @) N0 f& Aarr = new array();
* M! C$ B6 n- T7 R2 I4 R; i<%  int temp=0;. C! Q/ G* q  X3 P# k" V# X
while(rs.next())' `8 m+ p( s. I9 K# Z. d& t- ]
{5 v2 f# |% c+ U
%>
( f( A1 W9 U( k: ~2 S0 `" G: Oarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");$ J0 L+ E' P: _; Y; w
<%
& F. g* m1 R+ gtemp = temp + 1;3 x& t& S) ~/ D* V. c0 o
}
6 J' ~7 L4 I/ Y/ L%>
- L/ e1 c# b. d% g- N3 ]$ ctemp=<%=temp%>;/ p1 g+ X. j2 M/ L  y# Y
function changelocation(id){
+ p7 D* t2 t5 C9 v" q: h, Xdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
  T6 F4 T. I  I; [, E! e# Wvar i = 0;
6 g) q+ e3 V, q- e) ]7 `. V3 Idocument.combo_box.city.options[0]=new option('-------','');
/ t; C4 G7 H* v# |) E5 |/ K$ Ifor(i=0;i<temp;i++){
$ w- i9 _8 L( }, p& C, }if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
3 f4 b6 q; u. P3 ldocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 6 k. a/ Y' o! u! w. P, ~
}
6 V  x/ ?7 p3 r; r6 e}
5 V, X6 z- H* L7 t0 h4 {& L- w}
1 u3 e4 j3 I( [+ e# h( g8 d</script>
  B, ~% d- Y  ?5 h; h7 X2 u' H  V
<form name="combo_box">! A% }, t; w$ H6 t% h
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
/ ]2 \/ x# Z- u" n1 J. j  y1 v  <tr height="24">
) w& b8 r/ o3 z    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>; L$ l1 x, w/ l, p
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>- _' u6 ^& H% s9 E+ D1 L
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>! z* s  n, C0 U
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
5 Q  e  w' v9 Q  </tr>
. r, q; x" Q' W: y9 X  H  <tr> ' r8 H, B6 S" l% \7 D
    <td>
8 l2 V$ ?- T: f2 V  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
0 Y3 o" B* |% b  <option value="0">请选择部门 ---></option>
) d9 V  D' u6 a7 Y; k6 h: s+ A# N<%7 e+ i4 B  p8 C- H) m
    string sqld="select * from tdept";
, y8 o) Z+ {  c" r) ~" Rstmt=conn.createstatement();
9 F  `+ b. e: P0 B! n# w8 Brs=stmt.executequery(sqld);
, q# u! M6 D# r6 jwhile(rs.next()); h5 x1 _' B& H7 M) f' n( `( j. w
{
; n4 s" p9 i8 k/ X  H8 M2 U%>
" q% Q. E4 c/ |! Q9 k! J; _# h- G  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
  d( h. h8 s7 a5 {; c  q5 y<%2 k2 Z* W) I3 u3 k( a- F
}; q$ B2 O6 T" w5 K, e* z$ H9 V
%>
4 J7 A7 S9 w3 k( S2 s6 q& ?: W  </select>3 j8 B5 ~* H( X7 X
</td>! N3 o1 F7 K4 s
    <td>
: R0 }8 V8 Q. g0 j6 H& v  <select multiple id=city style="width:150;height:200" class="bgc">3 e8 \/ y' \% y( f2 o" \
  </select>/ h2 f& `: J& F# {  F& N
</td>
5 Z  T! t$ S! T8 H    <td nowrap align="center" class="bgc">+ x; q9 x% @2 I2 D
  <input type="button"  value="<<" class="buttons">
2 U( E" G5 i$ Y1 R  <input type="button"  value=">>" class="buttons">
- M  b8 ^2 T' E' P. Z8 m* |</td>) Y4 G/ V8 a6 F) ?) B* C
    <td>5 ]* J6 w  I. m5 B) ?- `; N* I4 Z
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
0 E: S4 z/ ^) w2 }$ u7 w) [+ X) l6 U  </select>, c' U& X# @6 c/ j- t
</td>
6 z; Z- ^" P* W; J' h3 e! l  k  </tr>6 g& h8 g. a% S' a/ Z4 h
    <tr class="bgc">
' ^; Q2 Z& W6 E+ d& q$ u9 o% }, j    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>6 u9 c9 Z+ Q  ?+ y, T! I; B
  </tr>
; g1 `6 t0 K; n9 m, A8 q</table>: k9 T3 j( g- C8 p
</form>( U: m/ L) D& F9 t5 T0 `
<script language="javascript">5 ~" W; z: f( {3 A. n, F9 l' L9 r
//人名移动! V- U2 U0 W# ]4 w
function move(fbox, tbox) {; n5 j' a! Q/ @+ }$ Z: D! E1 V
var arrfbox = new array();* P  x7 a5 n. o+ g: f3 h; b$ X
var arrtbox = new array();7 R, _: \7 T# _/ x% |, l" I6 U3 M
var arrlookup = new array();
9 H: ^$ @# [! @1 rvar i;. G  S" L) o# M8 M( ~' Z' J
for (i = 0; i < tbox.options.length; i++) {
  |8 w4 H  Z* o. f5 {arrlookup[tbox.options.text] = tbox.options.value;
6 E+ X' A6 P. C; iarrtbox = tbox.options.text;+ e+ t, ?" S4 L( G
}6 \2 ?  D# k% ~8 [
var flength = 0;
3 F, [- m9 a& F0 Gvar tlength = arrtbox.length;
! E0 m2 g# {6 q5 tfor(i = 0; i < fbox.options.length; i++) {) S- A( n- _6 q5 y3 M+ w
arrlookup[fbox.options.text] = fbox.options.value;
( ^  w1 X: Z* x! \3 Wif (fbox.options.selected && fbox.options.value != "") {  S# b3 p8 X: d9 L
arrtbox[tlength] = fbox.options.text;' v5 ?$ h& v7 v& R
tlength++;6 M% C# g7 Q4 s$ W! \2 A, k
}8 K2 j. G5 F, Z5 P
else {) A' r, L; h; Q' P
arrfbox[flength] = fbox.options.text;1 a7 L4 p2 F6 A& B( V% o8 I1 q! |. I
flength++;
4 O7 R- o  `  ~8 t# o   }
% t: N3 e- c3 W2 H) |}7 [* x) H* R- {# R) E+ I
arrfbox.sort();
+ o: A! K/ o0 m3 \# `0 B. ?arrtbox.sort();
) `9 V1 ~$ O" A3 y/ d: u5 P
7 i# ?/ b" c' B) ?( L* rfbox.length = 0;5 I/ z6 N* j9 ~  e
tbox.length = 0;4 d8 h' E0 \0 {6 d
var c;
% y* y- ]& ~5 S7 F7 {" }$ `for(c = 0; c < arrfbox.length; c++) {5 [% e+ f7 ]! g% o
var no = new option();
  r1 z5 J3 ^% o6 g6 _$ gno.value = arrlookup[arrfbox[c]];
/ s! b: d0 X* S" c- \no.text = arrfbox[c];! Z( r% T, I: }! k: p- Z
fbox[c] = no;
* o7 b/ Y* Q6 p, v. ~}/ z: A, z3 g! @
for(c = 0; c < arrtbox.length; c++) {
( U3 \, Q) m* P" Nvar no = new option();- i5 h6 E/ n/ T; @
no.value = arrlookup[arrtbox[c]];
6 i" O7 Y4 R) b  m- r( R; cno.text = arrtbox[c];
) V, z$ e: j, j* V8 ktbox[c] = no;: e. F# |* g6 y" r( R% Y8 P) F- p
   }/ ^( C- t$ r* [+ O
}
, C% i/ a! M2 k</script>% c- @* @1 @# Q- G; b" m+ {
</body>
* O/ @9 |; A. V. M8 i( t+ I0 Z

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