返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
2 r/ v1 S* `  O- ~+ ?# h  x# s$ J6 |         c pageencoding="gb2312"* \# u# p: w* Z8 C$ G7 k
%>8 n0 v  r( e1 Q+ h) ~' _' u
<style>) o& u! Z& @) h5 v& n
.f9{ font-size:9pt; }1 n, f3 R) M* i5 D  h1 n7 ^
.bgc{ background-color:#aecaf9; color: #0033ff }
; Z+ S6 P! g+ D' L: `; r* A.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;0 q  ~- H; D/ y: m# ^$ j' u+ ?
  border-bottom: solid 1px #4e7dc1;
* b+ y4 p4 p$ D9 q8 k7 Q' O) e3 R  border-left: solid 1px #aecaf9;- l0 V: P- C( p7 K- S
  border-right: solid 1px #5679bd;
9 l: [; W" l: F. Y! u! d+ Z! B  padding:1px;
+ l# U) o: ~1 m& M! [  margin:0px;}9 i( j. F, J/ Q2 ~
</style>
' C/ r; r+ u* m" F2 b1 O<script language="javascript">
! N# V3 `% U& D( l8 D<!--
$ f6 M- U0 z* h/ k6 t9 J4 o2 A# W6 O) Vfunction rv()( {7 [) \) z5 }" Z; [+ q  a( U; w. \
{
2 ~. G4 Q4 p9 ~  w- j* w0 ^( @  var val="";6 J* c' t3 u0 N- |! a1 P3 l' \5 Q* E
  for(i=0;i<combo_box.list2.length;i++){" e5 _- t; w7 W! M, ]
   val+=","+combo_box.list2.value;
$ H* r8 m2 P4 a  }
# r8 t$ \: f2 C3 H  if(val.charat(0)==","){
  l; m% N8 R  A' R. j   val=val.substr(1,val.length);
% P; H, l  ]/ h$ ]8 h  }1 D6 h6 H# ^: ?+ ^5 s) @
  opener.form1.frecname.value=val;
