返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
# o( P* `( I/ t         c pageencoding="gb2312". f0 Q/ h5 S% f
%>+ P) a4 ~% L3 ~  F2 v% C1 K# M5 l
<style>
) E' k0 Z/ p) n4 Y.f9{ font-size:9pt; }
+ x! n! c4 l/ t" Z/ G6 e.bgc{ background-color:#aecaf9; color: #0033ff }' ]/ S3 w1 l$ t
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
, U. V; ?# l7 ]+ I# x$ q  border-bottom: solid 1px #4e7dc1;, m* T& I# U, y6 J) M
  border-left: solid 1px #aecaf9;4 f  y  K2 |: A  @8 {
  border-right: solid 1px #5679bd;
) g. [; R  Y( _( E, [  padding:1px;
9 p# ], ]1 x" G! n6 O  margin:0px;}  t" Y$ N: `. Q( S
</style>$ Z  W7 U  @' n. V6 z. x3 l
<script language="javascript">
0 n. P" E' H; {: J' O4 s<!--% s7 p3 k: e' M/ E! _: g
function rv()! @$ I+ C4 @8 ~& h/ s
{
% @7 `  `* A$ s7 [" }7 g  var val="";
( X+ i, A8 m- {" W  T& c  for(i=0;i<combo_box.list2.length;i++){
8 M; v& ^9 a1 M+ F4 [1 [- c1 ~   val+=","+combo_box.list2.value;
9 o  t$ f9 A7 s" E2 z  }
3 j5 ?4 O  }, Z' W4 Z4 ]  if(val.charat(0)==","){) `  I1 W$ H$ ^0 X/ ^
   val=val.substr(1,val.length);
/ C+ }+ V1 C, p) E% J% p8 \/ y- w6 U  }4 X8 R% |0 P. b5 ]# {. T
  opener.form1.frecname.value=val;3 T# Q1 g# t( ?
  self.close();: j+ C$ z2 r- z/ j) `1 L
}
( E$ P& e; v- p, \9 ]2 b//-->  A, }2 F7 ]* K1 ^% x
</script>5 C; Q! H2 G- D" k4 X# _
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
6 o4 e; f# P0 k1 f( @3 P9 \1 P& T<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
, V1 {- W- q6 M<%
: a' c# \3 N# C: r8 q  cdatasource ds=new cdatasource();  //数据联结bean实例
8 g$ d- ?$ o6 u9 O* u: G) m: V  java.sql.connection conn=ds.getconnection();
8 {/ X9 V  H. R$ R  java.sql.statement stmt=null;
: A: n) n, A! S5 V/ t6 T  java.sql.resultset rs=null;
+ F5 [0 j7 \3 V: Q  cdatacheck dc=new cdatacheck();
: c/ `8 D$ t3 {  H& F$ t5 x6 g%>, _* W7 W' w' ^; X# B8 j+ O
<%
  \% l# L2 r( [/ @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";
5 r$ V: @) A% {0 zstmt=conn.createstatement();3 b7 z6 ~8 j- a. B
rs=stmt.executequery(sqlu);" x  u7 S2 {# i2 p
%>9 e/ p% ^7 u% g5 V" q* C
<script language='javascript'>
2 P* K' ?! o+ D% marr = new array();6 j. S% P7 J+ v
<%  int temp=0;' ?2 c3 j6 ^7 Q: Q& K2 f
while(rs.next())8 ^3 G4 I! i8 h% H
{
$ v' N1 w$ P9 z' n0 D%>" [0 j/ E; \0 }9 W
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");6 `# _5 y2 E0 }( c/ d$ [; p+ k) }
<%- C' k9 V# \5 G3 X
temp = temp + 1;  e  R$ d+ D6 b8 {2 D8 C
}
' w" K3 \8 ]3 n& ~%>) L8 t6 q  F5 p
temp=<%=temp%>;6 ]2 w3 V6 J  I! Q4 O
function changelocation(id){ $ p; h1 X/ I: B
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 4 u, Y  b: q1 g/ K1 j4 r6 Y
var i = 0; # B0 ~- b4 x: s0 Y
document.combo_box.city.options[0]=new option('-------',''); 6 ~: `7 C9 Y0 }$ x) A* x
for(i=0;i<temp;i++){
8 ?! W4 [6 x0 Tif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
& o! S/ g/ E4 O  k$ U7 }document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); ) T# t) t/ A6 X# r
}
9 ?7 [! b  |; O8 m- {} 1 H- M7 c2 U# [9 J* D- B
} / K! Z5 ~* X2 ~6 b. a. o
</script>
  a( t1 C! a" d% g% o' Q/ l0 C" K/ f  Q
<form name="combo_box">
$ J0 C0 f' E! u8 n, x* _<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">8 f- w8 X, ^! I7 ?2 }& u
  <tr height="24">) d5 z3 |9 g! v) L0 o" f
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
( K( O5 v9 L5 [; b) C# R    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
9 {1 s$ W! S3 K" G- t3 ?    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
+ a8 L8 x3 z* @  h, i, P$ d3 n    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
% G) X7 }7 k! \, |2 v7 [$ B  </tr>
( @) _+ v; z/ K  <tr>   P! D& W+ N: a1 F) }
    <td>% g. f3 L; O# f1 {
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">, A3 O$ |2 X' o; S! @- F; G
  <option value="0">请选择部门 ---></option>
, l- g$ ?1 M! X3 b7 C$ L<%3 M: k. i! H% }- j: D% f1 y  A/ l
    string sqld="select * from tdept";
% I0 b0 c" i6 I8 `7 h$ b0 c8 qstmt=conn.createstatement();
: ^* ?. {% b' H& ^5 i2 S: _% }rs=stmt.executequery(sqld);0 [% ~$ A6 I/ i! ?/ C* d" W' h- Q
while(rs.next())/ O0 l$ d9 H5 q
{
+ [. }% }" g/ ]# j, C3 G%>
2 [. ~4 s; B  b7 F$ p8 A  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
( m! c, C9 w& t4 Y5 h9 X  y<%
) D3 M+ p( \* e2 J6 s}3 c4 i9 I' H; ^
%>
; M% C" s- f* o: y  c1 a  </select>* {7 W  y" o: s8 ~% }* ~# c
</td>
) p( c& g3 P( ^    <td>% E7 V4 b+ C0 j( p, P' H
  <select multiple id=city style="width:150;height:200" class="bgc">
# F# `/ M1 m9 }% P* U; \" ~  </select>
& W( @4 D: t: a  y0 T* G</td>
% f' T  X2 `, x: y6 |    <td nowrap align="center" class="bgc">2 b6 w% a: z  `
  <input type="button"  value="<<" class="buttons">
5 E# T2 W) X( I  <input type="button"  value=">>" class="buttons">
% x5 Z0 j. Y5 q/ Y: O</td>
6 I# i5 P* K6 N: l6 w  F6 m    <td>, x, v/ l9 Z4 P2 B" I
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">8 @* {' p7 R5 b6 t" h
  </select>1 a5 }! c; d, \4 H0 x6 m# u
</td>9 P) g# t: H0 k9 w+ T1 g4 h
  </tr>
5 e9 x, ?& l1 Y9 K    <tr class="bgc"> ! @2 m7 p, e6 |, ^& @0 i$ v# X( d
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>  D, S/ M$ ]% x4 R9 |2 k0 B8 n
  </tr>
5 b. W, V7 g5 o</table>1 {2 L; N$ f" J* H+ s, ?8 e
</form>
6 Y8 P7 J1 X7 {  p1 P3 f0 m<script language="javascript">* S- [& v. \: F- R5 A: s1 S' r
//人名移动
- z! a4 ~& d( C! @; bfunction move(fbox, tbox) {
, v$ ^1 o! q8 C) |2 M! ovar arrfbox = new array();$ I& q9 n$ s" ~' T! S
var arrtbox = new array();
: U  x$ E8 i7 S" N- i8 k2 Wvar arrlookup = new array();
4 U$ t& x) W; N% g0 g" {6 S' l; Mvar i;6 f. z5 `% |6 [. J, t
for (i = 0; i < tbox.options.length; i++) {  A* C! v9 O$ v) r) I
arrlookup[tbox.options.text] = tbox.options.value;
. `( E8 k# T3 N$ ~" r/ Marrtbox = tbox.options.text;
& z' n9 F% H# P}- _# y4 N! M% m' K. K5 c) L: K
var flength = 0;1 L/ r4 {3 ?) e. k2 u
var tlength = arrtbox.length;9 u9 l+ o! P2 x& x/ V, Z) x8 h
for(i = 0; i < fbox.options.length; i++) {! i1 @9 F' x& x, f/ g* A
arrlookup[fbox.options.text] = fbox.options.value;
+ F" X' d8 `. Z6 V, _if (fbox.options.selected && fbox.options.value != "") {
8 |4 ^5 W8 _/ |' z% qarrtbox[tlength] = fbox.options.text;# s; q4 ~9 F2 g* Z( v0 a* L! b
tlength++;7 J+ f9 r* x! E& @) @8 z6 C
}
3 O1 Q& S; c$ w/ [5 Q" I* relse {1 }! J# E# D* `* X5 F" h
arrfbox[flength] = fbox.options.text;
/ p1 q. E% y) _+ U6 Jflength++;: F8 v$ e  n& y& S# r+ I6 e$ e
   }
1 m9 @: e6 n( V7 P}3 V" x1 P* S  d( m
arrfbox.sort();
: U* k) @; {+ ?8 k' |, G3 garrtbox.sort();; {, o* U9 K) C- e8 i
. J+ N, Z2 O( A- Q8 I
fbox.length = 0;2 c7 h1 h& a$ x8 O; L
tbox.length = 0;
2 n6 _% h9 r' g2 n# Z( hvar c;% E6 a/ w$ z  y! S
for(c = 0; c < arrfbox.length; c++) {
4 T+ h6 h) w- P5 x" H# i' Y* Xvar no = new option();
9 n0 [6 V2 |% C2 O. gno.value = arrlookup[arrfbox[c]];
$ [% w3 N5 }! e" T: ~+ q) z. f+ U5 Qno.text = arrfbox[c];5 Z( P! P" o$ Z  G/ r. q% Q
fbox[c] = no;
1 `/ Q& W0 a9 k}
5 n% c5 J7 h9 z, h3 bfor(c = 0; c < arrtbox.length; c++) {- s' D# r8 V  I6 z" D- M
var no = new option();* L& `. n2 ~+ c
no.value = arrlookup[arrtbox[c]];3 N1 e" M1 s- P) @
no.text = arrtbox[c];4 l! ^% V, e- R" R  ?* J- V
tbox[c] = no;
) R; N) ~4 b7 R7 v& v, H   }% r( n; h1 Q% g& l& x' p, d
}
9 v# g9 T1 K4 u! _- I9 v</script>
. Q. v6 o. l0 a0 l4 N5 A( |, o  N</body>4 h/ W( K# t$ u0 H# J1 |' \3 T9 a

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