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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"7 C3 c" ?. X2 k  t3 O4 S
         c pageencoding="gb2312"
* ^1 R6 _  s* U%>; K$ d! X, X3 _, r
<style>% @0 M$ C7 r7 H$ G
.f9{ font-size:9pt; }
: g2 B' _3 v5 R.bgc{ background-color:#aecaf9; color: #0033ff }0 D! U9 O8 n" b3 x, m  Z
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;# Y- L8 X; j( \9 E0 Q
  border-bottom: solid 1px #4e7dc1;
4 ^. C. v6 T: V- K  border-left: solid 1px #aecaf9;/ e8 i1 \) R, ?% q0 y
  border-right: solid 1px #5679bd;- I8 L, Q% ?! s0 [4 G8 h) m
  padding:1px;
2 k6 c3 V( Z5 A: C8 Z/ _  margin:0px;}* y2 T3 d1 o" E9 o4 g
</style>
4 q# j3 q$ U+ c+ l$ n5 l3 E2 Z<script language="javascript">
7 L7 j8 D2 n  D( ]' d  B, H) H2 A+ w2 [<!--- {% O6 O1 r. z. X- @8 e: @6 v/ n
function rv()* O1 }" I+ Y4 J4 m% a
{# h" S: v7 a6 _/ @. _
  var val="";# O7 `' W5 y- {! A, o
  for(i=0;i<combo_box.list2.length;i++){
: u+ l  y! U: o   val+=","+combo_box.list2.value;- O) W, X! Z1 \# x
  }. s2 s* u  s+ [' i; B
  if(val.charat(0)==","){
# h  }  ^5 h+ m/ |' W   val=val.substr(1,val.length);
, x3 \1 i& H5 P0 g  }
1 t- ^' R3 U& n* C- e  opener.form1.frecname.value=val;
& v& R2 m, h) ~% L. `$ I" A  self.close();& }% ?  r7 K# v0 L1 [
}
% r4 {! s' E& A//-->
; N' Z7 E! Q1 a8 O. X; ?' D, X! U9 R</script>
$ Q, M1 s" M$ n* S% t7 J2 T3 B<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">- W* l% a3 L" d1 K, o
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
7 j( v% j  x5 b. s8 O* b<%
3 I1 s: P- V8 n, Q  cdatasource ds=new cdatasource();  //数据联结bean实例
# n$ O! n; |) i6 n  java.sql.connection conn=ds.getconnection();8 Q/ M$ K2 N3 l, q2 U- X# N
  java.sql.statement stmt=null;
" y. i1 J9 i( _2 E0 }0 h) A  java.sql.resultset rs=null;& Y$ e* b2 A4 ?) B. \* j" g8 o/ u
  cdatacheck dc=new cdatacheck();+ W/ `2 }1 N! f. ^* u4 G9 |
%>
, y' x( }( e. z6 Q; B- {<%8 {% L, ]3 U( M% U- E
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";! F. x; J# M$ f! R" C/ \
stmt=conn.createstatement();
# s5 l+ h6 C" C% wrs=stmt.executequery(sqlu);- E5 L# v/ H, o2 O3 R. _9 W
%>
8 E: ]& Y& r1 x) _) _* P  Y3 V. J9 S<script language='javascript'>
8 ~/ t9 s5 q/ _- `  earr = new array();: r8 o. p: [2 M3 E, ]
<%  int temp=0;1 k3 `# U0 }2 n
while(rs.next())
; v3 Y" L( m& S: c5 N; J{2 N9 I& j+ g! @% E
%>
" w$ l: t4 L# Z. K( n  Earr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");7 a8 V4 h7 |$ D& @* d, X
<%! Z) E$ t4 D+ [8 L
temp = temp + 1;
4 N6 ~8 ^# i& N}
8 G7 T- `% f- B/ c9 r%>
5 w- l  K6 a2 t  b7 f& G7 K, Ktemp=<%=temp%>;$ u3 i9 ^& s* L. Q* |# z7 k" F
function changelocation(id){
7 F# K7 i; j' v+ R  l+ idocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 ' `3 }  }; R$ b: N: _
var i = 0; 9 \/ ^3 b# j8 [- p
document.combo_box.city.options[0]=new option('-------',''); * S% x5 `% f1 d+ }' S
for(i=0;i<temp;i++){
# e- f% b, o: N, Wif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] , O; B: A& l4 Z2 D
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
2 E( x0 @: ]6 D$ g  |* B6 m  Q} * z+ G" `+ `: z4 t
}
4 o! h# N3 t5 w# W4 X+ E4 P8 G}
# b7 c: y6 j% S" v, U' w; u7 C6 y</script>8 ]3 [$ V3 j' h

  P4 L4 Q, V3 c$ K<form name="combo_box">
& M/ m' B0 v9 [$ Q/ q) e3 Z1 b* Q<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">5 z$ z" L! C% |9 S
  <tr height="24">3 e5 X/ R7 w4 p6 ^$ \
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
/ B" S4 L# W5 D  E* v) n  h' A3 `3 C    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>2 o1 M( a9 ], x% H
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
/ }5 V5 o3 z% h9 u7 @' X* ?6 n    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>* h3 w* M' N" {" e6 \
  </tr>
