返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"2 l7 X* J1 }. ^) f5 L, W( C$ F# ^: Z. M
         c pageencoding="gb2312". o! R1 w( Q$ |  \  }; c
%>2 e, d6 q6 k4 ?$ L# V
<style>
4 K* t# [# G: ~1 f$ w* z.f9{ font-size:9pt; }3 J- _( x$ Q; M
.bgc{ background-color:#aecaf9; color: #0033ff }
) _; Z% p3 T# [+ g* \0 R.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;$ u* t# i" h8 c& z; w
  border-bottom: solid 1px #4e7dc1;
' m) k* m% {: U; ~  border-left: solid 1px #aecaf9;
9 ?9 F: d! X6 N1 l4 B# {  border-right: solid 1px #5679bd;
, O2 Z* x3 m. a6 @, R, r  padding:1px;
2 l0 P4 t8 Z. }: D1 P  @7 W2 f  margin:0px;}+ w; I: f% _+ \! G8 [+ f5 F9 b
</style>
2 Q* I1 Z1 V3 r+ y+ R* g$ b7 [<script language="javascript">% |+ T( b- U5 |8 I( Q) W
<!--* Y# L7 V- y3 V. S$ @0 [3 ^3 {9 B
function rv()
4 f3 u! o4 t+ j{
% @; L2 }' \6 m" G  `( N( \  var val="";
8 k- x) s: b7 V$ s  for(i=0;i<combo_box.list2.length;i++){2 t$ X+ j. P  T# U3 F! W
   val+=","+combo_box.list2.value;+ K* b* U! C0 N0 k
  }
& c' i" q! `+ p" q4 p- z  if(val.charat(0)==","){- W$ E$ T" Q0 S, Z. B- k
   val=val.substr(1,val.length);
+ C% T$ u2 P3 P- D+ l0 J  }
" ?% x/ O& J; n  opener.form1.frecname.value=val;
) S" y7 ?5 @! i% N0 v0 Q% N  self.close();& g% h) w! x% N
}
) ?3 G" Z4 K% h: N! m4 A. b4 ~& O//-->
6 {5 C% d) b0 ^5 C* t1 Q9 W5 Z. P</script>4 m3 U. F' c' q8 {7 F
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">2 h4 N* i. s% V. \5 _2 l
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
. q2 q% f- M0 J<%( @3 s  o/ |1 R7 S2 C7 M. @! b( i
  cdatasource ds=new cdatasource();  //数据联结bean实例
9 t# ]' L. s( c% q/ d* }  java.sql.connection conn=ds.getconnection();1 H& u: J0 X8 e  U/ @7 |, R
  java.sql.statement stmt=null;* S( b$ E: C6 }# h3 b4 @5 B: Y; V
  java.sql.resultset rs=null;% B0 w" l) p5 ?9 k9 Q2 a! ~' F
  cdatacheck dc=new cdatacheck();
0 g8 _; G4 D2 a5 F4 ?4 j/ M%>  F8 r6 c/ V/ ]8 ^
<%5 H+ b7 k' |/ m! ^+ z
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";3 D6 R6 f% }# I$ Q8 m& e7 g7 t' r
stmt=conn.createstatement();& M  {6 I0 ~  _# G! }9 V4 \! T
rs=stmt.executequery(sqlu);7 x, a$ }6 J. v" L1 O
%>
9 U& H: z, d  r- W- G2 u<script language='javascript'>5 v) f) y- |- K3 s9 F! k
arr = new array();/ P  h0 Q3 D8 E6 b
<%  int temp=0;7 n4 f" K: l3 ^! |9 K; o0 H7 `
while(rs.next())
" r& G! N  F, h1 {{
3 z) I& j3 `, x  l%>
$ N+ g! G  |0 Q+ w5 p' l7 karr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");4 l$ J% i4 T. Z, P6 C8 O0 h
<%* W" m  R3 O5 t" T& r8 p
temp = temp + 1;
% k! Q4 D: D: j- h( b* ]}
) G2 O# V2 I$ I. _7 k( Q%>. c2 g( V. L* U3 D
temp=<%=temp%>;
0 E  `, M+ P) e4 w: Wfunction changelocation(id){
( W& G& p4 ^8 \" w" t* @, Y- Wdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
' `* z. P+ m4 C& B; {var i = 0;
* @/ D7 n+ M" M$ H- n+ Zdocument.combo_box.city.options[0]=new option('-------','');
+ F5 _$ L+ c8 W  p' h" L" k# b- T  jfor(i=0;i<temp;i++){
& Z( S" a* t* A, g/ V, ~6 Gif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] ; M) e) H( Q4 g0 |' n  t" n
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
  M  }; _/ l0 \; u7 s" j- y" w} & f) G& r8 C' ~3 r
}
% S  }# Y/ g# r3 v} ) Z9 D1 _1 j/ C6 z' p/ M6 s, |  W
</script>; F/ @$ I- g( y) z

( U) b& c0 R# i% b2 i  ?6 j<form name="combo_box">  X* i  }  ~  h7 C* y& a' L* R
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">  p; e( G1 ~% n) W5 R0 v' f& B6 T
  <tr height="24">
