返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;") _8 ?' x: f' g$ z3 [6 X; F; X8 B
         c pageencoding="gb2312"
# y8 R" r3 F, n, j0 l%>' u1 L5 _$ ^( q% w8 i8 K: q3 [) l
<style>6 r) {9 i& g- u6 |
.f9{ font-size:9pt; }
/ x  t/ O, X/ q! ?; m8 r.bgc{ background-color:#aecaf9; color: #0033ff }/ w8 Q" m. T; [
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;+ u9 Y  I* @, X" x, D- J
  border-bottom: solid 1px #4e7dc1;2 x" ]1 ~; ~5 F4 I1 b
  border-left: solid 1px #aecaf9;
0 A& A+ S( i" c/ s# g  ~/ ?; y, K  border-right: solid 1px #5679bd;
9 s% ~/ F( n3 V$ ?0 U  padding:1px;
& m$ c' k2 V4 H3 H: `% V! z% c, V  k  margin:0px;}
! d6 Y& u2 V5 ?3 l  p$ o, k: l</style>
8 O/ K9 ~& K7 q6 }5 k<script language="javascript">
: }9 K( Q# K# f<!--; J+ |" w1 @# u2 b
function rv()
" c* S) |" _5 p9 w" g{
/ B! O2 M1 q/ G* Z; {- ?) X  var val="";
+ Y4 W* q' M6 [& N% `* u! }# {0 x  for(i=0;i<combo_box.list2.length;i++){/ v& U( i% W  I" ~. y
   val+=","+combo_box.list2.value;
: [, a0 [5 U* n* e3 O1 \) o5 y  }
; w) t3 a1 R9 B$ J3 [9 L  if(val.charat(0)==","){
6 D3 n% S9 X% g   val=val.substr(1,val.length);
9 r$ X9 u8 [5 o3 E  H' S  }
) U( C4 Q+ P7 D4 v  opener.form1.frecname.value=val;: S+ E2 G& p, j7 z: \! V& \
  self.close();: H0 W2 U: p/ j  z# y! Y" l
}% L  E) h# y- O1 X$ ~' u0 I6 j0 D
//-->3 V3 V" ?# X" H/ @) f
</script>4 z% L- p" N3 O. H( O
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
, ~* l4 H5 q& w' f$ g1 A0 Y4 t<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
/ O. W# K- }; l6 e4 q- J; X<%
& S( q4 E0 o- n3 n3 M" \9 a! w  cdatasource ds=new cdatasource();  //数据联结bean实例; ?4 g5 e8 I; n0 s6 G9 \# p7 ?8 n
  java.sql.connection conn=ds.getconnection();7 d1 e* ~- W" u6 q! j" g/ X
  java.sql.statement stmt=null;( ]" y7 P* X9 E/ V6 R
  java.sql.resultset rs=null;- q' |! i$ m% R! p) k
  cdatacheck dc=new cdatacheck();% B' c) Q7 K' P. t7 H! @  u& q# V
%>
: p& `% q) f3 W1 i% z- q6 `2 t' j# i<%' B5 a& X5 X! _! o# S% U0 o
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";9 Z4 k- [4 W2 o9 c
stmt=conn.createstatement();9 ?- q) T6 o" f2 f2 x+ }
rs=stmt.executequery(sqlu);
3 i! E2 X" i* B3 J4 W%>
: y1 v7 [2 L0 f<script language='javascript'>
" P, c6 j' {4 J0 c/ k7 v, r. iarr = new array();* m- Z, a; F3 b  j% u
<%  int temp=0;) R& T1 m- d/ ~( T" p2 Y" x' K8 ?
while(rs.next())- F+ z' w9 I2 B2 }1 C
{0 S6 P+ O- C& L; V! [
%>& Z  O" Z8 W8 u3 U8 Q. B$ h4 X& p8 t
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");# ^9 z1 K; r% Q( E: q& e3 R5 J
<%8 a6 O: t9 B* y
temp = temp + 1;. d0 @8 z4 t, [" l+ w
}$ j& w  O2 D% d( L# l. B. h
%>
6 u! Q: S# l/ e: m; ]5 M+ \temp=<%=temp%>;6 K0 b! E0 s) A# ]7 z' e* ^2 ~: n
function changelocation(id){ . I0 s6 ~* i! V% ?* @
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 3 X# o1 B* F  T  n1 i; @" \% f
var i = 0;
7 q, {' u" r" i; q6 V9 s- E7 xdocument.combo_box.city.options[0]=new option('-------','');
1 s' p7 @3 t& _for(i=0;i<temp;i++){
7 _: V6 P. p" q; V2 {' e2 Fif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] - X1 Q# L3 L7 P  [- y8 ~" h
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
, W. X  z- |, u  N3 y8 d6 p} # V) U$ m; y* q  a# W) Y' H
} 9 v  p  F: ^6 o
} ) }5 A3 o. }) W3 D( n" d  B
</script>
+ ?( n  x+ {) u" L  Q& R8 p, J$ d7 V
+ d7 d" a2 w9 [# \) S- X" A: i  Y<form name="combo_box">/ y; X/ Q3 [. F
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">+ A5 p- K) Y8 Q4 Z  J3 ]- f+ |' |, T
  <tr height="24">
% r$ s: C$ q9 u  D6 v$ |    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>* ~' u* i' q7 @) v& {0 N
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
1 ]  E' d8 {' L& h, B8 W    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
/ k0 B1 O! r. k    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>" b9 B& P2 J* ]# ]
  </tr>3 ?$ o+ v! t; U
  <tr>
% W# v$ f$ G* V2 T    <td>% m) d; ]2 a9 N2 t9 R
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">* Z, [" E' R9 [& H: N$ T
  <option value="0">请选择部门 ---></option>
" G1 g" f7 B5 r/ e, n$ ]; Z8 ?1 C' B5 W<%0 x7 n, p# y% Y. t! z
    string sqld="select * from tdept";$ B2 B! I) C1 l
stmt=conn.createstatement();
1 R; x0 u$ y" u6 yrs=stmt.executequery(sqld);0 l- ?/ C( H  A; M
while(rs.next())# p+ H# f- j0 O' i3 P
{
) {* N4 v% Z7 A' Q8 n* r%>
/ v$ }5 c2 ]8 F0 h6 Z( B2 I  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
4 f9 ^$ n2 N9 u! l0 Y8 _$ b5 ~& @<%
) x+ s0 r; f/ f. h}
* J. s. e" ?1 i0 ~%>
- p7 M1 ]: W, K: C* {  </select>, q) K3 X* |/ L3 F/ I
</td>. v1 O$ B" f, ~- T; y
    <td>