( I+ x* Z5 M/ O( B  B9 ]5 ^8 L( T  <tr>
- u. ?- U! b4 L  V0 @* M3 V    <td>! Q5 b8 X/ [& A
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
- ~8 D2 h! g" ]# ]- Z+ _1 k  <option value="0">请选择部门 ---></option>
" l+ ^/ g2 P, M6 `# @' `/ h<%
" ~9 @1 z0 f1 J: h/ Z" ~# @% z    string sqld="select * from tdept";
/ \7 i$ X0 A* W' ~" @6 hstmt=conn.createstatement();" D4 ]( ?# ~. q' U( g
rs=stmt.executequery(sqld);. c; T- [# \& \! x
while(rs.next())# P( u( v" ^9 Y* u2 ^/ Z8 N
{( s+ w/ Z, C- {+ N4 Z! L$ D+ L7 ?
%>1 M9 @0 M. n6 R; D& i5 W
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>, j0 b( O0 s% j* B
<%
- H3 E: J8 M0 Y: `- o- q}, i* V% C5 J+ k
%> * S- g( U0 P& P
  </select>. d) G8 }- v& v6 t: p
</td>
2 {) b4 j  s; W( V+ C- Q0 c    <td>
# e' }/ b7 B+ e* R7 Q* J; S. M  <select multiple id=city style="width:150;height:200" class="bgc">6 {. |. @' |$ C( `; z. s
  </select>" f4 i# E/ j5 D: m  k7 n: a+ p
</td>' [, r9 G; u+ W# c, C
    <td nowrap align="center" class="bgc">. [; Q+ j8 \) ?7 b, [
  <input type="button"  value="<<" class="buttons">
: L6 N, Q! N) b+ b% d  <input type="button"  value=">>" class="buttons">
0 O5 v% R1 Y9 I2 F* i, W3 d5 w</td>
. \% J  e. w' @; o+ E& X- I    <td>
7 f9 l' ?$ z0 z# \* i* b5 u  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">: r' }0 D( A' I" \
  </select>1 I- M' n. g3 y4 l# d* I+ d
</td>0 w5 B8 J- ]8 U
  </tr>' f% Z, k# |7 r4 p
    <tr class="bgc">
: R- I% ^9 C3 m0 t) T3 Y    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
2 D$ x: B6 b* _  </tr>
4 K* j5 _7 _  k</table>8 \9 k$ W9 u! I9 x8 f! }
</form>
9 X  G+ }+ ~) R: {" [: O; `, a7 c<script language="javascript">
. q& V$ b! m! }# J0 l//人名移动* Z- C) K: p/ c
function move(fbox, tbox) {1 @( m7 c% w  T* t
var arrfbox = new array();
/ A% ~+ c6 e& b. r: S, R- Lvar arrtbox = new array();
: M; X; H/ x$ _5 Evar arrlookup = new array();0 E1 m: t" Y8 [3 M
var i;8 h5 x$ M# p* \3 ?" S- m
for (i = 0; i < tbox.options.length; i++) {
7 }: _/ e2 h' a; rarrlookup[tbox.options.text] = tbox.options.value;( O) U6 F; t+ w
arrtbox = tbox.options.text;2 U7 j. O8 I- k/ h
}
5 h; F( w4 Z$ l  W$ Zvar flength = 0;# k, w. {6 L: C$ Z) Z" p3 X
var tlength = arrtbox.length;
# D$ `5 f, P; ^) f: g% Qfor(i = 0; i < fbox.options.length; i++) {* x3 d, ^, q2 o1 T
arrlookup[fbox.options.text] = fbox.options.value;& X: C8 T/ ?0 ~4 n
if (fbox.options.selected && fbox.options.value != "") {
# R2 Z9 L2 r! d+ s/ x! d& Uarrtbox[tlength] = fbox.options.text;
7 E# [3 Z& v* v# H, x/ Gtlength++;9 z2 X( i% H, T% A) u: t0 o/ z
}
/ o6 G* W  f) ~* d% eelse {; P* G; N. W" u2 |, H7 R# N3 G
arrfbox[flength] = fbox.options.text;% l# ]" Z% K% w( u; f
flength++;' i6 ~* Z0 ]4 d4 V
   }
+ {0 w' ]+ A2 w& ~. o0 n* i}/ z+ E4 m. b- j; S$ H0 W% c3 O
arrfbox.sort();
+ [8 M9 L/ ~& j. S5 `3 d6 rarrtbox.sort();2 Y) s: ?5 @( Y3 Q( L  U
7 `1 K% a! H. R8 K' H! |
fbox.length = 0;
- l$ t( i2 q$ g; a2 _6 @tbox.length = 0;' k3 o( r) s5 u
var c;
/ W' r0 t+ T, V- C. O: Z5 c1 e% Zfor(c = 0; c < arrfbox.length; c++) {- l4 m- R5 Z4 y& R& R
var no = new option();
) s, x" f  n4 e" O( bno.value = arrlookup[arrfbox[c]];1 b; ]# N% _8 s2 I- s+ H
no.text = arrfbox[c];
% F  `, a/ `6 V5 C7 g# ~fbox[c] = no;+ `3 Q- f2 Q4 P
}! w4 ?+ o; R; i/ S: O
for(c = 0; c < arrtbox.length; c++) {. {, y& x0 Z# h9 Z( h
var no = new option();
1 F$ T5 k  n1 q. \3 w, hno.value = arrlookup[arrtbox[c]];
7 D$ ]* Z6 m3 H' k$ ]no.text = arrtbox[c];  c% n8 {9 Q) C. I. `* ~
tbox[c] = no;) ~0 }5 c0 V5 Z: n' F& {
   }
; A4 I, o! n4 ]2 v$ _}
; t& Y) C% p5 l! F</script>
4 ?6 G$ s& C1 Z' S0 u0 V</body>+ P+ l$ m7 E9 S, S( r+ \

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