返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"0 c) l  v5 B; j  m0 ^
         c pageencoding="gb2312"
4 \* L" X( P: ?2 O+ f& l8 f%>
+ b, B, @% p8 l6 ]<style>
3 c( f0 ]7 e7 d.f9{ font-size:9pt; }7 M% ?* l, O4 y- A
.bgc{ background-color:#aecaf9; color: #0033ff }
4 `7 E( g3 W: c' e.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;8 U" }4 l  I  j* ]0 g2 ?: w
  border-bottom: solid 1px #4e7dc1;3 H0 F3 X8 l) ]! j6 g% L: W. u: K
  border-left: solid 1px #aecaf9;
; B7 t) B# M' h" W* u$ {- R- `+ }3 ~$ u  border-right: solid 1px #5679bd;6 ]! _) P: T7 z
  padding:1px;
* Z- A/ ~' r. p7 n# a- E' R- ]  margin:0px;}
" ]; V" b  K! f: ^5 v5 q6 m</style>& R! C  q! j9 s* v6 y
<script language="javascript">  g8 U( l  H1 [9 c) a  c" p1 _, O
<!--# l$ c/ k( i' l
function rv(). W0 D8 v+ i: f2 p* X/ {* m, b- o
{' R1 \$ G0 U" j+ p1 m/ @
  var val="";4 z* ~" O8 N' b! T, s+ D
  for(i=0;i<combo_box.list2.length;i++){' o0 f7 y7 D- z# @% ?8 q; z
   val+=","+combo_box.list2.value;2 S, E! w6 M$ p+ \3 l
  }2 g3 q* F' Q: q& i* R! D5 r
  if(val.charat(0)==","){* G! w1 g0 s2 S. l; L9 l
   val=val.substr(1,val.length);5 F' Y3 Q8 S0 k+ U3 Q8 Z- c( z, j
  }
3 `4 _6 V0 `7 H* g$ ?* w* v! Y  opener.form1.frecname.value=val;9 D3 ^* j  w" R- C. j% P
  self.close();: |6 Y' o* Q0 T: o: J
}+ H; P) k7 d# k, t, {
//-->
; P; {& d% {* L- \% S/ ]</script>' Y! x- g( T* D, s6 b2 \
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">4 ]# H' C6 W5 f* ]
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />/ j' W6 A9 |) a  W/ v( I' U
<%+ Y- z/ s9 E1 K
  cdatasource ds=new cdatasource();  //数据联结bean实例
# p+ b6 t- N, t  java.sql.connection conn=ds.getconnection();
, o8 _+ j0 Z7 E  java.sql.statement stmt=null;
0 _/ u9 w8 _/ _  java.sql.resultset rs=null;
. z/ Y+ N. Z) P% ^" G. t! [6 ?  cdatacheck dc=new cdatacheck();
/ S9 N- \# Y. B' Q/ }9 f  Z; r%>
/ p. V, F3 v& L' k<%6 ~8 @0 O7 l7 X
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";
( `$ e! D) N+ N4 lstmt=conn.createstatement();
6 w8 S; Q( Q+ J4 N7 ], }rs=stmt.executequery(sqlu);
5 J5 }7 n$ i& [# S+ A! b%>, R& j+ ]1 F+ ^8 n
<script language='javascript'>
& b, K8 }2 C6 W+ Y8 \& u6 rarr = new array();' H/ u# r  e+ D; M, P& \# y; A
<%  int temp=0;' ?" Q( I& U9 X/ Q' K4 k$ H
while(rs.next())3 b/ E" \& m1 I- u1 Y
{& |8 t* u8 q  L4 T8 Y2 U4 d$ R
%>
5 `8 _# |% j* d1 N4 F& o; L  J( q, ]arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
" r# m% @# W! I" a+ e1 L( c) I6 b; e<%
/ a1 w4 B: T, d& n& ytemp = temp + 1;
" D( O  M1 b) T! q2 j0 V$ S}* q  k0 p% v% D
%>* L$ `# X  {/ O+ I% C
temp=<%=temp%>;7 K2 b2 x* @% M0 L& ^; `, b9 _
function changelocation(id){ ) Q/ B* L' n: V6 t
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 5 u2 u# M8 x- ^* {! \5 O4 @4 M
var i = 0; * q8 a' ~0 h7 i. |( L
document.combo_box.city.options[0]=new option('-------','');
% v* y' K% K9 B4 O' bfor(i=0;i<temp;i++){
8 J, a) m' K3 e; \5 }if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
7 X) L) _/ ~) p% P* c( w4 Wdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
9 O' f. v" o; r7 `& `3 C6 z/ w}
! D" v1 Q, f9 Y$ @. n}
# y  i1 T/ G8 \) V! Y} 4 Q9 n4 e# Y7 ?  \# l" A* H0 U
</script>) H) E. u% L$ M7 b; I( G) ?( _

# }: m3 m. ]- R- d! a<form name="combo_box">
6 I2 Q% W! |) g<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
9 S  L; y. J- q6 e- |3 s3 B  <tr height="24"># F1 g* n" K: d+ i; u* y* ^
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>$ g8 V% D% G% _2 I5 |$ n% m8 A
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>" Z! s5 w1 z2 g: M3 x0 \" P! s) c
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
2 z# x2 V* P  _    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
7 b* q( Q. M4 L  q3 K  </tr>% l$ S1 [( e2 G" C$ U; x" d! @
  <tr>
! d: [6 t) H/ f8 Q. i    <td>* V# I% R; B. C& |8 r
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">8 f8 Q. a; e9 N4 @" C6 \
  <option value="0">请选择部门 ---></option>1 W$ Z2 r; L9 ]4 S1 W7 s7 m! D
<%
! J9 y  X$ Q2 e0 R8 Y, o+ T* g    string sqld="select * from tdept";
4 @1 f' B0 w9 Y. Rstmt=conn.createstatement();) @9 r7 a! K8 E7 z
rs=stmt.executequery(sqld);
' ~* S9 `1 s- I( t4 Kwhile(rs.next())% H% H: L' L. n
{
3 v0 _: H* O* J- }%>
. n* B$ N! m+ S8 G: M' O5 r3 t  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>; T% H: t/ C/ m8 z8 R$ ~5 H
<%
* q2 M" x( \! S3 R}
. X/ B; e1 D3 n2 v) R# v2 M%>
& Y  j. }$ v9 x" D+ U" n  </select>! h8 \4 G$ c) z8 z
</td>
; w6 t8 M" p$ ^+ v2 S1 s    <td>
3 f7 y' n: _1 T/ l  <select multiple id=city style="width:150;height:200" class="bgc">
  _- ~* r4 G- d: m9 ?1 w# s  </select>" T7 B" w; h# V7 ?' s, O9 Z7 m) {
