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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
7 I) _: }1 [" q$ P" o' H& D         c pageencoding="gb2312"2 ~) P+ y1 f; Y5 v; X: M
%>+ J: m. r9 Q& b
<style>5 ?$ Z( q$ k2 h2 T% h
.f9{ font-size:9pt; }
, B. ?6 |: b1 v0 N.bgc{ background-color:#aecaf9; color: #0033ff }
7 C/ U) L7 l2 n  H3 m  c/ o+ u, B.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;, f" u& o8 n9 _. L* y1 n
  border-bottom: solid 1px #4e7dc1;$ C8 K* z* g! S% ^4 ]( N* E8 S% b
  border-left: solid 1px #aecaf9;
: I& V6 H6 y  y+ [. _7 Y  border-right: solid 1px #5679bd;" i" h5 G! I0 F* _
  padding:1px;3 \' b) E, H. d1 d, e3 Z
  margin:0px;}- L1 U: t( o$ R. ^- E- _% n
</style>
7 K/ P+ V0 g5 }4 b, l. T<script language="javascript">% {( T8 P6 T( \: F0 @6 m
<!--
, d' G1 H' @# C  P& F9 Vfunction rv()
. ], W8 Q' g; X- F5 |{
- j2 s; b6 l% P  var val="";9 L9 g( V) v+ f3 t% r
  for(i=0;i<combo_box.list2.length;i++){
2 j: H3 g+ P5 k( \# R   val+=","+combo_box.list2.value;9 b- f* |! ]# _$ T" N$ Z! S
  }
# e+ F: K! ^2 E; e2 G8 F4 @  if(val.charat(0)==","){' Y8 k3 m7 Z' ^
   val=val.substr(1,val.length);0 W- u& }; B3 e# W
  }
; ^: o9 L: }/ m: ~$ i& V  opener.form1.frecname.value=val;0 \/ Y4 S( i8 r9 f: _
  self.close();
1 L$ c; @% ?4 I2 e' m# T}
+ H1 l. B/ O7 j1 u3 C- J//-->
: g4 _9 R2 ]7 \, @* K- e5 s8 D, w0 O</script>
9 Z4 K. R5 `0 K/ o1 J7 |# }<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
( I5 a4 E( }2 v<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />0 R+ f8 Q1 K! I2 ^6 n, x
<%5 F9 E% _, j1 k* E
  cdatasource ds=new cdatasource();  //数据联结bean实例, b8 m+ W( r4 Y5 \$ f0 @
  java.sql.connection conn=ds.getconnection();  l  g, r3 K1 A
  java.sql.statement stmt=null;
3 j- d4 e# ~3 |- m! F- k2 Z  java.sql.resultset rs=null;. p9 `0 w% w; R4 |$ x
  cdatacheck dc=new cdatacheck();
5 N, ~7 x( Q( A  E1 O/ A, D%>) j4 I* O. M/ A4 `; R. i5 t
<%
1 u  o6 Y, U, s/ a( Jstring 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";
1 X9 X9 N, g2 Y+ e6 ?6 P8 dstmt=conn.createstatement();
. @; H0 H7 i! V. ]2 b6 `4 ~rs=stmt.executequery(sqlu);( r" `0 i/ [! I" ~
%>
) W2 \6 J3 r& M! r' F, q6 H$ Z<script language='javascript'>/ t, M2 v# ^( e( ^: r
arr = new array();+ z: q' B2 Z! e
<%  int temp=0;
3 c  U0 Z7 E# f, b6 ], w/ I1 bwhile(rs.next())
, s! N' z* \. f; c{
! L. Q% V: N9 W' M9 Z%>
# t) H9 A5 H! s) f  \arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
0 T  h  M$ a: n$ m0 ^9 O9 g6 L/ F, Q<%: d, }( J" e0 \- j( V0 e( n+ o
temp = temp + 1;8 a4 F* y, V- g
}
' u; b# w0 V8 I2 \. f: N%>
+ ~$ z5 u' S7 H/ x' ]: W0 otemp=<%=temp%>;
6 j( O4 P9 U: W/ v5 R* Jfunction changelocation(id){
, u( `. Z/ H. \9 edocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
- g7 J, p$ Q+ Y8 }var i = 0;
1 Z5 W5 k$ t9 F/ Wdocument.combo_box.city.options[0]=new option('-------',''); ) l$ g- J( m6 `
for(i=0;i<temp;i++){ + a, }$ g. _1 x! b* |
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
$ N4 P: P& a- N# J" zdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 8 P9 @: }- M3 D2 j+ l
} 7 w3 ]# G4 v, w1 t8 Y6 @7 l: D
}
- c" }, P* t" l1 C} 6 ~2 @4 G& `, Z) z
</script>; @4 }: \6 d- v  V- C2 s
1 q* \, E, a* N5 h. C! l4 p- U7 k
<form name="combo_box">
; w: w: v- k6 r; \<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
* i- _, M5 H" J+ l" k, Q  <tr height="24">6 ]! [% l0 U, p8 G
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>2 k4 w, ~! h  S( s" T
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>3 H8 J2 l9 e, E- |0 B  H! Y+ U
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>/ W6 U& ^9 h; M' y" f& U
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>! u2 ?, e" v1 _$ J' y- w5 j5 k4 h
  </tr># o" i: G3 ^' d$ n$ m+ l
  <tr> $ C; W2 [! }" e. Z
    <td>
/ b6 _/ D3 O$ k  h1 D3 z# n3 X. m) x  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">9 m* |  A) X9 Z* l1 b% c  ?" d: r( o
  <option value="0">请选择部门 ---></option>4 U! w+ R1 j/ _% Q
<%5 x9 |' @; r- v9 F5 i8 |# ?
    string sqld="select * from tdept";
0 q2 y$ ?! y) w* Y7 hstmt=conn.createstatement();& ^9 d  d6 D' p' J  {# z. ?
rs=stmt.executequery(sqld);7 N* J1 D2 ^+ F
while(rs.next())$ P& [* L- k' H( `- L/ \+ ~4 n
{" m, v( P3 _% p  ~8 a4 ?
%>' }# k6 f% j! Q9 p
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
1 w" m; @$ R4 A( N( F<%
6 L" d* W: q" I( [& c}
: ~7 [$ K6 ]- t0 C; W3 i4 [$ l%> 4 @. g0 K% ^" {# U0 W* Y- l
  </select>  u: {% F% K3 e9 I3 C
</td>/ J  q! K& C: Q
    <td>& c+ F, I6 {( |( \: U# ?
  <select multiple id=city style="width:150;height:200" class="bgc">
8 h/ a: _0 ]+ u  </select>6 T5 A  Z4 v9 |) E' C
</td>
( W6 \& s2 v2 A# B    <td nowrap align="center" class="bgc">; E3 x  s1 Q% T$ H4 V) ]+ y
  <input type="button"  value="<<" class="buttons">( Z( c# i& z! @" K# ^& z
  <input type="button"  value=">>" class="buttons">
% w" A- n6 k" J) I* p  P: E</td>
" u  T* z" z) v5 g  k6 ?, X    <td>; b( W, @. w+ ~" ~
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">8 H, G/ e& a( V$ b) |
  </select>7 `; {/ N; `5 D  G
</td>& y+ R& n. c9 C  `# i  g' i' b* w
  </tr>
3 A& }, j4 Y; `9 a- I$ f/ T    <tr class="bgc">
, M9 ?  S; l$ g  A- l( c* R$ k    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>7 P% b' i7 b, O$ p  d& B
  </tr>; X( D8 l$ N) j2 d: D' j1 ?
</table>
# e' L4 f  r! D1 c! z3 v</form>
4 T! n, _6 h3 C<script language="javascript">. }. n0 d7 \8 q( Z, \/ U
//人名移动' _" y3 e9 Z1 ^% w$ P
function move(fbox, tbox) {, l/ |5 M1 ]. C6 `& C
var arrfbox = new array();- o, Y9 O, v7 S4 j1 T3 a: G
var arrtbox = new array();$ ~) T8 r/ @1 d! a2 E! i
var arrlookup = new array();5 @2 K9 O# f& E" N
var i;) H) f/ _$ Z( z/ \% w
for (i = 0; i < tbox.options.length; i++) {/ [# ?% g3 ?% m7 T- C
arrlookup[tbox.options.text] = tbox.options.value;
# Y0 L3 {% ~. A. ?6 W# h* m  sarrtbox = tbox.options.text;0 i) s" T" x% a( ^0 S
}
" s( m) k) R/ A( dvar flength = 0;
. Z& d  v2 P7 V2 L+ bvar tlength = arrtbox.length;7 x: u, n& O% o, r9 Q
for(i = 0; i < fbox.options.length; i++) {
6 O2 l; K( m4 b9 T( i5 Jarrlookup[fbox.options.text] = fbox.options.value;2 ~0 f( k' @0 i! N: R4 d
if (fbox.options.selected && fbox.options.value != "") {
$ ?6 d4 C7 P$ a! }6 D6 ^arrtbox[tlength] = fbox.options.text;
0 O+ N5 q' f3 }* S5 X/ Etlength++;
7 g8 K; u( A9 m/ ^}9 h4 h& l$ S' D" {) q4 _% Z( d) K
else {
% a: F7 p; ?8 F3 F' l3 garrfbox[flength] = fbox.options.text;0 p7 i5 G% N8 E' [; s! C' ^
flength++;
3 l5 X# e- e9 l% c( h8 Q   }5 x% ]6 j1 y2 a4 H9 Y
}
0 P5 G& q) g% Q4 E7 b3 Z5 z8 b4 Varrfbox.sort();
* T4 L0 m3 f0 o+ M3 ]1 harrtbox.sort();
5 j- r- S8 a" \( p1 s
$ o! F' F& u$ C: o* ?' efbox.length = 0;/ b2 {* a. M' y; V0 t- b/ t
tbox.length = 0;0 L) l) H7 ~) S; Y' ]& o
var c;& T+ `# o1 ]. `; s8 m* N
for(c = 0; c < arrfbox.length; c++) {4 i$ Y2 q: X) F3 ~% p$ u+ d2 ]6 W
var no = new option();, b: ]5 j2 B* F3 B8 i
no.value = arrlookup[arrfbox[c]];2 D5 c- [# P! {  t0 V" ~; A. f
no.text = arrfbox[c];
, B3 g1 H- L, h' p1 `fbox[c] = no;
* [1 P$ x% M& p/ x( p9 ^9 G}5 O4 X$ n0 d; g8 \
for(c = 0; c < arrtbox.length; c++) {; F: n. B- x: R6 z( A
var no = new option();
7 I+ G9 x2 n, f6 }no.value = arrlookup[arrtbox[c]];
# A$ n; G: f  o# W% u. F  cno.text = arrtbox[c];
) ^4 C0 |/ t" s/ a5 C. ]tbox[c] = no;
6 D2 b. s7 E9 j# ]0 Q9 O   }/ ~7 h1 d% h3 H4 T
}
" B6 G& w  @  t2 A</script>; l+ X: K8 g1 s$ o
</body>' O8 F9 n" C2 F: E; {% ^$ O

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