返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
* [, @! a0 C* M- o/ X# u% j" X         c pageencoding="gb2312"( M* J- y; I. \; [. a' i4 W
%>3 L- K6 u0 o" F9 q0 V
<style>$ ?, O3 g0 _) B0 P2 x8 E
.f9{ font-size:9pt; }
+ k3 j" ?/ [6 c.bgc{ background-color:#aecaf9; color: #0033ff }
4 f* z- Y& Y' Q3 P' B6 a& z. O' E.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
/ j% ]4 M$ n# G% c& \& S$ Y1 g9 V  border-bottom: solid 1px #4e7dc1;8 u; U/ I! K: q3 D  [9 h
  border-left: solid 1px #aecaf9;4 T9 r! }3 P; N" r7 l6 S1 X
  border-right: solid 1px #5679bd;6 S; j8 n  v0 K/ w& l* i4 V
  padding:1px;9 j8 j, @: X2 W/ q+ ~4 ?# G8 n, F
  margin:0px;}
# i$ n1 e" a- V! \/ T! G/ [* v</style>
5 @2 e8 D' R5 M- C0 }/ p" g<script language="javascript">$ B4 K: s6 Q6 p; {
<!--# {$ r/ n0 Q) L! T
function rv()
6 z$ F6 F5 S2 B{7 d; ]! q$ n9 J* @7 S
  var val="";' z) |. \7 f$ ]! e1 \
  for(i=0;i<combo_box.list2.length;i++){+ a: O6 ^6 I6 {
   val+=","+combo_box.list2.value;
& Z! B# _; A+ U, i9 ~  }
6 V: F- U0 h2 o  Y2 u  if(val.charat(0)==","){( u) H) e: z% @* k* `1 S1 R
   val=val.substr(1,val.length);
$ g) z* ^- H, J: B2 G& t  }
$ z$ Q1 e! I- Y! v  opener.form1.frecname.value=val;
3 K0 _! a' x$ s" ^$ q  self.close();6 p* U. z, S% E" f& c+ y; E- g7 E3 M5 ]  N
}
* E( W$ A3 b/ J# [  e//-->
$ q4 t- R; [/ z' a; m</script>1 W# O% Y# h; Z! Q8 j4 `
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">, F" P, z! {3 G- Q" Y# }2 m% n( N2 e
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />6 z) }8 F  p4 }- Z. L8 U" P; k
<%5 _7 m' n" d: w% d9 l7 K( U
  cdatasource ds=new cdatasource();  //数据联结bean实例" i2 P+ K7 `% d, g
  java.sql.connection conn=ds.getconnection();9 S9 D- m3 [+ m/ B, `* |0 s
  java.sql.statement stmt=null;& z/ Q  [. X4 `2 }6 n# {* q
  java.sql.resultset rs=null;6 @+ ^/ J8 T* L8 t# U
  cdatacheck dc=new cdatacheck();, j1 e, t0 \' V  n
%>
& ]2 [' F' T$ p+ s* X9 e3 f<%( H2 @2 K* |3 G! j% u+ a  J
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";! q! G+ B& P& p7 d
stmt=conn.createstatement();' r( m9 t7 e! c, E: O0 T
rs=stmt.executequery(sqlu);$ }2 e+ V/ l& M7 y6 M+ l; ~4 p
%>* o# s& J  S$ U+ [+ _& C
<script language='javascript'>
4 C6 h, T2 |, K9 qarr = new array();
* z& ~- Z2 l- _; C0 A- K<%  int temp=0;
" W: S! Z. z6 p6 b2 kwhile(rs.next())% Z9 F) O( v1 p6 ]& {
{0 R7 S% q/ h- U
%>
/ @& e8 P! |+ u; sarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");% }( Y' Q7 a% @, m8 G' U
<%, N. z" I* q( d# }- C
temp = temp + 1;
! M) h8 I1 [& B( A  Z8 l}0 p5 |3 R4 Q) s8 J' @9 B
%>
3 ]8 r7 ?* s) |' ]7 ?temp=<%=temp%>;; ?& M" g% b' s6 T
function changelocation(id){
2 S/ g' g% u, i8 h3 M! ]3 wdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
0 Q5 J+ h9 G7 q; Z& ]% a0 X1 Bvar i = 0;
) E# P0 F- l* j' v" hdocument.combo_box.city.options[0]=new option('-------','');
1 ]7 H2 D3 q0 o/ S7 J  h. Zfor(i=0;i<temp;i++){
! [: o  g3 @3 r: q! Z: \if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
7 s8 `0 y% b; C8 z* o# }document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); ( |8 m9 m/ x5 N1 d1 |
}
% J; U# L9 o+ {( W0 J) k  h}
  y& h5 U" H7 j  l# }}
! {$ i- h$ D( i1 i1 C2 M</script>
8 h$ y7 P2 ?: `, A0 c+ c8 X
0 D1 O+ n4 e) u1 f& Z+ T4 [  e<form name="combo_box">: ]& D; c; E& h6 u2 b$ c
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
" E1 |, G: i7 K  <tr height="24">
5 I$ I7 ]# b' y8 x& O    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
- q+ m. h; b0 M, {    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>) O0 Z2 c% B% M+ d" g- O1 b3 \. N
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
' r0 [0 `6 }  E6 s* O    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>2 S+ N& d3 L4 u2 M  @# @' Y
  </tr>% P1 m$ M  G- p% x) x
  <tr> 4 A2 i$ M4 d9 ]
    <td>
4 s" h0 w8 o' D" U0 m$ q3 z2 ^  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">$ V, k- G1 G8 e
  <option value="0">请选择部门 ---></option>
