返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"2 ]/ m; j! g. w# I: Q, W
         c pageencoding="gb2312"* K; m3 B7 {7 M+ e; R0 i6 y& j
%>
+ L4 ^1 K% j( j; m* i3 R<style>- i5 X9 P7 n8 V5 L
.f9{ font-size:9pt; }
' I" H. \5 N8 [& z/ n8 [.bgc{ background-color:#aecaf9; color: #0033ff }
3 o1 s9 y1 \8 z- _. `0 _.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
( a9 U  _1 ^0 W2 W9 H  border-bottom: solid 1px #4e7dc1;: P2 b1 S: c7 {+ t6 l
  border-left: solid 1px #aecaf9;
8 D6 j- r2 W8 w! H  border-right: solid 1px #5679bd;
) H$ t$ |/ H7 y* B  padding:1px;  [* L  j/ M' F: G* F1 ?
  margin:0px;}
$ _2 b: p) P" C) k</style># S( s" {6 [8 b# o! Q5 w. l
<script language="javascript">
% K: w, i  u# [: \0 S$ j* [: d<!--
. G5 D- _& N0 ~' Q& g& lfunction rv()
; E8 |0 A% o+ F. k9 \' F1 i{  b* a$ D! q: v" w
  var val="";( i. z* I: S$ Z: C
  for(i=0;i<combo_box.list2.length;i++){
2 Q' F" o/ k9 ?8 d$ F, Z   val+=","+combo_box.list2.value;7 \# \! ~. x8 L+ A6 I% s, @3 K5 V, z
  }( Y5 S6 j. y) q; U+ x! D: V
  if(val.charat(0)==","){
) _; X0 h% s, m* K1 X   val=val.substr(1,val.length);3 M/ s( o$ Q1 n6 Y
  }
, w& H( [: M; M7 Z# N: Y  opener.form1.frecname.value=val;
/ G& z* K: ?0 ?- z  self.close();/ u& t! q5 ?! s
}# I% O: l0 x& |+ q2 K) C/ {5 M
//--># Y1 Z& R* q( @1 H
</script>
0 P5 l) {' y0 }6 ^! s% m2 Q<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">$ Y) G! C# h- L
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
+ K$ X9 s/ @3 Z( e+ s! F<%- L; l: r* Y  b7 i  ?( h
  cdatasource ds=new cdatasource();  //数据联结bean实例
# b( }/ Q% |8 y) p$ B4 {+ B  java.sql.connection conn=ds.getconnection();8 I/ E5 }$ L$ u9 I+ P6 h) e, X
  java.sql.statement stmt=null;
6 D9 G0 k6 ?" J  java.sql.resultset rs=null;
) [) G6 I! H8 ]8 c) W  cdatacheck dc=new cdatacheck();2 m6 L+ E6 G9 J- t* N1 `! s
%>
4 g) S4 }& A' A9 Z* N<%( |8 w3 @" A: I& n& Y
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";1 e$ i" R5 f  S5 P( Y; i
stmt=conn.createstatement();
9 O9 \2 w- r; i) zrs=stmt.executequery(sqlu);
# m4 ^0 ]4 z5 ~9 s7 c3 J( }%>: L  d% H' H/ D
<script language='javascript'>
  x7 v! c- a$ X9 ?1 Sarr = new array();$ g0 `5 p2 B8 l1 J+ a
<%  int temp=0;! Y( T: X1 D8 F
while(rs.next())
" X0 X% d$ ^: H( E8 R0 d" a{1 d) S7 n9 d/ [; F  R8 x( l6 ]6 r
%>0 e# F. q7 j) J5 h: [5 {$ e4 N
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
# z0 H. ]2 R- g: E5 c6 l; h<%
% K) A. Z- n& C# U7 I+ F( Ntemp = temp + 1;$ u$ Y  c4 z- N, e9 H
}
/ Z" ~' q' V( Q; k%>" l0 M% f7 e  e( l/ z+ K
temp=<%=temp%>;' m1 b. k7 m1 i/ m, y7 i
function changelocation(id){
1 w/ x# d# L4 x9 T4 K2 r7 T- Bdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 ! j& \3 q+ A) N
var i = 0; 5 o% |+ v. u3 `8 w7 z9 x! O
document.combo_box.city.options[0]=new option('-------',''); . k  q+ P3 x# d, j: a- @
for(i=0;i<temp;i++){ ' E2 _7 q% }. T4 v$ }2 o6 D& B$ q
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 3 b% U$ I) X- g4 q. Y8 n
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
& l6 ^; D8 R. n2 H% M( P( Q  Y, C$ h} ' k9 ?7 j' |) T
} # R# e* o2 U- ?" ?. T# U
} ' n/ }. n! l! |2 K, s
</script>
$ w$ {* t1 B# D8 x
! ?8 T5 }2 b/ D2 \2 h) |7 I  d; V<form name="combo_box">+ V1 w6 ?  H; E1 F- L9 V
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">  f% l( z: T( d' n$ |) u
  <tr height="24">& Q/ ~4 z. f& w: E
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
" F8 i! S: F5 X" h. v    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
7 N7 m$ t9 P/ R6 l! ^" \. X7 L    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
' R! R) D: _3 r( Z  v! b    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>. y) g" c& ^& ~* T6 J4 k/ X
  </tr>2 Q& Y& ~+ d" S- l( l
  <tr> ! x: L# a+ X$ ?7 |6 H; i
    <td>. h- I+ a/ f0 s! h$ w# q* [: H
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">3 j8 @) y+ P) o8 Z# X' P; Z
  <option value="0">请选择部门 ---></option>7 u( e/ d# s2 E
<%2 }' W6 a; W2 i. _- F4 N
    string sqld="select * from tdept";
