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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;", f. Y- V, j% [" b4 E9 y& A$ d
         c pageencoding="gb2312"  e( H) @0 Z: ~. M0 }2 S
%>
9 x* \( T) Q1 p<style>" w3 ~7 Q8 y0 q$ P8 p
.f9{ font-size:9pt; }
* T* A) s. F% I) y" J7 m3 j- p/ ~+ r.bgc{ background-color:#aecaf9; color: #0033ff }/ T2 G' a3 s1 c  e
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;' @8 _' u2 ^  V( F
  border-bottom: solid 1px #4e7dc1;% U. j% w* q5 a. ~- ?# Z5 t
  border-left: solid 1px #aecaf9;- q2 F2 A: c. S
  border-right: solid 1px #5679bd;$ N/ A* m! c9 g( L( j' |9 P
  padding:1px;
) ?3 I) M7 E( W4 N4 q/ D; g& u9 |. u  margin:0px;}# o' s. q' p1 p; `8 ?2 M! m
</style>% z7 \3 m2 K0 l$ ]6 c/ K+ x" {
<script language="javascript">
0 l9 j& E8 g' C8 v8 M& v$ j8 w<!--
6 Q+ k& N) L1 O2 G; f3 I9 ?function rv()% U' a% Z' u, Q, Z
{
  N0 a' K5 l8 O' j# C8 W  var val="";
$ ^$ Q0 p7 D3 [+ f0 ?% r  for(i=0;i<combo_box.list2.length;i++){" S( i, A! E* w! H9 f2 R: R' f
   val+=","+combo_box.list2.value;
* J* J5 ]$ Z! n$ E  }
$ s) q# q: i. A3 X& ?5 X# k  if(val.charat(0)==","){
- ?) ?: n8 x! k+ S   val=val.substr(1,val.length);- [5 g0 {; `1 I" s& y
  }7 ]/ S4 s! ^. X9 f
  opener.form1.frecname.value=val;
9 T& |& i; A0 p  self.close();' m/ V, d4 o) e7 k, ]' p
}
9 p( Q, e1 _- I3 m! Z. S7 k//-->/ S  p; S+ g+ |- W
</script>" q+ G* q- O8 ?* D3 @" K
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
5 f4 h8 m. G3 A. t* h7 v<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
: m" ?: j# m- y+ [<%& ~& N3 c7 G. t, a4 N7 ?& g7 _$ t
  cdatasource ds=new cdatasource();  //数据联结bean实例
9 s  g, N2 h& H: _  java.sql.connection conn=ds.getconnection();
# G% ], V" [$ m1 `  java.sql.statement stmt=null;/ f# N  P# X3 d5 @) B$ h+ i
  java.sql.resultset rs=null;
& Q4 [# P+ s; A0 }1 C  cdatacheck dc=new cdatacheck();8 ]: i' _: t! b% d2 Q
%>
- ~. ^! ]( X( |) S  o<%
% ~9 c# S* J2 B5 K8 Hstring 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";
, Z1 K& h0 c1 i# F) ustmt=conn.createstatement();( o5 u3 T3 L; K) q, y6 \+ o
rs=stmt.executequery(sqlu);
$ K. \% K. F$ _8 q3 S8 m$ N%>
: S) q$ Z5 v. b+ @: l  U<script language='javascript'>
" G& e$ w$ @1 @/ n0 carr = new array();
" l2 x& A* M8 q1 Z3 ^<%  int temp=0;8 B  f! f. S# Q2 }1 e5 s5 B
while(rs.next())6 i0 [# g* G1 r, g  ?9 s/ a3 E
{6 Q+ t- |7 S7 [6 C7 k
%>- g* i. t$ b, z
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");( J! I+ C5 M" |+ m2 [% `5 e( ?
<%% E, [: u- L" S
temp = temp + 1;) t5 N6 C1 s* N6 ~
}
  d4 `; B. \% |& ]1 j, G%>% B+ F  B3 G# n8 v
temp=<%=temp%>;+ {( x/ ^' ]% N. M8 M
function changelocation(id){ , E! j: Q$ P2 T- a. k' }4 G& F
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 : j& s9 B0 c; L8 \$ E6 u
var i = 0;
$ ]. u/ J6 Z' v( Q  {document.combo_box.city.options[0]=new option('-------',''); 5 O, @+ G$ w  o1 E
for(i=0;i<temp;i++){ , r8 R, T1 X& o9 ?% a1 X' [$ a
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
2 i, S1 e( t0 G. i  m/ P7 w+ idocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); : [. \7 J7 H2 Q, [: H' P  s6 D+ r
}
4 l. h. ]8 D- R1 L}
' j* J* a+ U5 f} 5 ]3 O- h7 M' R. n8 k8 N5 A5 D
</script>4 f, [4 U, N0 n1 p/ J

  O5 d! C9 i! B. R  N* y<form name="combo_box">
* {7 A4 w+ q( S& @! N# r) z<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">* Z0 G8 F- y4 V3 q
  <tr height="24">0 h$ t9 p2 f( S4 C7 K
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>/ I, {4 X: M" R$ Z2 T6 @7 V. l1 V
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
0 y! c  D! S  x" w" S3 L9 M    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
9 C5 a* N* x7 _6 s, G( F  C0 O+ |    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>3 {* V+ X* R+ Q: h$ [2 D. q
  </tr>6 d3 u2 y7 q8 m
  <tr> . r4 m. e9 d+ g
    <td>
6 R% a6 Y) i% D7 l  O  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">% A! N8 @' i' `. k9 f1 F, W
  <option value="0">请选择部门 ---></option>$ `4 {- d9 q* N; B
<%
8 L1 [: i) p& q0 V7 T2 r, {, t) M0 W    string sqld="select * from tdept";9 d6 N4 g4 T% J* i+ ~0 ?! L, e
stmt=conn.createstatement();' N* C" C# D4 z. a* ?% i  Q, p
rs=stmt.executequery(sqld);9 x# p( ?2 x# Z4 d
while(rs.next())
5 t- Y& X- ]: d: P{5 R7 j( {& m: A3 K
%>
+ x) V' e6 T* B5 p& Q  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
, K, ?' P0 Y. b5 y5 ~8 \) c/ b) y<%  _5 F2 |' Q2 H, u; B' ~- z
}5 _# c& O8 j" ]( U& O7 e* w& e
%> ; |* u" Z9 K3 l# ~
  </select>
1 y( k- a0 f6 m3 k6 G</td>
, I/ ]2 ?% ^$ I9 t    <td>0 ?% ?4 l" m5 U$ |. }6 ~$ O3 n4 B) v
  <select multiple id=city style="width:150;height:200" class="bgc">
: Z  R, V2 e2 }  </select>% R/ {4 q2 A+ ]1 b% @3 Y' N0 E, ^
</td>
7 E, J7 ~3 B8 ^, u; G) H2 m' E    <td nowrap align="center" class="bgc">( N, R; V8 W& J
  <input type="button"  value="<<" class="buttons">/ D9 o; ?4 h) W& d5 S2 S
  <input type="button"  value=">>" class="buttons">
7 j( Y! [2 m% h; w7 i$ |) m/ D3 p</td>
7 p! E6 z/ b+ t6 d+ Y    <td>1 E4 c  D. C8 u  y, L
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">! p+ s9 [, A% ]/ `; M
  </select>2 o. }7 d8 @' D' |; d( d+ b9 I
</td>
5 F7 }7 X+ X  `4 t5 W' \" `  </tr>+ x7 k1 w- w5 V( @! }8 R) T
    <tr class="bgc">
* N1 s& v0 \$ U    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>5 Q# _9 d6 W5 v9 N
  </tr>0 A3 `1 \- @* ^
</table>
1 K+ j6 s" E6 D1 D) \1 z</form>
4 Z1 B2 j8 v/ J! g<script language="javascript">
' Y) y* _. E% U( L//人名移动- |* ^* ]5 K' S+ `! G
function move(fbox, tbox) {' o+ m4 R' s+ q+ a0 e3 F- Y% b
var arrfbox = new array();, a& d" ?* R6 U& m; G
var arrtbox = new array();4 I) I# e- I! `% g: a* ~' [
var arrlookup = new array();# q) J) O$ S& i# `, [8 p
var i;0 g  b/ w0 w* M
for (i = 0; i < tbox.options.length; i++) {
- A. t- U1 p7 e0 barrlookup[tbox.options.text] = tbox.options.value;
' c( ?; ]. v: J& _arrtbox = tbox.options.text;
0 d" n6 a1 v8 K+ Y# a}* J% L8 j) C( s% F
var flength = 0;7 C5 f9 F. a8 \) p; N2 x$ x$ c1 L
var tlength = arrtbox.length;
( j: ^9 ^* C- ~2 \for(i = 0; i < fbox.options.length; i++) {
8 O9 o9 X1 b! P' W. Oarrlookup[fbox.options.text] = fbox.options.value;
) m, [6 o/ S$ Qif (fbox.options.selected && fbox.options.value != "") {1 j+ c8 f* K8 L1 b; k$ S( o4 V
arrtbox[tlength] = fbox.options.text;% l7 g* T- f0 a1 k9 n$ y; m5 q& }
tlength++;, b) g9 o0 h4 F, D6 k9 n: K9 r6 v
}
6 n# D  X9 c$ p/ ^else {2 a' y2 m9 L9 P5 J7 w
arrfbox[flength] = fbox.options.text;
0 ~7 Q0 m6 a# l8 B  U9 Rflength++;9 \5 F0 V0 k. G- |5 {* a9 L
   }# g' K, t' n' ?& s7 e- Y
}0 e6 i6 v2 w: X) X( C
arrfbox.sort();, {; q, h  \! y+ a3 F* c9 A
arrtbox.sort();
& B" ^. A  m9 R9 U! w4 v
, I; [) a( J/ Nfbox.length = 0;
% w+ b0 _& Z/ I! U% P. F3 ^" @tbox.length = 0;
- \8 R( Y8 F. B& g) j5 T2 pvar c;
+ L" W, M& a( ~, Ifor(c = 0; c < arrfbox.length; c++) {
0 y9 R, |3 K+ {0 d/ f0 Lvar no = new option();/ J+ O% U$ a' w2 ]% e5 y% }
no.value = arrlookup[arrfbox[c]];& T- q+ I* h: P7 j- p
no.text = arrfbox[c];; K  Q, y8 o7 }2 l0 W; ^4 t2 I5 `! s) y
fbox[c] = no;$ h: M. f" ?* }
}( ]( F! X4 S! @+ e6 F7 B
for(c = 0; c < arrtbox.length; c++) {2 u* k) N9 Y1 J% {! N
var no = new option();
. k- F& t) v4 R7 o* H: a- Bno.value = arrlookup[arrtbox[c]];/ a$ q# g6 [" x6 Z2 M7 m3 ^7 K
no.text = arrtbox[c];
6 H( N4 V' j" ~) P& Z9 S9 {tbox[c] = no;, O1 Q: q1 T1 Y! w+ C& Q1 u
   }3 R0 Q( a0 L+ T' W4 I* D
}  A  U# E  Y. I& K0 D* g
</script>
$ p3 L; Z/ m3 L- _# I' X- F</body>
  z1 ^! U1 k- w9 t' d

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