& q: L4 \6 c. `4 k9 j  <select multiple id=city style="width:150;height:200" class="bgc">2 |  l  j1 E# v- q+ g1 _; D  ]
  </select>2 v1 d5 K* l0 Q$ f
</td>2 Z! K, A1 w3 a0 L7 ]. ?; F% E
    <td nowrap align="center" class="bgc">
; S# f  t! W7 v* b; ]1 U' u  <input type="button"  value="<<" class="buttons">
8 C6 j8 Z! o6 g7 E0 F) C" T2 S" M  <input type="button"  value=">>" class="buttons">
2 p; @- i+ R3 r% G</td>9 j" C, D0 @* [1 D
    <td>
# \" L6 _7 j: z; o  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">1 O& z6 N- d# [% j; [5 y
  </select>
! W% c; g( O: i. ^! Y</td>
# r; Z; p$ \: R, d  F, q9 U2 H- A' N  </tr>. K. X- z" a) q2 w. M% O( R( F
    <tr class="bgc"> 4 w6 @/ U9 d- L: Y4 `4 E5 O$ E
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
) R, X5 ?+ M% ]; o3 T  </tr>% H6 s9 s" }4 d+ V% i
</table>
% Y* g7 O& X0 B! u</form>4 J6 ^  X4 t2 }
<script language="javascript">
) B4 n. g5 b8 u/ v2 q+ o1 C//人名移动, _) R1 i. N/ r
function move(fbox, tbox) {
1 N) o' D2 g' J7 N: C! c2 qvar arrfbox = new array();6 s7 E* [0 O+ ~6 M% a6 ?. i- g, J
var arrtbox = new array();1 J; I5 n; J) C  E% @
var arrlookup = new array();
3 R$ j( i& ^5 w, e# t6 D+ cvar i;4 H* `6 w& {3 t3 n+ ~
for (i = 0; i < tbox.options.length; i++) {! b( O( C2 B) Z( V5 I1 _1 g: |0 c& q
arrlookup[tbox.options.text] = tbox.options.value;0 R5 |& A& u  u. q1 {
arrtbox = tbox.options.text;
9 I- p. |- Y. `0 K# M- ]6 z" `}
: i$ l# z- N1 w7 G. U5 q5 h, Fvar flength = 0;: @8 N) W# `: d& ~, o! w# F: V
var tlength = arrtbox.length;
( b1 ~9 G- r/ K1 ?for(i = 0; i < fbox.options.length; i++) {
: P+ E2 x* ?. H9 n, n, C" c8 ^arrlookup[fbox.options.text] = fbox.options.value;3 c8 n( z- d0 _5 ^9 M
if (fbox.options.selected && fbox.options.value != "") {# R2 h' j: T. y- Q( _
arrtbox[tlength] = fbox.options.text;
/ |# }0 U- @& i3 J3 Wtlength++;
. ^# @: h; i+ Q- h, y( ]}( a2 V; B; |; B' d7 i
else {
+ |  U9 i: ~( f$ r# F  darrfbox[flength] = fbox.options.text;7 ~' h6 ?( c2 f8 O4 J; D
flength++;( ~" W$ `, y4 _
   }' n; h9 O  z0 l, Z0 b/ {0 e
}
! B2 Z: d5 u0 r8 C' rarrfbox.sort();
/ K; K# S: V, E$ `$ s' {' _arrtbox.sort();
6 T, f: x* s% w; c8 v+ }
0 F+ O' c2 _( p5 `. f5 Cfbox.length = 0;
$ D1 |3 v$ O3 o: G  ~& \tbox.length = 0;5 H# Z* f! U/ K2 `) [$ O1 l3 I
var c;# e  P5 D" `1 N$ x) f4 q) m
for(c = 0; c < arrfbox.length; c++) {
1 ]3 B8 O3 C, @' h! ivar no = new option();
* b: @4 i6 f' S" j& i: c' ano.value = arrlookup[arrfbox[c]];. Q2 E' r4 M4 t' F
no.text = arrfbox[c];
7 P3 _- t3 K5 p' Rfbox[c] = no;
8 J! m( f9 u* j% o, N9 n1 p# l$ L}
+ G9 G" B6 U0 a& |. Qfor(c = 0; c < arrtbox.length; c++) {, G# a$ Q' L+ i' z# ?% J9 L
var no = new option();
+ R# m( G% x1 l- @; q( \& sno.value = arrlookup[arrtbox[c]];3 M+ @. m6 x; _; P$ M
no.text = arrtbox[c];
/ M" ]. r( o/ {3 q( c9 I' ftbox[c] = no;
9 m2 a8 L1 W% Y* ^* }! T1 ~/ F, ?   }, R+ Q* C  c/ v& u0 n1 T3 b% X! i
}0 m/ \6 p. ?, C+ x
</script>
: Z6 i& f5 |- c  R8 {# @8 x</body>& f4 |* M/ o1 Z$ q

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