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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
6 @) }' V/ z, r         c pageencoding="gb2312"
9 l: `9 D3 i0 C* Q6 j+ ^%># U. J1 z( z! h" m
<style>
# P5 o" }8 r) f& ]2 q* w3 K4 n! K. g$ m.f9{ font-size:9pt; }4 G$ W( A5 t  z
.bgc{ background-color:#aecaf9; color: #0033ff }/ E1 r1 t' L' Y! v' E0 v3 R- }1 A/ \
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;8 E' r( N' v2 i+ J: X2 I5 j+ R
  border-bottom: solid 1px #4e7dc1;; `! i% O! ]4 R8 P" D
  border-left: solid 1px #aecaf9;
1 r; Z/ L7 _) ]' [6 T8 h; i; l  border-right: solid 1px #5679bd;( s( u! y* B* ~# K7 g7 i6 l
  padding:1px;0 Y  k8 q; z% D4 O8 B
  margin:0px;}3 d3 h4 e( r5 \2 z3 p- P7 d/ Y
</style>8 I* n; Q  W4 }9 ~* f6 d8 y
<script language="javascript">3 e' |5 e8 O' e0 ~9 u7 C: O
<!--
4 a% j" G) p  C3 Pfunction rv()* r8 F' E( Q% C3 H7 |- v; v3 E
{0 l3 {0 O! a: r0 O/ V3 O
  var val="";
% u! t! H( Q; b8 W: J$ W$ `  for(i=0;i<combo_box.list2.length;i++){- t4 j+ P& u9 C, A8 n7 r8 Z; o3 v
   val+=","+combo_box.list2.value;
7 @5 b& p$ g$ Z9 G7 n3 w  }
2 Y7 K1 a+ Z- H0 ?  if(val.charat(0)==","){8 `* S! p$ W% o/ U# m; ~. a
   val=val.substr(1,val.length);1 K$ A/ g1 M) _7 V$ ]; {) _9 w. c
  }
& P# ?4 T# N* h$ \  opener.form1.frecname.value=val;
  u; L: }2 S8 @5 Q  self.close();5 V8 @0 W3 B3 Q: i
}( B; G" x- P% T9 ]( B/ [4 P
//-->
" L6 ]4 O6 i6 c# d- A( ?0 W</script>
1 a. W6 }# L+ k' @/ Z<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
" ?9 P8 y3 t/ @9 @( T<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />) O/ m9 A' \0 }) H; g# n5 r! }- e6 P( `
<%# |/ t8 b; B9 \% A
  cdatasource ds=new cdatasource();  //数据联结bean实例- _+ s8 G" [) z9 ^
  java.sql.connection conn=ds.getconnection();
& h; ]# P1 _, [. H7 z  java.sql.statement stmt=null;
3 ]# u+ v8 L' D- i: `3 \( q7 l  java.sql.resultset rs=null;, @) |0 e1 ^# b2 O2 {# r
  cdatacheck dc=new cdatacheck();8 p3 c% t- V5 r* z% Q4 s5 o# Q