6 R3 W1 Q( j+ Z! A+ lstmt=conn.createstatement();) O/ ?+ t9 l  l4 Y1 l. t
rs=stmt.executequery(sqld);
9 m# v7 w) d4 b0 q, e/ }while(rs.next())
7 x: D& w& J5 x6 I/ x{! \6 ~$ m2 E( h3 e# N4 y7 i
%>; Z5 D6 `! f$ b1 I4 }
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>) |5 L. |6 W5 d1 V7 N
<%; Z) B0 S8 v! q
}
1 Q8 k8 W* v9 ^%>
: l! F% }" O4 f  </select>
4 I3 r) a( I: @9 `0 H, i# ^4 R</td>
( S, b5 o9 A" |; w: m) a( W    <td>
$ v# K; T, b- D8 `- l- z* H  <select multiple id=city style="width:150;height:200" class="bgc">% n7 [( S" C) S2 k& F8 G
  </select>
  W7 v* ]* D0 }% H) B+ r( i) r</td>
2 u" ?4 P1 I+ \& {( ?6 O    <td nowrap align="center" class="bgc">
2 f6 }9 Z# `9 ^/ n+ I6 I; ]  <input type="button"  value="<<" class="buttons">
# E+ r) l: f% ~  <input type="button"  value=">>" class="buttons">
8 `2 \0 I. A/ R: P</td>
7 Q5 R6 R/ w( f! ]2 t8 H/ O9 J    <td>) _  Y! V  R8 z% v& g1 w0 ^3 A
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
- |/ s  |: }+ F. X8 W  </select>
; _4 f6 L8 I* S4 y  Y' N</td>
* T% H4 D% @) l" q, q( U  </tr>
- \9 \/ X9 O& e    <tr class="bgc">
9 T; ^  r1 N) y4 F0 d: z# i    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>3 [4 i: F# x+ t+ f- `! R0 s' }
  </tr>
- Q8 R9 r# o* p1 X2 A</table>
2 U5 l, I: ~& f</form>
8 p" z5 B5 C7 M9 i* O<script language="javascript">7 e% O# @1 \3 L6 I' W" E5 H
//人名移动
# U5 ]8 I) C! B: ?function move(fbox, tbox) {
. _! i2 P/ l2 z4 J& b  qvar arrfbox = new array();: {" {3 L$ c) T' ^
var arrtbox = new array();5 G6 B9 t: F7 F9 ^% B
var arrlookup = new array();
9 \& r/ M3 ~9 }9 v! J" pvar i;1 q) [  I/ Y# g- {0 F2 Z; P
for (i = 0; i < tbox.options.length; i++) {
3 U' n, ]2 Y1 y  D) Darrlookup[tbox.options.text] = tbox.options.value;
' K" W; W9 \* q5 ]5 narrtbox = tbox.options.text;
% b( v. B/ ^. E* f! M1 f}" X& E3 m& N) {4 {. `
var flength = 0;# R: \0 r0 t, X; c9 Y
var tlength = arrtbox.length;& Z! ^  [* F2 q6 |+ k
for(i = 0; i < fbox.options.length; i++) {  D% u8 P' d4 w9 l
arrlookup[fbox.options.text] = fbox.options.value;# v9 I4 j9 K) [4 [0 i
if (fbox.options.selected && fbox.options.value != "") {/ p& T' s" ?& C- ^; W
arrtbox[tlength] = fbox.options.text;
, f, g2 K' f8 F% h9 w1 qtlength++;  Y! B2 G8 S6 e& h6 Y: @7 o9 G( W
}
; C: p- Z! a* M. e1 Q* qelse {
* l6 z  b/ m/ y9 W  h! earrfbox[flength] = fbox.options.text;" Y! q, h4 ^" l% U* W7 i6 ]
flength++;
* D, Y3 l+ ~8 G+ }7 n7 e1 s   }8 M% t; Q: B9 f9 e3 J; P) Y# \
}
: O+ {7 b! X6 E) w9 {! Y9 s7 S7 y1 Karrfbox.sort();; e0 |% [0 Q, J
arrtbox.sort();0 B- l. N& y9 J  [* P
4 E3 \, R& T. m, O
fbox.length = 0;) s$ t1 n$ t" i7 |* A+ F
tbox.length = 0;6 \% X, a) k6 P* W; d
var c;
/ U. C0 Y3 g- l7 G* \8 P1 Jfor(c = 0; c < arrfbox.length; c++) {/ D' T6 |# s/ d; a0 _1 A) n: E
var no = new option();3 E8 T6 z1 E4 r1 Y( G9 s0 e$ i
no.value = arrlookup[arrfbox[c]];
6 w6 G! U9 l' l8 n& W6 Bno.text = arrfbox[c];& s- J7 r. I- V% K- \1 Q8 Q
fbox[c] = no;
) K( N( Y/ L( z' z}7 [/ m; Y3 p, a: x
for(c = 0; c < arrtbox.length; c++) {
. v& W3 @5 Z1 t) J" v  _var no = new option();& x. Q1 o2 O# @$ `" ?0 M& b9 d5 ?
no.value = arrlookup[arrtbox[c]];8 L2 O/ c3 ^3 l: Q: g4 K; W$ O
no.text = arrtbox[c];6 n7 o: V. A, f2 p) X; z4 b
tbox[c] = no;. p2 V4 l. O7 G  V0 P
   }& W# r0 r2 D( p' m
}
. ^" n7 h: M) r# |. h+ g2 Q  g+ X</script>1 N( _1 C) Q. Q) O; v
</body>% R2 g: K, r: `# N

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