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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
( H6 q+ K. p) k* Q* [/ |3 j         c pageencoding="gb2312"
' g" n& i' L3 i* |# q+ Q%>
- j2 [# A0 y$ g& q+ U# l5 O3 P<style>
; W! b+ I7 w: Z' ~- _.f9{ font-size:9pt; }, n+ x4 f/ U9 s5 [
.bgc{ background-color:#aecaf9; color: #0033ff }
: [% ]( U* y  T. @, K& `.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
; V  ?6 p+ Y8 F/ ?1 P1 j4 ~  border-bottom: solid 1px #4e7dc1;
4 {/ d8 Z' z# V8 D- A( {  border-left: solid 1px #aecaf9;
2 \, n, y1 |  ^! |. m  border-right: solid 1px #5679bd;. ?9 j0 x& z. ]: Y/ ?# }
  padding:1px;0 a2 r  C$ m) u7 _6 `# D! w
  margin:0px;}1 J& J0 G# X8 S; S  `9 _3 l
</style>
4 _& @2 b  |9 r) _# T<script language="javascript">* r+ a  \; I- T
<!--2 T( @8 a; [. Q+ J" j
function rv()
8 ~; \- r4 ^9 J3 s{4 q' r5 K7 N+ k5 r3 [* V) p/ d% u
  var val="";0 f; y; Q5 Q9 D/ y* A/ H
  for(i=0;i<combo_box.list2.length;i++){
7 |1 S7 G3 K& @5 H) V   val+=","+combo_box.list2.value;
0 `7 z. x* a% ?% }" z8 T0 m9 `- O1 `  }
( h8 v8 U, F* s: ]  if(val.charat(0)==","){4 {% s' n5 O8 ]0 @% ~
   val=val.substr(1,val.length);
" E9 L- @: `  B' j7 k  }/ s. @9 b8 P$ K* J2 i
  opener.form1.frecname.value=val;. ]: P5 v' H, A, T6 w
  self.close();" v  D4 d5 L- s% ?
}
0 k. Z" E3 s- S5 O//-->  W) R1 X  t: x# Y+ D. \8 Q% R4 [
</script>/ F9 U8 T. r' z0 O
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">- E# z+ ]5 G8 X# `8 B1 [2 i$ m
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
1 v/ A  j  a$ ~$ z, j1 _<%1 Z; Z2 B* E; A; d
  cdatasource ds=new cdatasource();  //数据联结bean实例6 U+ h) i6 p+ E; z% p% w  A
  java.sql.connection conn=ds.getconnection();7 b5 S5 ?/ a) s+ B8 g! i$ t7 C- S) }
  java.sql.statement stmt=null;
