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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
' u; F% s2 u% [" B5 \* ~         c pageencoding="gb2312"
# W# G9 i0 ]# d" E" n1 z%>7 Z. Y8 m# ^/ }  w- p* x$ S
<style>0 c. _* ?9 f/ i6 g1 m
.f9{ font-size:9pt; }  p& j; D7 q9 N! C- z' x1 a
.bgc{ background-color:#aecaf9; color: #0033ff }, u% @7 J. W7 A
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;% I* B3 c  \: s0 q/ w
  border-bottom: solid 1px #4e7dc1;- L8 T) i! f/ Y( y; ]
  border-left: solid 1px #aecaf9;- t( [3 y, ]+ R
  border-right: solid 1px #5679bd;
% E! d* h. p! w- V  padding:1px;
  t5 t8 Z+ g' k) S  B$ l" R  margin:0px;}2 ^0 h; d) F9 q/ _
</style>% y& K. ?& b( Y  Q
<script language="javascript">! L8 H) w+ [# c, y1 [5 O
<!--. c# D( ~" y2 |& K5 c) [* w! t* w/ t
function rv()
1 @; k6 C" ^, v/ C. N0 ^  g{
/ O" Z) E6 J( O4 g  var val="";5 S3 M; ~1 p% c0 n) r. p# C6 N
  for(i=0;i<combo_box.list2.length;i++){
: q6 n7 r3 N$ o+ z   val+=","+combo_box.list2.value;
4 x& C; f/ d3 ^* r6 g# r# |  }' |+ |% ~4 N, s0 U: n4 F- g% o$ N
  if(val.charat(0)==","){1 `+ ]$ E& q$ I4 D
   val=val.substr(1,val.length);
. x3 l' V+ ?: W% ?( H* T  }6 z8 K, [) r& V. o& F% J
  opener.form1.frecname.value=val;& W( J9 c/ c. _% R3 R* a+ X" C
  self.close();# G, l$ u! `, ]! e
}
5 z6 h2 a  G3 [* Z. J1 I8 N//-->' {7 i) Q4 A4 Z" a  C* x
</script>
* Y2 K( I: C8 c<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
, T8 h+ K- L, @- c<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
) V) C9 V  ~: F<%
# w* P- @! U3 N" W8 t  cdatasource ds=new cdatasource();  //数据联结bean实例
3 b8 V6 E6 l4 x! a. R8 Z7 l% M3 m  java.sql.connection conn=ds.getconnection();
- G+ C, J3 ^) A; I5 `% s) _$ e  java.sql.statement stmt=null;) u6 W1 R$ I7 E1 s, f
  java.sql.resultset rs=null;# f7 v  Y2 [( M* h
  cdatacheck dc=new cdatacheck();" z* Z/ t; u' b' w" r# z" T( A$ d
%>
- O( T% z# O$ j$ {8 Q1 C8 A<%
( v( c/ P1 J( ^8 u4 ]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";) w: a: ~" a5 d+ s2 u1 e
stmt=conn.createstatement();" Z) Y/ S" M/ ^% c" R% `' \& o2 z5 t
rs=stmt.executequery(sqlu);9 {* {( Z4 e: z: b: J8 ~
%>) b7 v) g; e3 h; H  e8 `
<script language='javascript'>+ e; g  n# o5 n5 }: G
arr = new array();0 o! V( [% \1 I( u, w. p
<%  int temp=0;
+ P6 Z% o% K1 N, l) ]! @while(rs.next())
( P0 d; D, D2 n; z! Z% a{  G5 m2 l* }# K6 ~/ n) ?/ y4 Y, m
%># L( t. W: d8 ]( G
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");5 Y( ]3 {" v4 [' \, C. E
<%# Y6 U! f6 D0 J) X/ t+ I
temp = temp + 1;
; ^4 m0 Y* a- Y  e}; A: s; R  P) t5 O2 y) T" u; b3 l7 L; K5 y
%>
2 H0 q1 d% s$ S& m+ t0 |2 Ptemp=<%=temp%>;; i0 p6 F2 b3 Z& v$ C. V& N
function changelocation(id){ ) O$ c$ B1 @' B
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 9 k" Q4 F$ J' [6 w7 w% W
var i = 0;
% W9 B, N, T& P* `8 o( E/ zdocument.combo_box.city.options[0]=new option('-------',''); 2 U2 j$ ]' T) V0 E
for(i=0;i<temp;i++){ 2 n$ L/ Y% ]# A# n. |+ Y$ C" n
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
& i6 M  W: t+ ?! {' Q+ Z/ X# `3 Cdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
9 N8 N) ?6 d" t- {} ! K2 J& N: j, V9 q% O: L3 T& p
} 8 N7 Y; Z# ~9 P8 O/ q
} + F) u) ]; n. S# E$ b0 E8 v
</script>" O0 x# M% B- P( W0 x7 u+ H
) ]  z' _6 r- i9 d. f
<form name="combo_box">
: w2 ?" p+ D6 A: B2 S& v<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">5 n" k; {- L# }
  <tr height="24">
+ d- W( ~) X7 U5 ^5 P- r    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
+ D& T: p/ \  C7 ]" k! t6 B9 b    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
% W4 _1 G' X! s# D- e# ], ^+ C    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
; t$ u7 L; T, J0 H# ?    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>4 H) L; W+ o, A  K) u0 ]5 x1 h
  </tr>& W' Y; b6 Y" V0 [7 E
  <tr>
  K3 ^3 R7 E$ E; F    <td>
0 w( Q8 J8 W9 c' D  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc"># a/ X  u) G* |
  <option value="0">请选择部门 ---></option>) n" Y" x7 Q: ~0 [5 ]