. y$ N  D& e6 b4 s# q    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>6 Q) Y$ _5 ?( J0 c5 k3 M3 l1 G
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>! @$ J) a" r) O/ J
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>* L$ `! @! R- X
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
# J. |5 M2 i3 F$ ?7 h  o  </tr>
2 Q' _$ O9 M$ p$ ^  <tr>
' m# E( m/ t% j) F  h    <td>
3 G  r8 o. n! o! \3 ^  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">  B4 F# H/ y. l5 V2 ^  m
  <option value="0">请选择部门 ---></option>
: Q) w, o7 [% q) p) x& J<%. y2 L0 T) t3 J3 ^% d! n" T1 m. g% ^
    string sqld="select * from tdept";4 _5 D$ z! y2 o  F) }
stmt=conn.createstatement();
8 u! a7 F* C' I: Ars=stmt.executequery(sqld);
6 n, D) M$ F+ G1 Xwhile(rs.next())
; h$ w7 b7 C$ b. P/ O! O& y{. c( @9 [! Y( y$ }  y0 w) `3 }
%>- L% w9 d( z# _# Q
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>9 E: s$ k( X2 b% D
<%( v3 c' f9 E* U, ?5 P/ T' m5 t' F
}
2 ]0 _1 S% V- g. h4 s%>
' ?& }) `' a8 e! r- a* S  </select>! }4 i9 N2 n, {/ N9 |
</td>
0 }0 M8 l: m9 o0 Q2 C( }    <td>$ Z; S+ h9 H5 A9 K* e0 C
  <select multiple id=city style="width:150;height:200" class="bgc">
. ?* _5 E( r5 S, S, W  </select>
) c% c, X& k  @# J3 C7 V/ s</td>
: B# f1 n/ q: z. Y    <td nowrap align="center" class="bgc">
' c& B; Z+ E! \: r& p  <input type="button"  value="<<" class="buttons">
% w3 M3 a2 L1 f  <input type="button"  value=">>" class="buttons">
9 s" u; d: {1 r  K8 }/ N</td>4 n: E2 o8 z- |( C
    <td>9 _. V/ V0 o2 Y1 U2 @
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">+ t+ h5 d  {/ b
  </select>
; h) t4 ^# G& `- \</td>7 |4 a5 [( Z2 G
  </tr>7 j/ C0 y& \6 v8 M: {
    <tr class="bgc"> ( E' D3 J8 k2 A" \! w& C" ?0 P
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>* d- M+ j( F: H1 v  p9 C  V/ V
  </tr>
3 B7 M3 Q5 r0 W) b</table>% L+ ]) m$ s2 r8 @) X' R3 m& |
</form>( V6 b, E& M- O1 Z- ?
<script language="javascript">
& I3 @9 u) |$ N' C5 O//人名移动
* k: H1 f2 h4 G! Nfunction move(fbox, tbox) {
- u3 C% b. C6 `5 i1 ?' h" Ivar arrfbox = new array();
& {5 G/ Y- H% o! s1 }# n. |* ^var arrtbox = new array();# h8 ?0 [. R0 P: U! N% a2 o0 @5 U, ^
var arrlookup = new array();
% O7 Z+ l; g9 t' _' k1 d# ~$ Z- cvar i;7 b- U' y3 ?) l7 @" G; B* s  L
for (i = 0; i < tbox.options.length; i++) {9 N. v* f6 a3 C8 d, N
arrlookup[tbox.options.text] = tbox.options.value;- Q9 I! R9 T% l9 k
arrtbox = tbox.options.text;
* J( b+ M$ v. \  r8 T1 u4 N}& j3 Y; L* ?3 _. Z
var flength = 0;
) U$ O- k) `1 x" R7 Mvar tlength = arrtbox.length;
5 |' e% q9 {8 Nfor(i = 0; i < fbox.options.length; i++) {7 e9 T3 j9 i; k# B
arrlookup[fbox.options.text] = fbox.options.value;6 C) H# b3 H: Y7 {2 u
if (fbox.options.selected && fbox.options.value != "") {
. N% H( F; r! F' ~5 @  l3 uarrtbox[tlength] = fbox.options.text;6 I. b; {/ l6 U
tlength++;6 u- ^( ?! s1 k' s' F1 S! ^6 p4 z5 J
}4 C4 }, ^5 |7 q4 k% ~
else {
+ q8 l) X; u3 F9 W; h  w, oarrfbox[flength] = fbox.options.text;! [* j2 B4 G5 s' I) d
flength++;7 x# k0 [# M6 g! a& i6 i
   }" I3 N( B0 L% d7 Q. V
}
1 ~* F% x3 F; s* ^+ Q/ B. ?arrfbox.sort();
2 @/ f3 E* u- L( @arrtbox.sort();
/ H1 @0 `5 R# g! P  f2 d2 |% N. c# e, X( M! F
fbox.length = 0;$ _8 x8 n' H. A  W
tbox.length = 0;
0 Y1 s5 ^+ I2 C  Zvar c;$ w9 i1 s& P1 |7 _, u9 k
for(c = 0; c < arrfbox.length; c++) {
+ u5 U/ u' f  r3 Z( f% {5 Lvar no = new option();- K9 D7 q; G3 X' Y% p
no.value = arrlookup[arrfbox[c]];
- Q9 g2 z+ B4 tno.text = arrfbox[c];* x! m+ r% A6 a2 r* C. o9 l7 U5 L
fbox[c] = no;
2 ?/ r2 p/ X) q) f2 T! w; g% z}
4 K0 A* o# I7 b. C( ?for(c = 0; c < arrtbox.length; c++) {" f$ S! W5 d- C/ h- o) v
var no = new option();! G% Z) O5 _. U
no.value = arrlookup[arrtbox[c]];1 c1 n$ }! H; x$ Q
no.text = arrtbox[c];
4 S1 G" }5 N  d, y% [0 Btbox[c] = no;
/ @( [0 i, D3 S/ m" s$ K   }- P3 A9 N9 A  A; e7 R4 X/ {  t( \
}( y% Y- i1 C7 E  h+ D
</script>3 V- w* ?1 b6 t% l4 K& b8 f& T* W* v
</body>
( Y  s1 n$ h& x' Z! y& R

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