. r9 h" l1 d  W7 F3 D: O  self.close();3 Z7 u4 s4 x; U/ m5 R
}
* `4 T9 V1 }5 o3 k% i2 ]//-->
, |1 K$ O: s; }2 R" o</script>
8 O, g2 L$ C5 m( x<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
" {+ G6 A; u5 c7 M7 N0 J<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
# c& \* }$ R$ W4 E- w* |- a<%
, y, J& b- d6 m5 ~1 _  cdatasource ds=new cdatasource();  //数据联结bean实例
& _2 d% a$ j7 J$ M- U% K3 f8 S  java.sql.connection conn=ds.getconnection();4 r7 O6 }' k5 X2 l+ M" L9 ~
  java.sql.statement stmt=null;
7 M! H6 u+ U3 h% c, @, ^) U* R( _* F  java.sql.resultset rs=null;
. a& O/ n% l3 i  I9 [1 T! |, g  J  cdatacheck dc=new cdatacheck();
* V' m" m$ i6 _2 K5 H+ V2 h8 g%>$ F; q* y; o" X/ ?9 h
<%
$ ?6 @  y2 h6 U* Rstring 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";
+ l7 Z- |% @" j6 Istmt=conn.createstatement();3 R# d3 S# g& Z/ i4 X8 t# w# Q6 i1 p
rs=stmt.executequery(sqlu);
4 o1 k) \" }" x( X- x& T3 E%>1 z7 n8 n- h0 z+ B
<script language='javascript'>, {1 `2 h; Z4 U+ _% w% m
arr = new array();
. m: g# m% [- i' e6 K<%  int temp=0;/ Z2 \7 T4 r: G7 d' A- l0 P' O
while(rs.next())+ g) A* [3 }) V
{- q; x$ d* m$ J7 m  G% G5 k( y% `, v
%>, V& H4 t6 [% O9 t( R" l- d
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");4 v* c3 w  m3 e; M
<%
: b- ^7 r' l2 g" [7 Q( @( mtemp = temp + 1;3 H2 z# j& B: G
}/ b9 v7 G7 l0 M+ ~5 k6 S
%>) V& O3 c8 z/ Q3 U9 o9 i
temp=<%=temp%>;  V# v5 Q, [# {6 H9 f
function changelocation(id){
6 _) {7 X2 |, |$ ~8 k) O7 c+ x8 rdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
% [7 k- G  C5 }% g* A$ l' Xvar i = 0;
! S( U$ a. W6 W' X7 Q8 ~document.combo_box.city.options[0]=new option('-------',''); ; h$ W5 ?: Z/ N' Y
for(i=0;i<temp;i++){ ! @$ k' [1 z, E/ E! g$ \# h2 L
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 4 Q( O, R7 D4 {. U0 d
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); ; U$ Z/ ]- q7 L. |* M
} + C% y& |6 k& S2 b
}
  R% c. s/ k  l$ f6 ^1 m/ |}
% J! x$ O$ {9 l; u+ _2 w</script>
9 A- l: w2 L; }. _
+ j5 p3 o- c8 Y<form name="combo_box">( D" ?6 d) j: M# v5 W
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
  u, Y& Y- y4 H  <tr height="24">' f& u/ k# }7 T" Y2 o6 P* B
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>0 d( n0 m7 ]! n4 r  v/ P7 s
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>2 W- B/ M. Y. l6 l
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>% z+ \: F% X+ M! Z
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>) Z9 h% @$ r, e" s& k+ m# k9 y) ]
  </tr>% P  y. c1 s$ T7 C
  <tr>
# F- g4 W) q  \; r8 `& D    <td>
; ~6 r5 j5 E) L9 V; L+ ]( p: f7 v4 F  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
/ t, F  S' [) s2 }/ X7 G# V+ j* X9 j; N  <option value="0">请选择部门 ---></option>; \0 B5 B, d  ?0 w2 W' T$ ?
<%
0 O, W0 X% v4 @& o4 b    string sqld="select * from tdept";5 g8 I* ~; h% W8 X
stmt=conn.createstatement();  h8 y# v2 \  h9 r. A( @
rs=stmt.executequery(sqld);. q1 c# I0 s% D) r" M% B# l
while(rs.next())% `( l% o  e) _7 x
{- _! V% |! h2 M4 {% P0 ?5 o1 g% \6 n
%>3 j! f% }5 G' w
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>% E! }" T/ T5 i8 m) q
<%
! X6 b: N, I  y- r, |9 M$ h}
+ M' X+ a% Y$ a5 e%>
0 }: v6 ?3 L5 x4 M2 G+ v, T; n7 E  </select>
; p# J& C3 g/ Q$ x* x</td>
  x$ A+ w% J+ u4 @8 e- T7 M    <td>3 a6 B! q. {% {3 T( P; p0 a
  <select multiple id=city style="width:150;height:200" class="bgc">
7 N: {) V2 b" G" [, M  </select>
& x# i' S( m" x4 D3 q! \$ ~% B* f</td>; Y1 ~5 c4 r3 A( S
    <td nowrap align="center" class="bgc">" w# ], x9 k+ j9 n& M  t
  <input type="button"  value="<<" class="buttons">
% G8 ]( H; U2 @+ \# e4 @- {  <input type="button"  value=">>" class="buttons">
; N$ ^2 x0 `5 Y9 ^, Z</td>/ a/ P+ T% s! A  P1 [7 V
    <td>6 ^  _) v" ^$ h8 v$ e
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">' U) z. L" i& m# A3 Z6 K
  </select>
5 {( E( ~' M/ ]0 o/ d; d1 ^( i</td>
0 B% j3 `7 p0 H7 B  </tr>
; V: o* z- B5 i5 ]8 T    <tr class="bgc"> 4 m5 k& z0 e( L7 ?
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td># E# K/ `( c9 j+ ^5 e+ [$ {
  </tr>
' m6 T' t& h- K8 a3 Q$ S* t</table>: s! N* A. w- r, b) E/ ~
</form>/ [8 D3 K; m# U6 ~3 B6 ^2 u+ J
<script language="javascript">; H1 G1 w& q3 N- D
//人名移动0 ~5 C0 X7 s* U. q/ h1 u9 D
function move(fbox, tbox) {
* S0 g  R* A* r7 _. Uvar arrfbox = new array();
! B' l( `  j. q5 c) \; Q9 |var arrtbox = new array();
: y1 T% |5 C7 Z) R. @var arrlookup = new array();
, H2 m1 v9 }, [/ V* Jvar i;
: Y7 ]% r7 A( Tfor (i = 0; i < tbox.options.length; i++) {
7 x" Y; V1 l# r3 K6 s, yarrlookup[tbox.options.text] = tbox.options.value;
$ v8 N9 Q( G. ]5 H+ a/ narrtbox = tbox.options.text;
; ^! O1 M; w# F}
* |: Z. O+ ~, P" G! Cvar flength = 0;& n9 Z: L1 O4 B- E  J- C& A
var tlength = arrtbox.length;2 A. h5 U# g" o( y" K) Z. X
for(i = 0; i < fbox.options.length; i++) {' f# P2 J& }# M, x4 d
arrlookup[fbox.options.text] = fbox.options.value;
) {3 O3 I+ b0 J1 {4 p" i$ bif (fbox.options.selected && fbox.options.value != "") {
2 W5 Y2 F/ [5 d; T% N4 M9 q' [arrtbox[tlength] = fbox.options.text;/ @; t% s) V. e. H- {# s* j" ^
tlength++;0 D' s& Y) W. U7 e, _8 \( }& x- k
}
2 I! k' S- Y5 Y  @! [7 f( @3 b$ oelse {
9 x$ i, O8 p; a& g! I3 Uarrfbox[flength] = fbox.options.text;
/ ~, ]" x$ e" Gflength++;
# `: q: r4 R4 V   }
- K6 D4 R# i& K% `8 r! x}
8 q& v& y, n) l/ T$ k/ Zarrfbox.sort();
$ W7 m8 a- R0 c# }; @  G; u7 m6 p$ p9 karrtbox.sort();7 T7 S' h; m- R- }( M( s* s& K
% t* j2 L; J" E) {2 |9 k
fbox.length = 0;
( z: Q$ ?# a9 B$ v/ @- f2 htbox.length = 0;7 [7 I+ \' E  V7 O; E
var c;* v8 ]1 i+ D$ g$ E6 b
for(c = 0; c < arrfbox.length; c++) {' l7 f5 F7 }) Q" b% o6 ^
var no = new option();4 h. Z( Z1 |& n5 g# I0 S8 Q
no.value = arrlookup[arrfbox[c]];
9 \) j1 H8 R* m+ Q7 h& Rno.text = arrfbox[c];
' c' I6 G* s. M. x/ Zfbox[c] = no;+ }1 P2 v5 V& t/ y9 s$ t( j  d+ p
}9 E, J$ S% h3 ]; u
for(c = 0; c < arrtbox.length; c++) {
% k0 r3 w2 _- m1 d* f, @var no = new option();0 J  O- @3 M& E; T1 I. O
no.value = arrlookup[arrtbox[c]];
/ W8 C7 V" {# u1 ~. Pno.text = arrtbox[c];6 J) X+ l7 G  @* I! R. v  A
tbox[c] = no;- ]1 E& E0 O! n$ g+ s9 Q
   }; h3 d8 t- ?% s
}  w4 E  p1 d/ m# X
</script>
9 u. E% k0 m( w- a6 g</body>
; J9 [, ~; ~) n$ q) |) K) X

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