<%% |: m3 \' b, |0 x1 ?9 n4 @
    string sqld="select * from tdept";1 a5 i5 X6 ~0 A; l* q
stmt=conn.createstatement();
# g" \7 z9 ]! N+ g% g* Krs=stmt.executequery(sqld);
1 ^: T4 _( i* A% q. |; E* u4 Uwhile(rs.next())
4 z! ?8 D, |4 U5 H! \{: x: q+ s7 f: E& \2 l7 \+ r- |
%>
/ i0 W8 b! g$ N& K  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
- ~/ N; b5 y0 w<%) d5 o2 R* C' A1 ?$ T4 V
}2 k7 u7 t" y& [+ H. r& r& P5 w
%>
( t2 K; G+ |2 ^  </select>: y& K2 X) R$ q
</td>9 o) ?3 M: k' U6 b
    <td>8 H* F5 ^( c6 z
  <select multiple id=city style="width:150;height:200" class="bgc">* [% u: u! u% l/ a* |# I
  </select>- ?$ ?( F1 h1 K3 ^3 F0 x8 h% L
</td>
# \( |, ?+ c; x    <td nowrap align="center" class="bgc">* p& @8 f, }7 d
  <input type="button"  value="<<" class="buttons">+ J& P% Y; N5 m
  <input type="button"  value=">>" class="buttons">5 C  a2 g7 k8 w/ _3 n3 r) w% a$ e
</td>3 n0 F+ t2 z9 u) e
    <td>5 F# r0 F0 d5 s* b7 g4 Y& f" D; X
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">3 I4 f! V! D* d2 V. f9 |- P& q
  </select>
2 x) Y+ U' W/ C4 T4 {% b/ a</td>! c% i9 a. z" \7 [( R3 J
  </tr>& K$ T/ ?8 N& E( }5 v5 T; b  Z
    <tr class="bgc"> * z1 G' Q6 T8 D/ J
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
% w! _! x6 I! b! p. k  </tr>
: _9 E& r9 `  ~) B0 O</table>
4 A0 z6 p- l8 d$ G' t' j6 y+ s</form>! {* C! L' T' ?. I- w
<script language="javascript">/ a# u/ K7 v; e
//人名移动
1 Y! r) K9 A7 r7 wfunction move(fbox, tbox) {
) R" {5 G) [' b9 @; G) X! E" S8 g* ovar arrfbox = new array();
& k9 x) F0 o' J9 Z* S3 Bvar arrtbox = new array();
  I" c& W1 n% O0 {$ V& _% cvar arrlookup = new array();
2 o$ j0 g  N% wvar i;* _) P" Y" n% y6 C9 m
for (i = 0; i < tbox.options.length; i++) {
# {5 k* x' I0 @" ]  Parrlookup[tbox.options.text] = tbox.options.value;
; h3 w' v# e% x) t- ~4 i5 warrtbox = tbox.options.text;. ?$ J1 Y6 ^9 B/ p) o( o- [
}! a4 m: J$ G( v/ h9 e. N
var flength = 0;+ b7 q4 o2 N- X5 A# d
var tlength = arrtbox.length;0 }# j# f" h* I0 d+ j6 X! H4 P2 i
for(i = 0; i < fbox.options.length; i++) {4 c+ z. q, v$ p2 E$ V
arrlookup[fbox.options.text] = fbox.options.value;4 N; F2 \: o+ t' q
if (fbox.options.selected && fbox.options.value != "") {/ U1 p" @" H$ R
arrtbox[tlength] = fbox.options.text;
2 p+ B* {7 h, c  E: Ktlength++;
( A* @5 G& J8 ^2 U5 K0 C$ E9 o}  j: G, {% i  C- B- Y
else {
6 h" E7 S0 ]7 s) n( I3 f2 ^3 Barrfbox[flength] = fbox.options.text;- k7 `5 y* r# z* ]+ b9 [6 ]
flength++;
  G8 Y' l! `2 @0 E   }
+ g. X/ G5 d7 v* y$ l; J}6 r' l; K7 n8 W) x; A" R7 D
arrfbox.sort();
8 K8 J! {7 i' [7 Parrtbox.sort();% H* q7 i8 L9 ^
+ e$ N# d' w; Y' _; {
fbox.length = 0;
( [: L+ {, C' a( U4 otbox.length = 0;0 F  }& p" o& l6 F
var c;9 K$ n+ g$ @! g7 k9 @5 m$ _
for(c = 0; c < arrfbox.length; c++) {
6 x$ I% D/ e( i- C  u5 I! R. ~var no = new option();
5 ~, Z  Z- _/ K% j( m0 zno.value = arrlookup[arrfbox[c]];
  u9 h% m5 ^. L/ T# i+ `no.text = arrfbox[c];
& y- a9 A7 c1 m( Mfbox[c] = no;
; x+ H# i% e7 l$ N# s& f7 y2 ?, D3 ]6 A}+ l) Q: x0 ~5 u9 O  S
for(c = 0; c < arrtbox.length; c++) {
- h8 g! |1 h& r  wvar no = new option();
' n/ W* H3 N5 U+ Kno.value = arrlookup[arrtbox[c]];/ r  `% e1 k  W1 z  [7 D
no.text = arrtbox[c];
* m* w  \- |  b' H4 j' Qtbox[c] = no;
+ w5 r$ n* a/ W  n! m1 H   }
# k3 X. g8 E8 T# n+ h, a}
& Q/ i* K- X( `: b0 w& J: d: E+ \</script>3 z& J- h# p( c! v9 n0 z/ t
</body>
% o6 p- i+ a, W! l

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