</td>/ [3 ^; b) {/ I3 h* N1 @
    <td nowrap align="center" class="bgc">3 x9 v/ Y5 {8 F8 I+ m% c0 S
  <input type="button"  value="<<" class="buttons">
8 ]8 }! |( X9 u1 b9 g  O* Z5 T  <input type="button"  value=">>" class="buttons">
0 {; O4 R. Y5 I. N$ B$ o$ I</td>
, @) t  `  m. y- i! z+ J. ^    <td>
; r+ ?1 [0 I3 R4 H" h  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
5 k4 u8 _: c- o, I  </select>
% O, o( ^+ Q$ _8 R% e" o+ p/ T+ ~! |. N</td>
/ H% r% |+ I/ O  w+ C7 G0 Q; e) V) ]  </tr>5 E9 d4 n9 B4 I; [8 [
    <tr class="bgc">
" p  Q! _1 L7 s/ N1 u    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
: O. t- |6 G3 t1 a5 V6 ~  </tr>
6 Y; `  P* [+ ?( h8 _</table>4 ?5 t% g& V4 _. J* ], {
</form>$ ^* w# q' s4 }7 P8 q# |0 I
<script language="javascript">7 J  L; V  x) l: Y8 i
//人名移动3 R  c; m& b7 E7 E! O; K
function move(fbox, tbox) {5 a* w; b$ t6 M" T/ [: I
var arrfbox = new array();
% N5 j$ z" F" a7 a1 ]var arrtbox = new array();
- Q' C  K$ M, o4 H# Rvar arrlookup = new array();2 L* u, L, R+ A5 f0 D5 Y; h( G* G) ~
var i;
0 p; ]) r. c; h' @for (i = 0; i < tbox.options.length; i++) {
+ h# K% X' k! u; U) Uarrlookup[tbox.options.text] = tbox.options.value;0 ]: X! V) _9 X8 m
arrtbox = tbox.options.text;
' H. P# `) y: K  m$ D! I, d8 E}* q: C2 J! Q6 U+ c" l3 ?! M& z
var flength = 0;' T( w; c; ?4 v) u0 ^
var tlength = arrtbox.length;
; K* S4 f4 c( ufor(i = 0; i < fbox.options.length; i++) {
2 ~6 \5 W0 D: }5 h: ]- marrlookup[fbox.options.text] = fbox.options.value;3 D7 ?+ `+ w; f/ A0 |6 s' m1 l( s
if (fbox.options.selected && fbox.options.value != "") {
& k' _; z1 v3 K# X1 tarrtbox[tlength] = fbox.options.text;1 s$ A9 L2 B4 l- P$ k6 L
tlength++;3 k' h: h( U4 g' D% [! ]  A% t8 E/ }
}
# }) N% a) e& g2 ^else {0 C' [$ n  }1 I$ p) Q& r) Z
arrfbox[flength] = fbox.options.text;0 |/ P: b% Y% R" f0 X. ~5 b
flength++;" k( e7 D5 A- s; l+ {) k' B7 ~$ o
   }7 S* V) Z7 O" i
}# x( k/ t& G8 }5 J
arrfbox.sort();
" L" ^) g" @) p* tarrtbox.sort();0 p  \' ?6 [! r. U

$ Z- I5 p1 ^( s" f/ kfbox.length = 0;
* ~. L! @* m1 y% @% }tbox.length = 0;1 X2 y( _) n- z/ n
var c;! Y$ Y3 V+ v- r: Y4 H) \; n
for(c = 0; c < arrfbox.length; c++) {1 G( c2 C9 t( S/ e$ X6 h
var no = new option();6 v: g. a% I( S: Y
no.value = arrlookup[arrfbox[c]];
  H# }6 Z$ T9 D3 [0 Ono.text = arrfbox[c];% e) q$ u- D0 i$ ~1 P  T& f
fbox[c] = no;
& Q9 r+ M3 h% _/ Z; T; R+ H( v}
0 x+ b# Q" T' P3 i  f$ g0 Nfor(c = 0; c < arrtbox.length; c++) {
3 H3 T" g4 U* v: Kvar no = new option();3 |+ C, r( o3 Z: i0 M' k8 j5 q
no.value = arrlookup[arrtbox[c]];
" @* l: X4 p3 V( `3 Tno.text = arrtbox[c];
, Q3 |* v* u% [$ xtbox[c] = no;& _0 n( v/ k' ?- J$ H9 S  l
   }
2 X  x; |' _7 @4 ?# N! S}6 e, ?# X; `% Q& L6 Y
</script>
; V/ p- N8 z, x2 T9 K</body>
% [1 g- x; R' t8 I

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