4 y; ^& Q8 U1 t4 g- B8 U  java.sql.resultset rs=null;
3 q9 _0 y$ X$ ^4 G" `  cdatacheck dc=new cdatacheck();5 @+ V1 w' u8 x. H7 N, i& s" a* [$ V: n
%>6 o% ~/ Q3 v6 ?+ G
<%  O" ?9 ?. s/ T2 B
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";6 A/ c" Q, Q$ j- t+ X! d
stmt=conn.createstatement();
. Y; f. S- \, @4 K+ lrs=stmt.executequery(sqlu);
9 k# g: s# B' ^" {& A%>' K. U% x3 ~3 Z. x& _& @3 K
<script language='javascript'>% v$ @1 I. ~; `7 e. S. @
arr = new array();
- |2 G6 Q9 L2 k; i% s7 f<%  int temp=0;
1 h, f. ?8 t1 X* s4 t8 swhile(rs.next())2 b, A) j' V$ o$ ]/ ]
{
5 d1 _% E3 r  J%>5 M* \1 f* }; @3 e
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
  W* w7 m8 g! V<%' \! s  E  z) ~: ]& P& w% i& ^
temp = temp + 1;0 ]' ^, N+ t8 }) O- U" R& C, h
}: K& T0 ^8 A+ }$ O- T' `, Q
%>
/ S0 M0 I' v8 g6 W' [temp=<%=temp%>;
+ x5 _/ O$ ]2 v. Vfunction changelocation(id){
, }' A: u; `/ N( }% ydocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 : F, Y! \7 T6 a5 g
var i = 0;
" q6 ?: m; _0 s6 i' C; @. ]% ^document.combo_box.city.options[0]=new option('-------','');
# a' u/ R- `2 _for(i=0;i<temp;i++){ . C$ Z  U& c; k7 D' s( w, \+ ^! p7 R
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
4 }4 c( `, J2 A. m# |# V/ v+ R; `document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 4 D$ z3 ?' H: r6 k" \2 N! W
}
; o0 }+ j2 N& Q* k. v- d}
4 e8 j; V5 C/ X1 W5 |}
% T& ], @) a3 X& [* C' |</script>
1 e0 ~9 u8 W8 p& f" K* g. J; T7 b. D6 K
<form name="combo_box">7 ?; y- @0 d0 D# x/ y
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
$ @3 O1 l* t. Y  <tr height="24">
4 b7 g. O% @9 p, z    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
$ [! ~2 N  L: V; Y3 n    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>5 M* O3 w% X6 H- c1 N: A0 J" k. w! N
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
& B) V$ C$ P" @% f$ h    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
& n- s0 r, R! `: z6 k1 b$ O  </tr>
$ s, b% a0 j( U0 o  <tr>
' W' P/ M, ~1 r) ^9 h, F# q" e. c. _    <td>
2 g$ P1 k) ?1 r# w% I  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
8 @/ r5 Y, m4 A% m7 d9 J' r& [  <option value="0">请选择部门 ---></option>
9 L1 _: X+ d0 b; _9 g<%+ Q% f& p. L) _
    string sqld="select * from tdept";
1 P  `3 K& k2 [9 g* g5 O2 V+ wstmt=conn.createstatement();
0 W' d9 v- W; \8 o! i  @3 ~3 p5 N9 {rs=stmt.executequery(sqld);
! l* D. I; g  r( B& k( Awhile(rs.next())
% n$ {; x& ?2 X8 g, m. u2 g{5 Q) ?4 g3 r  Y/ j
%>
$ k8 s' B+ E7 d* {8 O: c  Y! u  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>$ F$ ^- ]) G$ @4 [2 U3 O4 A1 z: i
<%' i4 S6 _" `$ Z1 Y
}, p. S6 @% D7 v( J2 z; G8 J7 R3 P
%> 9 _( J9 I: i" u4 m
  </select>
7 Z, B6 K5 G& z, F4 T</td>. f9 }' ^' |# ]+ J# o+ O1 O" C( k
    <td>
4 h5 _. P) @  `# _6 z. Z, I  <select multiple id=city style="width:150;height:200" class="bgc">
1 b( d; `( r% k6 T( {  </select>
# o- M5 f2 C: g( j# s6 F</td>
; D. a' J( n4 l" r2 D+ Q    <td nowrap align="center" class="bgc">
$ F* q$ B8 A% b' {6 E# v  <input type="button"  value="<<" class="buttons">, w3 T1 n  z9 U) R- _$ g
  <input type="button"  value=">>" class="buttons">8 \# i& P8 r" ~
</td>" ^  n8 M$ O* N& Y5 k6 R6 M
    <td># V5 T- v" F* `) e$ e
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">8 ?' l/ d/ k: x0 _$ X9 U. B4 }
  </select>
" k: A6 x: X1 r6 P+ C</td>4 g0 `! A$ H& k# P5 g
  </tr>0 n: W1 I. M8 A+ x  q1 G
    <tr class="bgc"> 5 C0 ?* h/ z) A  K
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
/ B+ h7 ?' w( c3 X6 \: ~  </tr>' U; E* Z, `" s3 K7 m" U* h9 t
</table>( C  v$ O7 H9 A. ~$ f' O3 N( Z
</form>% o1 c5 ^4 F6 R$ E: q
<script language="javascript">
. S- t8 T; e. \  p; O9 i8 U: D5 ?//人名移动& J' P2 N$ q/ b' S" z  L, T
function move(fbox, tbox) {
' ~: s# M* j6 [var arrfbox = new array();
, w+ F, c* n: Uvar arrtbox = new array();5 i- x9 M) R" e8 l, Q+ {; X
var arrlookup = new array();
. T7 r% y" q. a8 i, qvar i;
0 M  W) J* k4 j. O  }  Afor (i = 0; i < tbox.options.length; i++) {+ u9 o2 u$ X/ @8 |3 ?8 U7 N
arrlookup[tbox.options.text] = tbox.options.value;
& B9 {2 H2 F1 D  a5 w/ qarrtbox = tbox.options.text;4 n# c8 t. N9 t  m
}4 a8 Q. R& ?. C6 v/ g+ P! O
var flength = 0;# F1 s9 z: @) q
var tlength = arrtbox.length;2 d) U  p0 V4 U5 Y' n
for(i = 0; i < fbox.options.length; i++) {
" f% g7 Q+ x$ _, ^9 T' {2 S  }- uarrlookup[fbox.options.text] = fbox.options.value;1 |& D# m8 k/ X% c! b
if (fbox.options.selected && fbox.options.value != "") {
" V5 m& o: }" h2 F" }arrtbox[tlength] = fbox.options.text;7 T! ^1 y$ F- {9 T& j, }
tlength++;8 y7 u' |6 x& O' T- d0 O# Z% d# h
}/ d3 N7 Y  c8 S6 j% w
else {; |! c/ L) R0 q) [- O- ]
arrfbox[flength] = fbox.options.text;
2 l- r; N8 y- X; S+ {" jflength++;
' f5 p1 @, R) Q$ _8 C7 H   }) @' @* b  A) a2 }1 Y, W. F, u
}
  B/ n8 o' y/ b8 tarrfbox.sort();
+ X9 [' i+ h/ W2 tarrtbox.sort();! y+ G% z4 j) }4 A! s4 @+ ?+ H& e# t- w
) U6 ?7 t9 V1 v" B7 h0 H
fbox.length = 0;: Q) S* I" e9 B
tbox.length = 0;
5 J( \! O3 N/ U; O: \var c;
9 E: b+ @% G" c9 k2 E, c7 sfor(c = 0; c < arrfbox.length; c++) {9 x) Q6 ]7 t' I& |+ P- ~, u  [
var no = new option();
5 U, L& }% c: v3 ono.value = arrlookup[arrfbox[c]];+ _! q# K( x* e4 |! M& T% l
no.text = arrfbox[c];
. B+ `2 `, F! T# r4 b) Hfbox[c] = no;
" a6 S% H" C4 W9 D4 I* R# o}
8 H' B# v& S4 E4 r* t# F0 Vfor(c = 0; c < arrtbox.length; c++) {5 Y7 x" x: d- B& r& ]: C7 [% a
var no = new option();+ t. z2 U9 s' L' I  P* j
no.value = arrlookup[arrtbox[c]];: b* J# M/ d* [, t
no.text = arrtbox[c];# m6 g% @! Q" W4 j
tbox[c] = no;
, ^$ y0 [( j- N- U8 x3 G4 E4 C$ O0 G9 D   }
3 {; z+ S8 V* ^6 O* L}, x  r7 F! z+ y) Z! q
</script># b( m0 E0 a3 Z! c; E! L8 f
</body>7 ^- @( y' |6 ^; v- E

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