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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"& x& z, P: j: i- @" m/ N0 d9 h
         c pageencoding="gb2312"; ?" Z  X. J' {- B/ Y& ]! [9 |9 h6 g
%>
9 I6 E- g  s; g0 L<style>
! N7 `1 r2 Q: P4 u% N8 p. N.f9{ font-size:9pt; }, E6 S( a+ p3 |8 k$ P- ~6 d$ R
.bgc{ background-color:#aecaf9; color: #0033ff }8 a$ Z6 @# a0 q$ X" v, N. \
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;7 k( @4 a3 ]5 K
  border-bottom: solid 1px #4e7dc1;* x( d- E8 c1 N& a
  border-left: solid 1px #aecaf9;
* r  v# c. B+ N; A! O  W  border-right: solid 1px #5679bd;
. G1 t2 L! U  \/ l4 W$ s7 Y  padding:1px;  h$ S4 }/ D* J/ F
  margin:0px;}6 Z& i2 H; G  O4 v/ W" i) v- s& V& }
</style>; h& l8 u! m& e- L
<script language="javascript"># B+ ~5 e9 O3 k) c! F
<!--* D; j9 F# Y9 o6 J4 Z- z9 X& y
function rv()* H1 b  L; [7 [7 P/ g+ g0 |2 W- r3 E
{2 \& q/ C" Z/ H7 B
  var val="";9 N6 q( H0 }; q! L- @% _% `. l/ h) I
  for(i=0;i<combo_box.list2.length;i++){
. g& C  [- W7 m& \* e: z   val+=","+combo_box.list2.value;- X" S  E. t, T
  }
# y% A* {4 X& j6 T  |  if(val.charat(0)==","){" G* _# X' P2 N: G% `9 z$ w3 H. n1 X
   val=val.substr(1,val.length);
+ F- L' V8 x2 @5 N' _, A; w  }5 _# f6 l* y" O) r: j7 z4 C
  opener.form1.frecname.value=val;
$ ^3 g& r$ y5 F# I' ?  self.close();
! a' z% S# L  K; w}
! K9 C4 M* F9 a- {# o& Q9 N: D3 O//-->
) ?! A8 g% U+ K- A& S: Z; ?  e</script>4 q' ~% Q" s" u& q
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
' ^8 [/ }  |/ D' u<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
( x% e1 \- v: f  w1 q! s2 C<%. r+ G6 `$ `5 y3 W7 K9 }
  cdatasource ds=new cdatasource();  //数据联结bean实例; ]/ \& W9 e6 }: G  F% J# Z2 S1 @$ e
  java.sql.connection conn=ds.getconnection();
& z3 k# @# k7 R9 W% Q  java.sql.statement stmt=null;$ a; o1 F) z3 H( m
  java.sql.resultset rs=null;
