返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"1 \' n" I  i) m3 g
         c pageencoding="gb2312"
3 v) h8 u- K9 t' d# p5 q%>
0 ?( q* ~- d  e) P# t<style>! F+ ?. u  q5 R0 J/ c
.f9{ font-size:9pt; }
9 N* V) w! }" a. {' {1 Y- S6 j.bgc{ background-color:#aecaf9; color: #0033ff }
$ c* Z0 \) A4 g9 P7 d. V% r/ x$ @.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
7 O# p0 a; z; F4 u) w+ v- d  border-bottom: solid 1px #4e7dc1;
; u9 _+ k4 S/ {  border-left: solid 1px #aecaf9;
/ L+ p' H% @# D  N; n  border-right: solid 1px #5679bd;4 X& U. D& ^% P. G2 B# |& u# U
  padding:1px;
7 g$ h( Y6 @  U4 Y0 F! I2 R' t  margin:0px;}/ W# C* w8 v# w! {/ T" G! y4 y
</style>
) `6 @& r: p; r4 D# f<script language="javascript">5 H, {- i) C% f/ T+ C1 @2 J" V
<!--
( }1 U9 X; x  bfunction rv()2 E2 r* `/ I  [0 d2 T
{
8 g+ M) b9 {' v4 f' Q( r/ P' j1 l" V  var val="";
* [4 J, s; B% g$ R  ^  for(i=0;i<combo_box.list2.length;i++){/ ^6 t. v0 m3 C' B. w1 @
   val+=","+combo_box.list2.value;3 O3 {  w& Y: r4 ]: k5 U
  }( r% M4 g7 G- [: X" j4 |# I$ S" B
  if(val.charat(0)==","){
) w- a7 ?. Z  H6 H   val=val.substr(1,val.length);8 y0 Q; H/ e! n' l5 F3 m
  }
. U& u5 l0 ~: Q( ~% Y2 T4 a  opener.form1.frecname.value=val;
( \, t3 q/ r9 ?  c1 H! Y( y  self.close();
7 o% \+ W. ~$ @4 a! [8 t}. ?" j' n+ Z. J3 C
//-->( [0 q5 d$ i& F: W) a
</script>
, K5 i7 q2 w0 |# j( o<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
2 h) k' I3 J7 y- ~, {<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
) Z  z& _; w9 O! G<%0 a) W% m9 i& d5 r1 Q3 z
  cdatasource ds=new cdatasource();  //数据联结bean实例" F, T; ?: x9 n5 v
  java.sql.connection conn=ds.getconnection();
) O1 v3 k' _( U: S- u6 {/ X  java.sql.statement stmt=null;
/ W) [- ]- [) {* _$ \  java.sql.resultset rs=null;0 c$ K; B/ M0 w
  cdatacheck dc=new cdatacheck();
, x3 |$ M# }6 Z" O; x8 \9 w%>) t% f7 x: M8 C
<%
) f& R, {- `+ k' j% z/ _. kstring 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 n, i. g( t8 D$ n- ]6 w5 B
stmt=conn.createstatement();, L: C- p+ a3 ^3 [2 M
rs=stmt.executequery(sqlu);' B  |0 z0 q$ \2 b4 O
%>$ L9 j) w# b1 F. a* h
<script language='javascript'>
7 ]& ~7 ?" v0 p) O6 ]3 Zarr = new array();5 D7 s9 L, x. t, S6 G
<%  int temp=0;
) B9 B: w" P: b( S: Uwhile(rs.next())
/ N8 b( P: @! {/ j% ^& J. z{
% ^# j+ ~: e1 f1 [1 x1 P%>
, i- S) K3 i6 c: r3 m: carr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");& h9 K1 L; k; m! U$ U4 E- i7 {
<%
6 z0 x& b2 r( g: J: E% Xtemp = temp + 1;
" T! |7 M; v1 h}* p: E" D2 F: z, [- A
%>
7 r! F* B* H: itemp=<%=temp%>;- I# x4 B$ q4 W( m
function changelocation(id){ & d+ N3 v' y2 C3 L5 d/ B9 q4 E" J+ S
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 / a. E  q+ O) i, z1 m
var i = 0; ! T* [  h; C* e1 u3 p4 A- L! L( c3 c
document.combo_box.city.options[0]=new option('-------',''); - G' w) D+ k' X" N
for(i=0;i<temp;i++){ / i3 R, Z' f6 `1 W" I
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 4 E* k" y2 H' ^, a
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
$ o: Z0 l; J8 h  A8 L& Q}
- P2 ?; q1 D, h3 F} ) }# j1 k4 c0 v0 B
}
# \/ q. h) \: m' t</script>% Q' S  x  U9 R& M