/ F: G+ |- F# d. v<%
/ H$ z9 ?# i. Y    string sqld="select * from tdept";
3 H) K9 L9 S  M9 V% hstmt=conn.createstatement();
; e0 w( u* u; vrs=stmt.executequery(sqld);0 }" z- W6 e  A  e4 |! k
while(rs.next())
0 `5 z: }4 z7 R* |7 M3 O! v9 B{
& u% f$ ^' S, n1 N%>2 b! F$ ~5 z/ A: g
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>, P6 B0 q5 u, m. ]7 j6 _# }7 ~
<%
8 `, L6 w8 a) \}" M0 x) Y3 _* U; v4 s, F4 G
%>
7 R: Z' |* R) n/ {& d- u$ V8 m: A  </select>
6 f' E# h1 \7 ]! U; K</td># U) M7 M1 R2 ?% y. N
    <td>
7 l' y0 F  `" V, p  <select multiple id=city style="width:150;height:200" class="bgc">
! u2 b- b) \/ }  Q  f# ]0 D# V+ ~* a& Q  </select>- h2 {  d: D4 A) q3 K
</td>
" F6 D( y3 b9 {    <td nowrap align="center" class="bgc">+ H$ G  J; `* P
  <input type="button"  value="<<" class="buttons">& n$ n- i6 }4 K2 k' N* C! t: W/ {
  <input type="button"  value=">>" class="buttons">3 {5 l8 ?: |4 r' K+ k
</td>- `. j' e9 G3 F  v# W- J* r; W1 p8 ?
    <td>5 A( M; d9 l% h6 ^& ]' e2 H  b' s
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">+ c& @. @% Q& K% l
  </select>
) o. c. b; x, u1 b" N</td># ~, E# o: v. A0 W  b1 s5 t$ y6 ]& @
  </tr>
  |6 ~! y9 p6 E7 C4 f    <tr class="bgc"> $ k# b! L7 B! w' x, F; m# q  M& |0 g
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>) B& k  f; r. R' t( o: @
  </tr>
4 c; Z- ]+ `7 ?; i) ?</table>6 \/ ]& d2 W+ l# O; }, R' E
</form>& E+ l2 J, n1 j4 C1 E
<script language="javascript">; I  o" A2 f# q. F  R+ x4 B
//人名移动
4 f5 }5 }% \' _! Afunction move(fbox, tbox) {+ D: B) \) Z; c
var arrfbox = new array();
( C& F- C) Z% n" Y$ i- ivar arrtbox = new array();( M1 F* G6 U3 z& `1 r
var arrlookup = new array();! R3 `9 z6 y* L% I0 B
var i;
5 u5 _: z. ]6 r( s( Q3 Mfor (i = 0; i < tbox.options.length; i++) {
) Y% Y9 \2 X& }0 b1 Y2 Harrlookup[tbox.options.text] = tbox.options.value;
3 \; D+ K& b) f& P, ]arrtbox = tbox.options.text;
! F% {, b2 H* L) E+ }: `}
# [# d% V* U, S5 `- g1 svar flength = 0;) m& E* M0 m6 [% B( y1 L  C
var tlength = arrtbox.length;2 w/ V3 ~" K0 S, ?
for(i = 0; i < fbox.options.length; i++) {0 n1 N2 e/ J! X3 g" u; ~, V/ F, {' C
arrlookup[fbox.options.text] = fbox.options.value;; W, j, K9 s, a
if (fbox.options.selected && fbox.options.value != "") {
" G5 ]$ h0 }) [) T4 Narrtbox[tlength] = fbox.options.text;9 [/ O4 @; Z2 v! z7 z5 m  x5 X
tlength++;
" o  ]5 }" `+ [* D% V! g}
& F' K* o& }) v7 }: O+ \2 oelse {
& p5 x% g9 l  D# ^2 o& D) Farrfbox[flength] = fbox.options.text;
; I/ k2 l$ s/ I* n2 ~( l7 Q( k) o  Gflength++;
6 H8 ]2 x2 P1 n' p   }/ g$ X$ r; [7 A$ T5 `
}
0 m6 ]1 h( I8 a# t2 T$ S. Aarrfbox.sort();
- t; d  I, u- |4 R9 Zarrtbox.sort();
8 _+ D5 [' ?3 z0 c; x1 G8 ?  B
5 R, d/ n9 m, x0 a. M& afbox.length = 0;' i0 C) X1 q2 z6 |! V
tbox.length = 0;
/ K. m* z5 ?+ X; `" P0 a- mvar c;
! u( x6 l# X/ V0 r( Pfor(c = 0; c < arrfbox.length; c++) {
  v% w$ f$ B* j9 I. dvar no = new option();
0 D5 M$ j$ U) t0 Hno.value = arrlookup[arrfbox[c]];8 [9 l5 \, ]" e5 Q6 L
no.text = arrfbox[c];) U% v: z; U. w/ Z
fbox[c] = no;
, F( d5 R5 S! @+ E( p, o4 n}
9 g4 e* D* h; i1 w" ~2 wfor(c = 0; c < arrtbox.length; c++) {
1 S" `' p# t. g1 K* s2 N3 [5 B3 gvar no = new option();
+ b' M* n, W& v: r% sno.value = arrlookup[arrtbox[c]];% F4 [2 l9 g& g* @- R
no.text = arrtbox[c];0 E# O: r" {- x
tbox[c] = no;
4 V9 [, f3 P& l9 E3 Z7 z   }
' D- e8 ~7 A1 R1 `+ \# d& }}) A5 K% N; p5 N. ]% |
</script>
/ D1 p2 s5 W; c) R6 u" D</body>" c; ~# M5 _. S. _" T; s9 p* ?* {

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