( A% @  T7 D6 F1 O. e  cdatacheck dc=new cdatacheck();% ]: I  t* L8 r  `* C# Y) Y
%>, D, ^7 h2 \& G0 W0 i( D9 v1 [
<%* K& k1 V! E  x  u' B5 [/ T
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";. a8 [& c$ w- g6 |$ c" W# n
stmt=conn.createstatement();7 u9 {# r& V1 ?' ]
rs=stmt.executequery(sqlu);/ Z  j$ \) O7 N* O
%>2 Y/ ~) Z- c5 D# v
<script language='javascript'>
" t$ P3 ]4 |- h0 T+ d9 \arr = new array();/ z4 v, x" F: o8 Z$ f- K5 B
<%  int temp=0;
& H! e" X+ d, pwhile(rs.next())2 \1 A$ @% b( O" m% f% |2 U
{
1 g, D, p+ s. m  i4 c  P%>) ~  J' _8 r/ U: g4 O
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
) l" }  m0 m! T/ N<%) ^1 @$ r% W6 Z+ M* B+ M
temp = temp + 1;6 K* U- N) P+ N( j# e
}, t1 {  Q3 w" B* [
%>
8 J- N/ a) q5 u/ C, \temp=<%=temp%>;
6 I1 T1 L1 n5 q: a2 Ffunction changelocation(id){
2 J' d$ k' c& ?" Rdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
: K9 E+ z6 O; n2 V9 K& k+ Wvar i = 0;
9 V  Z, d1 y2 B3 f! {document.combo_box.city.options[0]=new option('-------',''); 0 o$ J) w6 p8 S# \- T. ?4 m/ b* B
for(i=0;i<temp;i++){ 1 B2 Q6 _9 N; v4 T! F/ D; ~
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
) {9 m! j# ^! k, s* _. {0 wdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
2 |$ o& |1 N5 m( ]! W* ~} 7 A+ [; y, A7 Q, y% t/ {8 ?
}   \+ X0 c4 Q  b1 c3 g1 ]# O9 D4 |/ _
} - `( \( R$ x' d' ~# b
</script>+ B3 z  q2 h* j& ]. P/ O
3 _- o; b" e; }& S* }; E) A) _( E
<form name="combo_box">
4 N6 i2 M  R5 R4 ~- T$ ]) o<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
# X' k8 k. ^# g: n6 R  <tr height="24">$ k; o9 t  {/ i
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
3 D3 y& O7 k; K- ^1 d2 o, Q" E    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
2 Y  G: ?) Q0 [" y' ]    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>' J7 o1 K. V7 X  H
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
! C$ x/ T8 c. Y, C5 o  </tr>
( o0 u1 B+ k9 B6 b  q+ H5 e/ s  <tr> 2 ?. U* F3 e+ \/ a6 x, c6 W% b1 G
    <td>$ m4 O$ B9 W; \5 V. H' K
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
: @; c/ w: `, n" P: M8 J  <option value="0">请选择部门 ---></option>
1 W9 B/ E# k; r<%
4 q3 L; @& c; U% f    string sqld="select * from tdept";
! O. K& N/ X3 q, c, Rstmt=conn.createstatement();
8 J- r* _% t0 H- D6 Srs=stmt.executequery(sqld);
4 A5 H+ ^1 Z3 B; Y  _# V( q! j9 Rwhile(rs.next())
! o% B3 \) x3 v) h8 T& v$ C% `: {* O{
# I$ Y: B! ^$ d& m. \8 d' l%>2 f# Q: ~' m/ C  k0 V- C
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
5 j+ ^* ^9 y) c/ {. v<%: _. R. X5 l* [0 D. ~
}
5 E; }# `! `/ @%> + e; H/ g7 A3 j7 a8 Y) T  |1 U6 ?
  </select>
  w& Y) g" N- e, N6 F  r3 m! Z</td>: W4 F* U  b$ f( m
    <td>
- E9 F: ?  f! v' x  <select multiple id=city style="width:150;height:200" class="bgc">) {4 O2 n1 r$ T
  </select>
2 L- h/ g! m: q- O4 R' f) t</td>1 R8 f- A+ S9 [5 E+ J) H1 K8 t' f
    <td nowrap align="center" class="bgc">
3 Z! s1 f$ g4 B/ G$ P8 w4 [6 O  <input type="button"  value="<<" class="buttons">
! L( Y) M# r  B* Y( ]  <input type="button"  value=">>" class="buttons">0 G! T5 K) O( q& P& Y6 }( `# ~
</td>( @8 m: ^' m. N, Z. J
    <td>
/ d. w: `8 ?5 P* j% J  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
) ^3 }$ l3 h8 b0 x( ]! x  </select>5 d# e/ H: C- |3 p
</td>
) `. O5 c& p3 X4 f, G. g  </tr>
' h1 u- F& ?( m& @0 E( _    <tr class="bgc"> * k) _# u! b4 i. O
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>4 R5 y# H# g5 j! `6 ^  U, \
  </tr>7 n1 r' ~6 M; A! D; y8 W
</table>
! g3 i$ f% o& n% m& x% g</form>& h2 v; C# H, E: c) R
<script language="javascript">5 d0 D0 s2 y% q+ e8 _$ [% ]; y
//人名移动# D6 @+ Q' a5 J" [7 {% [4 n! P
function move(fbox, tbox) {- n3 r" _& m$ J5 t  \) @
var arrfbox = new array();- b/ _7 ~6 _( a; c
var arrtbox = new array();3 P& e6 ~2 v6 w
var arrlookup = new array();3 L/ G3 q8 A( f& E3 C4 _2 W
var i;
0 |% I; u4 P& t) a( B; Sfor (i = 0; i < tbox.options.length; i++) {0 C+ n3 \; `4 F
arrlookup[tbox.options.text] = tbox.options.value;: a6 \) s8 q1 p% ]( G
arrtbox = tbox.options.text;4 \  p( I+ C) Q. q5 b' V4 d1 z
}  a' h' Q* ^/ I, n% L0 E8 G1 Y
var flength = 0;
* u: @9 l1 H( p% P) [6 Y3 |+ R& Svar tlength = arrtbox.length;, d' [# G6 m3 `! v9 m" ~8 K
for(i = 0; i < fbox.options.length; i++) {5 b/ X# _$ F* U, s
arrlookup[fbox.options.text] = fbox.options.value;
; ?, |. i8 q* U; L. rif (fbox.options.selected && fbox.options.value != "") {2 }- |# p3 X2 m. |& g/ x( j
arrtbox[tlength] = fbox.options.text;' a9 ~- t+ Q) h- v# R
tlength++;
$ C6 }4 v0 j5 x7 h! k+ c}! m3 i( m" t: ~1 ~$ j8 W+ M
else {; r: @! ]1 ~9 ^' O8 }
arrfbox[flength] = fbox.options.text;. i5 [/ @7 |3 ?8 {# C+ O& E# z
flength++;
4 K, t3 |* u+ {5 t- j   }
7 d5 ~4 i( S4 M+ y# V5 U( j}
/ h: S7 u( [& d4 T# R9 Y1 T( Earrfbox.sort();5 r" @2 A$ n8 r
arrtbox.sort();
8 w; |$ J, I8 r3 ^  M4 E3 f7 D0 ?, X1 m
fbox.length = 0;8 ]5 Y+ v+ s: ~$ T' n/ ^
tbox.length = 0;
# _* Y. U1 B* E: m0 X) H" d6 F0 ?9 gvar c;
- ~+ H' d* T# Ifor(c = 0; c < arrfbox.length; c++) {
  h0 @* m6 v4 o& d3 B: y- Rvar no = new option();
: M) h0 [, @, jno.value = arrlookup[arrfbox[c]];( `9 y( P  [+ z0 o* ~& O
no.text = arrfbox[c];
" P! @" l& ?8 o0 t  t: K  r- Jfbox[c] = no;
. I, ?2 c# W9 t1 C1 K% ~, m- B}
$ z* L9 n$ @! A4 B' f0 hfor(c = 0; c < arrtbox.length; c++) {
( D2 `! n& G6 P! b' I- l% `0 jvar no = new option();
# C5 |5 P; m* I. Y$ C) ]# W3 n% eno.value = arrlookup[arrtbox[c]];4 R. m% ^* ^; N
no.text = arrtbox[c];; k6 J( o% q0 c. T3 u. ]8 c9 Q/ ~
tbox[c] = no;
0 B" P4 t& O* i8 U; V: }   }# W+ i3 G- Q" D+ o: \1 O$ |, q- L0 t. I
}. g" ?& `: Y' \1 b( l) Y
</script>+ S! t' F% x: g
</body>
( d- p  ~, A8 m. C

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