%>5 \) S- {- n( X
<%
/ o; m) R7 q! @# 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";
) S! K9 a& Z$ l2 q! U5 G$ W6 o4 kstmt=conn.createstatement();
& ~& [9 L  V2 w, D2 Jrs=stmt.executequery(sqlu);
% ?  m7 `$ D, U: k' d%>! \& M1 n+ y8 y0 t' b
<script language='javascript'>, M1 G) f/ N! v* J# E
arr = new array();  v7 |8 v& V) n$ [2 L
<%  int temp=0;2 }7 k! L6 y% N/ P  O
while(rs.next())
: M& C& G; P7 [! n{- |$ M2 }8 T2 O% x4 g, L8 S
%>+ P  h$ y( f& P4 a% `8 ~1 W
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
4 R5 k) C* l7 \<%# `$ u: I& C/ L8 R6 @
temp = temp + 1;
* o0 L+ K, j/ M, e, C4 S, l}
) n: d: A/ E8 h3 i" g- d# C  v%>
$ f/ v/ ^1 Q# X$ @" p9 t& H# Ctemp=<%=temp%>;
4 h, d4 P/ ]7 I- `' y/ o6 xfunction changelocation(id){
+ A" e! S& n+ a. N# E! ^document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 6 z# n, E2 d. p, q! |9 t. e  }2 F
var i = 0;
: U0 I% F. m$ C/ Q) Hdocument.combo_box.city.options[0]=new option('-------','');
3 _+ A0 A, P# Z+ d( c$ u! Cfor(i=0;i<temp;i++){
: l1 b; D: K1 ^& r  j& hif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
8 k7 h3 d* u: f! @- A9 ^document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); * d, y4 L- l0 \" d7 J: l: s
}
$ c8 [5 \! k% L6 U} - g9 R3 u& g6 K9 x  S! f0 d/ i
} 5 e$ X$ }: M* T! S" h+ Z1 g
</script>
' X: O7 b! O6 u/ M- U
& V" {: t+ t+ P( K& }  T<form name="combo_box">
* {) [. r5 ?# G2 ]0 h<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
& I' o+ x  P# \  h  m: l. o  <tr height="24">
* P, Y2 W2 a0 T, I+ M5 g    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>4 _- U$ P  ^& Q
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>- m; p% U5 z0 T$ C! l+ u5 D3 B
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>" C3 Z1 K$ g; d
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
7 M& o6 ]" I5 D- F$ U) @; w  </tr>: W( \8 f- r( _+ L
  <tr> * l! `& w* t/ }+ r: j
    <td>& z$ x- Q) N. h6 V; h4 o1 H
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
# u6 R4 u0 o$ ]9 K" p. a" L  <option value="0">请选择部门 ---></option>  E! ?1 Q! g2 \& [
<%  X& d( Y% ~1 Q$ X2 K+ Z* k
    string sqld="select * from tdept";, u: T( d; h6 @: [
stmt=conn.createstatement();
* J  ^3 G$ z5 E' `rs=stmt.executequery(sqld);# f3 s; g: S" A& S; ]
while(rs.next())
- s  p* v6 I4 I5 F5 w1 [{
# |& Z8 P& _2 G6 A% q%>
% e- o# Z- }/ I8 _8 q: y  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
$ S) @) b/ R" y2 J- @<%  ~4 {3 j/ b# n# S% }  n- c
}
( J. p4 y! D/ @  ]# g& r%>
7 z& h% o6 m! Z* _4 S  </select>5 Q. N# k) q. i& `6 T
</td>
* K0 r, Z! j/ ^; b1 s    <td>
8 C% `2 X8 n7 y  <select multiple id=city style="width:150;height:200" class="bgc">+ ~8 y7 I, X7 w' |3 M( J) Q
  </select>" c) J) c2 b, L0 |% h; b
</td>
7 f) O- t# y9 f: D$ a    <td nowrap align="center" class="bgc">
- B) }) V- l& G& r$ G& s  <input type="button"  value="<<" class="buttons">
# _; ~/ D% U8 A1 r1 l% @  <input type="button"  value=">>" class="buttons">
: ~- h# }" j+ ?. f</td>: y5 i3 D1 c4 D& i! T
    <td>' t2 l/ ^2 ^3 y. j# t
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
3 D6 I% }4 K- ^4 H0 H  Y/ q5 ]  </select>
5 m+ F4 h$ R8 ]6 ]* [- P</td>1 f, U3 ?7 R  Z9 Z1 l/ S% Y
  </tr>
5 X3 Q+ P7 h9 U& u. Q2 S- ^    <tr class="bgc"> ! q& L+ c1 j/ R! a0 p
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
8 Q  H" a, z+ K0 m, f. X  </tr>  h, T; I+ [- a
</table>" q! _; D" m0 a% p9 I- E2 |
</form>" [3 s1 u* i. t6 K
<script language="javascript">
7 X" ^. m, M4 C! J+ B//人名移动. K7 T$ M/ l  M) w: n0 q
function move(fbox, tbox) {
/ A! V( y: H4 ?0 q7 d. M' E  Lvar arrfbox = new array();7 f4 C8 m, j) _6 j+ O
var arrtbox = new array();
) w2 {/ [& b0 k, o9 s, m( rvar arrlookup = new array();
8 o( }0 b, n" ?5 i% l% c7 I: x' pvar i;
% \- B  Q8 V) Ifor (i = 0; i < tbox.options.length; i++) {
% f4 T2 \  ]: [# harrlookup[tbox.options.text] = tbox.options.value;
9 t- x) L6 n  Tarrtbox = tbox.options.text;
! s. |$ P. C, L. C+ `* |0 z" Q0 P5 d}/ Y5 j/ L" P) X. w
var flength = 0;: F  \! b2 ~: P
var tlength = arrtbox.length;
, c1 P1 ~- u$ n/ [9 }/ c$ rfor(i = 0; i < fbox.options.length; i++) {, ~% ]) S8 o- i3 }4 P
arrlookup[fbox.options.text] = fbox.options.value;- |# i3 b# B" i  [
if (fbox.options.selected && fbox.options.value != "") {
5 \! l, S. |+ J! @0 zarrtbox[tlength] = fbox.options.text;
4 K2 V( P; ]( v- Gtlength++;
1 O0 ^# v  L) P4 E# [! F}; f$ s# N) T% L' \9 Y0 Z7 [& C: ?
else {; @1 v! `# o: \" P3 z7 v
arrfbox[flength] = fbox.options.text;
+ G2 k! o  F, @- f$ \$ W% P9 W5 E! @flength++;% r: i# Z7 k; S& N8 `. R, U, x
   }" A( j- Y& a# q% Y) ^) o
}
/ E( y) y8 y" b) o0 u& Qarrfbox.sort();  K, R& Z! H6 S3 j
arrtbox.sort();
4 q( [+ S: v# w1 V! d8 y
4 g! L. ?! z! p, u: Gfbox.length = 0;8 O( X# s" k  z1 _5 J
tbox.length = 0;
( V; z" x8 n$ tvar c;
) x/ X$ c; K% f' Cfor(c = 0; c < arrfbox.length; c++) {) f2 H4 t$ @( F  D, E& ^2 h
var no = new option();
8 |8 {/ _2 F" N9 T$ ]9 o3 ?no.value = arrlookup[arrfbox[c]];# u6 e$ y( }: G  W0 X5 ^
no.text = arrfbox[c];. Q# S, P# @: Q
fbox[c] = no;4 f0 W" e; t9 k+ B
}2 C! J5 i  P5 q. E% K5 E0 e1 R
for(c = 0; c < arrtbox.length; c++) {
: |- |, L2 h2 a- j" cvar no = new option();
/ [5 ~( U6 ?8 L( nno.value = arrlookup[arrtbox[c]];1 t. |+ m6 L% K
no.text = arrtbox[c];, z" K! u4 c' a/ M# S2 K6 Z/ J
tbox[c] = no;. w" I+ m( L- J2 H- E0 O
   }
4 r+ k0 ?) b7 p: A}
1 D' }6 L8 {7 L2 Q2 z</script>, J+ Z3 {% a  S( \
</body>( B( Q: j9 J( m

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