返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"  H+ K7 M* T5 ~2 [
         c pageencoding="gb2312"9 L$ `3 ^( G5 }
%>
7 P8 f. I( z0 e* T6 T<style>
, |, e) k+ N& m* y& J# t" z0 P.f9{ font-size:9pt; }3 r! A/ B. A: V6 X  W/ x  z
.bgc{ background-color:#aecaf9; color: #0033ff }4 _, c0 P+ \+ W- D( Z. ^7 Z
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;4 c% ^7 Q* ^' `" l6 P6 D" X  w3 |( v
  border-bottom: solid 1px #4e7dc1;
( \# _( @! g$ P, M/ _0 x" J- b  border-left: solid 1px #aecaf9;1 ]0 t) d' K3 h! w. L7 F+ z% R3 u
  border-right: solid 1px #5679bd;/ s1 ~( @+ L+ D$ F5 P, o9 B
  padding:1px;
" F3 d, i3 X& T0 Y  margin:0px;}/ z( D6 k/ V+ Q
</style>
; I+ n6 i: X9 w: [+ M* S& ~<script language="javascript">+ Q. `0 P* r# l# E  V6 i
<!--
3 i, O- @# `. G" c2 C7 t4 Mfunction rv()
( Y6 N8 @4 [3 V' G' p6 l, k{
1 H% O# M0 D+ C9 [: x  Z$ U$ _  var val="";- I/ B  c% a# h) @" y
  for(i=0;i<combo_box.list2.length;i++){+ o6 q' |* N2 H
   val+=","+combo_box.list2.value;
) |: |' D& v/ H  }" F1 o/ g- P: `. ^0 m
  if(val.charat(0)==","){" n5 P# T. F! [5 a, g3 A( D
   val=val.substr(1,val.length);
  t2 R0 m- `$ ^( {& \3 B# b  }" d9 `5 V1 w7 Z/ q" v  Q/ ~* b5 F
  opener.form1.frecname.value=val;1 A- r6 I* _. _$ Z  d( ^, ~
  self.close();
" x# n9 C% G! C$ k$ l}9 a0 r1 R5 ?( w+ {
//-->1 z& D' ^" _# ]8 O% j( J; L% r/ I; l+ r
</script>$ H! H; u- B0 n+ i- x* F' V2 i
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
7 Y% B$ M9 ?3 |( B: D<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />. p& Z  G" J6 j: g; X
<%1 M3 X% `. i4 K# A. [% ~& t6 ~" b2 p
  cdatasource ds=new cdatasource();  //数据联结bean实例  |, v7 m# T9 L4 Y% y. S
  java.sql.connection conn=ds.getconnection();0 h( ^8 n% U, C" }
  java.sql.statement stmt=null;% t6 [1 I, i6 y
  java.sql.resultset rs=null;! x; U! o9 H1 L! ?
  cdatacheck dc=new cdatacheck();
& |5 E& F' C& E. S, g%>
7 t" h1 }& s6 M4 C2 {+ B9 P% d+ t<%( V$ u+ p/ C9 E! 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";
, ^: ?2 w) i1 A+ Xstmt=conn.createstatement();
; T9 \! `! w0 Z7 d1 S8 Ors=stmt.executequery(sqlu);) J- x' B0 S: y& m$ A
%>! j# _$ H5 T) u7 K
<script language='javascript'>
4 E; m, y1 F3 s, h: uarr = new array();
( X1 F; h, Q5 r* x<%  int temp=0;
. \0 k* C5 ~2 ewhile(rs.next())2 D1 W( M2 Q9 ^3 I# R% U( o
{
& [2 r8 G$ ~& Y" _+ m%>( e+ A$ `* f$ {$ `! F, a% h
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");# N! ]- J! O5 s
<%4 d$ d% l& m. D& C
temp = temp + 1;0 u# J% n4 W. z
}
0 u$ N* ^1 U/ G8 J1 K! ^% h%>8 V- N, _  I, V, m& @
temp=<%=temp%>;, c; Z: i. C0 h: f
function changelocation(id){ & v, D( n% X0 t
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
5 w) V% O1 \: t6 Bvar i = 0; ) B3 i$ x6 ~3 \8 L8 |
document.combo_box.city.options[0]=new option('-------',''); + X& r* k9 C- M1 G3 o* g
for(i=0;i<temp;i++){
9 @1 d2 I/ G9 X6 H3 a1 Uif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
0 R) R' F5 h, U" Y. c! ~document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
8 |$ _5 z9 X: q, M8 ?8 `}
) h4 m  B% D2 P# M, W} / P! v# o3 B: G& k2 ~) L9 D
} - V3 G3 ?8 F! y/ y4 F# c, c' f
</script>/ R- \4 A4 J1 a, B8 r
& [+ L) \. {' G, b0 b
<form name="combo_box">
* |1 @2 ^' p2 |- ]<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">" f% W; x( X! U  t8 A/ _9 D. r( w1 R
  <tr height="24">
/ L; ^1 u# G6 ~& W    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
. N9 p7 n  z  n8 `" T! ^; p    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
1 p" i( n4 c5 p0 S( p/ W) s  W    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
; V2 w3 h! o0 I8 T) S    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>7 J+ X1 E8 I7 I& A
  </tr>
. M1 a1 l1 }6 K0 G: n  <tr> 8 ?; w/ K  M7 }7 v$ N
    <td>3 F7 g0 f) D/ {; w; j
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
1 o" \! z# `6 A& U4 ]  <option value="0">请选择部门 ---></option>% J) J: g! `& r4 h& ?. J
<%3 L) _7 `; S/ ?# s
    string sqld="select * from tdept";' n- k0 m7 e. F" u
stmt=conn.createstatement();9 \- Z$ b& l  \3 ~; l  [. Z
rs=stmt.executequery(sqld);; s  d. S+ v: h* b
while(rs.next())
0 p6 R9 R- _+ c* u3 a{3 _( D  [* y) P& z# O9 Q: Q/ A- w* V
%>
1 T6 Z; C, G! e4 X1 X  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
9 O. r% Z; M- X' t5 B- D0 @) X; ^<%+ |  g1 ]* s& |# x2 \" l
}& y  J  S+ a  U  h
%>
$ Q; _' @  V! b- m/ r/ v  </select>
3 Z/ d0 }$ X$ S. y</td>
1 m  J* d$ K% y& q: M    <td>
% N, q% T- L8 K4 F* i  <select multiple id=city style="width:150;height:200" class="bgc">! J. g4 Z  M/ @* G, c, }
  </select>
' w/ _; e& z1 `$ l. |( I7 Z3 }6 u</td>
; b% f6 s/ z# u7 N9 O# n/ P6 V    <td nowrap align="center" class="bgc">
. `: v) c4 m5 V% u1 M4 K  <input type="button"  value="<<" class="buttons">0 n! J, G4 j- l
  <input type="button"  value=">>" class="buttons">& w, O# j- C2 W5 I( g
</td>7 v  r7 D6 Z- C* N; g. L
    <td>% X8 `0 f" z$ l# u: e3 E4 d: L5 C9 o
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
- j8 V3 p" y& r/ |8 }7 Q) @  </select>8 y' C4 p7 [$ O, ]8 B5 s. n0 _* ^
</td>( V6 Y0 B. v8 R
  </tr>
" L5 q' |# R1 x. \0 `2 g' Q    <tr class="bgc"> 1 D) L8 j+ g. x) B$ \- i7 A9 k
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>9 X/ j1 L9 G% `% i( j
  </tr>! _6 U( _( e3 v8 f! ]1 E/ H: W1 u0 N. h
</table>
( s3 n3 k, n; u7 O</form>; S! O0 V, d8 ?$ ?2 W5 v, ]2 _
<script language="javascript">
' q% j4 {( N1 n) |9 z//人名移动
9 E  ]% [4 a) z" H- c  Q% v8 rfunction move(fbox, tbox) {
; h8 v4 z; |3 K4 r% t9 |$ Cvar arrfbox = new array();4 i. C( s8 H' y% K  p
var arrtbox = new array();
/ ]  I. L: J: n4 A* t) {var arrlookup = new array();
; f& x! L# i+ v! z5 _var i;: t' ?  g8 c  ^" [' w
for (i = 0; i < tbox.options.length; i++) {1 D6 P5 `4 `, A
arrlookup[tbox.options.text] = tbox.options.value;4 x5 p$ c4 T- L
arrtbox = tbox.options.text;
6 f% P$ M! w( t' E}
2 [) t$ u" Q: o2 e9 j, `0 Svar flength = 0;" F; g* N+ w" ?* J8 b& o4 {
var tlength = arrtbox.length;% m9 ~& |% D! A5 Z
for(i = 0; i < fbox.options.length; i++) {
: S  A# G" M/ e2 x' E' Uarrlookup[fbox.options.text] = fbox.options.value;
# {2 h7 B1 W2 G' yif (fbox.options.selected && fbox.options.value != "") {
: J/ x/ l! {/ j" J) Varrtbox[tlength] = fbox.options.text;
6 Y+ x( i0 E7 b2 [+ p0 T- etlength++;8 S% Q5 _% {9 T7 v7 T
}) o  U+ S5 u( I+ F8 W$ \
else {0 R2 e" ~; m- b$ T7 x
arrfbox[flength] = fbox.options.text;
$ m( G. k1 z0 E- p. M" ~flength++;
: ^/ E6 h) h- B9 V8 V   }
+ R+ B) r1 c# E. o1 n- m! h0 G1 f}( R3 w, R: Z. N: {% \
arrfbox.sort();
* A/ O4 f! Z8 X) |. E2 [arrtbox.sort();
: k3 l1 V* k$ u$ E4 R7 n9 U. r$ Y/ ^3 L; E( b# N4 c. {5 ^# h1 a: Z
fbox.length = 0;, i0 g! @$ H) M+ q& Z4 P2 M
tbox.length = 0;
6 j% H& O' A7 M) Qvar c;# K( e: f7 |! p4 o! W6 p
for(c = 0; c < arrfbox.length; c++) {
5 r' |) `9 n  [& G+ qvar no = new option();
; V2 b( Z  ?8 D( U6 F) i& P0 H+ bno.value = arrlookup[arrfbox[c]];$ I1 k6 ?+ H6 ~' F7 ~" y7 p
no.text = arrfbox[c];
* G. a1 f  p. C: Nfbox[c] = no;$ D& W# O1 V5 \5 [7 t
}% |1 R8 d7 H. _# {. t
for(c = 0; c < arrtbox.length; c++) {
# C/ G4 D6 M& n! c% A& _% J+ t# J4 wvar no = new option();
5 _; K4 u% s0 t2 K  bno.value = arrlookup[arrtbox[c]];6 K- h/ h: K( c9 p* e) i& p9 W7 c+ z
no.text = arrtbox[c];
# Q3 s; o* u* E- Utbox[c] = no;1 ?6 G7 M6 M& v% |, s2 W
   }" `8 Q! y  I& h, L; p
}5 K3 W. y$ C% K
</script>- ~3 G9 J0 e7 Z% A9 Q( a
</body>) j! B3 {* P! F

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