8 o5 U* u9 o; |1 j% P& p<form name="combo_box">
- {/ h/ x9 Q! t0 N- Y) c<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">! R6 L2 s  H, b
  <tr height="24">' @  W6 u: g; a3 `8 R1 n2 v2 L
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>5 r6 ]* ~9 K, s
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
- G9 L2 T  ]! y) E: o+ y    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
$ v1 O, Q8 n2 s3 W1 h4 o    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
# @; z' d( X2 _& X! O! q  </tr>
6 y3 |. J3 ^7 x, ]2 Y  <tr> 1 ^! G7 y7 r( I3 y) Z2 @4 i- {
    <td>
. P5 D! p, M/ P  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">- E9 @$ E7 n" C( F4 F- G4 P
  <option value="0">请选择部门 ---></option>
( [  K2 W7 ~3 K$ x<%% h/ {, F) Y" D2 R
    string sqld="select * from tdept";
; @6 s) @& b" ]  p. y$ \8 hstmt=conn.createstatement();$ E7 v' `! I, a% o( }
rs=stmt.executequery(sqld);# [; N$ m8 G$ ]) M. Q
while(rs.next())" ~9 F3 c% d3 B1 L4 w4 W
{
  o8 m" p" [( O1 Y%>, x' i1 B7 b3 R, W% M
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>6 q0 T/ p$ ?. c" M' z
<%2 d$ _" p. A/ B! [7 w$ X
}
: P; l: @- {6 s0 O5 X" h/ @%>
; K8 {& E5 b3 G5 V! d  </select>+ h! q; q1 [# e/ R. M3 q0 B: t
</td>
% T1 p0 G2 r+ F9 U% h1 O    <td>8 P0 M! J' f' ^* d$ I8 a+ W4 s1 Z) L
  <select multiple id=city style="width:150;height:200" class="bgc">" g$ F1 d1 S1 I! F4 y& K! J& U
  </select>
4 u- w- x4 {8 [4 q- ~4 A2 M% g</td>8 v# Y" u5 I1 S: b
    <td nowrap align="center" class="bgc">/ v% S) j: i$ H
  <input type="button"  value="<<" class="buttons">
" `- w! |8 b/ T  <input type="button"  value=">>" class="buttons">5 T! y( n) p: D5 O+ s% \2 Z
</td>
# b0 q: f% B0 k6 M# N- \- U    <td>$ R% ]+ z) b# z; {: m
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
4 P" J0 ^1 [: e0 P/ [  </select>
3 i6 \( D, B5 e/ _6 S: f</td>
+ w$ ?2 ?: N6 A( i  </tr>  a1 O. j* v( U7 h% ]! Y/ C
    <tr class="bgc"> + [0 U: l: ]3 ~( m+ x3 ^7 r
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>" O! b: u  Z2 G! e% a; E
  </tr>
) E# }3 V0 f: v$ m/ F. s</table>
. ~" Y. B. W, M; V</form>
" N! t+ ]. Y- m9 j<script language="javascript">
5 K/ H/ q# N3 B( V: a//人名移动  z' A; v' F! s8 @0 R
function move(fbox, tbox) {
( m' ~6 f$ E6 U; K% F5 z" n' Dvar arrfbox = new array();
1 i- N) q& X$ f* fvar arrtbox = new array();
. @: l: e9 j7 B) Z0 o; q8 Y( jvar arrlookup = new array();
$ r( M  z1 [# B3 ivar i;- _8 S: n: K% G+ D0 z* }( O
for (i = 0; i < tbox.options.length; i++) {5 f  S- K) L  c: R$ V
arrlookup[tbox.options.text] = tbox.options.value;) T6 C! d% Z& h/ p
arrtbox = tbox.options.text;
2 \$ H% F8 F4 K1 G}& h& R. h9 F; b7 u$ y0 d& n$ \
var flength = 0;* ~' m8 W  g1 f
var tlength = arrtbox.length;1 S/ Z! h+ `8 F& b2 T4 T) p
for(i = 0; i < fbox.options.length; i++) {9 n; y, g8 v7 i/ O1 X  g/ p
arrlookup[fbox.options.text] = fbox.options.value;
) Y+ r/ z" w' s$ n% w5 ~if (fbox.options.selected && fbox.options.value != "") {
  |# o/ e, V5 A4 j0 D1 oarrtbox[tlength] = fbox.options.text;- l4 n7 F0 |5 T4 r! S
tlength++;
" R% |3 u% d" O) @, G}" c# S. D! y3 }6 S
else {; f" m/ {/ d( e8 u
arrfbox[flength] = fbox.options.text;* u+ d* c' y5 [
flength++;) I9 ~2 V$ C: F) T% p
   }" [6 v2 Y( _! W: I, J
}
0 x, T2 `% E# f" B2 Iarrfbox.sort();/ j+ u/ ?6 P; |( G' ~, z3 G9 x
arrtbox.sort();* y; H) S3 J7 g5 k' s5 D. [
! `. h+ w: `! _. I+ B
fbox.length = 0;
; D" O9 O8 p! m# e  F' ttbox.length = 0;5 J/ i1 h0 E% S( ~" @) y
var c;
! S& V* _7 {$ m$ Q$ X+ _for(c = 0; c < arrfbox.length; c++) {1 P0 Z* {3 e# t9 q( I3 |' V( g" }/ W
var no = new option();
. y4 B" F# W, b/ Lno.value = arrlookup[arrfbox[c]];6 `9 i* z7 D" z9 _9 q, _
no.text = arrfbox[c];
: k1 _9 s) @* w0 yfbox[c] = no;1 ]! d0 R+ s4 U
}
' h/ X$ A) @2 C9 K. t" \' efor(c = 0; c < arrtbox.length; c++) {
" ~+ z/ L! j' [. A8 ^1 p1 y0 _var no = new option();
/ k. X' s3 r/ L% s4 C* Gno.value = arrlookup[arrtbox[c]];
5 x5 s  R% s4 E' q8 r+ I# Vno.text = arrtbox[c];
& f3 F+ p0 |/ ]) htbox[c] = no;
2 A! o1 D: o; H+ \/ j   }0 z, [: M8 `. @8 r( I! S% K
}
) m; Z- T9 W/ o9 t* }, O: y# W</script>
+ L+ e2 S- f3 U</body>
' u) L2 S' e9 B1 Z0 ]" q

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