返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
7 q( c. Z8 w' U         c pageencoding="gb2312"
1 q0 |& N  D* R8 p%>0 u3 [; i. a+ s0 n4 Y
<style>6 Z6 O: H/ g" c+ x8 U& y; {
.f9{ font-size:9pt; }" q( h6 A6 T* `: @# g
.bgc{ background-color:#aecaf9; color: #0033ff }
. z  p$ Z3 D8 j$ r, r* |' s.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
2 H& w  [: N9 ]0 T3 t  border-bottom: solid 1px #4e7dc1;
8 v: D: L2 p/ c$ t1 {# {, z  border-left: solid 1px #aecaf9;" K1 E' c4 F$ G' K1 C% r
  border-right: solid 1px #5679bd;1 T, A5 d7 w. Y& y; F
  padding:1px;
1 u6 \# e. a9 k6 G  margin:0px;}
# n# r6 T, L+ m) q4 D$ @& J</style>
! @* G. u7 D# O" d' P0 v: {: h" c<script language="javascript">
) z- |  I) ^4 h5 n<!--
* \# e1 U! q8 I- [" ifunction rv()% |- z/ j! O' S: D% r1 v1 w, C
{7 g& R  q" T; ^2 e( e$ P
  var val="";
+ p) G1 Y2 i& |  Y; b8 `  for(i=0;i<combo_box.list2.length;i++){
- N. o- {1 e5 j; s' B   val+=","+combo_box.list2.value;) E9 g9 m0 S& U+ d. d3 |# ?
  }, d" b' P  h( N, M; p
  if(val.charat(0)==","){. ~. k& A0 b, m* P" r! m( l
   val=val.substr(1,val.length);
2 _/ k5 ]2 V+ d. ~# ?8 s  }
' }' w. F# M: {& R6 ?- X  opener.form1.frecname.value=val;0 H; l9 K/ j; n) {8 K
  self.close();
9 ^6 K7 u/ ^5 r- M6 L  ?}1 I* _: j' l( J- m% t- h
//-->
1 J! \# p! m  J+ S  U0 x! u</script>% S7 ~) D! o' }$ v
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">" y  h6 Z8 K4 P! N$ s% e4 D
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
  G5 j2 D9 {) s; W3 [! C$ H9 p# j<%
( y4 q* [* t; a. \# p) U  cdatasource ds=new cdatasource();  //数据联结bean实例
2 X- S" W* ~) q; ]: X$ K. |  java.sql.connection conn=ds.getconnection();
! ?8 v+ ^6 j% x- O# \  java.sql.statement stmt=null;
5 v8 c/ x2 j$ T1 I5 w2 \/ }  java.sql.resultset rs=null;" h( d. X# X  i- I
  cdatacheck dc=new cdatacheck();
$ c/ q/ d: h$ _/ ~+ A8 d4 H%>
/ B9 j/ w, b5 v- z- r* U% c+ p<%  y1 t# z0 \1 t. |3 k
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";
+ c1 M) r) w5 G& E3 @4 Ystmt=conn.createstatement();
& x8 m' m$ Z$ ?/ i& K- O; Frs=stmt.executequery(sqlu);: H9 i7 Z" n0 t7 c5 n
%>
# I0 `% F5 A4 d! X# j<script language='javascript'>
; O5 a, t4 s9 ?arr = new array();% P1 q) ]$ R, _% ?1 }- k
<%  int temp=0;. Q; Z6 k5 p: g0 G* \
while(rs.next())9 {/ X& _8 b$ \
{
$ `/ N- {& B# ~( \5 F, D) j%>
) M# U( W4 d9 Marr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
) H$ ~' y7 c/ a  O- ?: U- x& r4 t<%7 P% e/ H* h/ `, j  o3 X
temp = temp + 1;+ L' k8 V2 f! l# L) B
}
" \) K/ a8 }. `' l, P; r%>
% ?/ r' I2 s. P/ rtemp=<%=temp%>;
1 i" d! [' K  ?  Efunction changelocation(id){
+ }7 M" [$ I: @; v/ Mdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
# h+ t& Q+ Q% h1 q( p/ Yvar i = 0; 0 X* }8 T) O4 L6 W4 h1 K
document.combo_box.city.options[0]=new option('-------',''); 4 H) d9 h: E- @3 W6 d1 j8 M4 v
for(i=0;i<temp;i++){
. F7 B/ H1 B, L1 E* i0 Vif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] ; W# H+ X5 Y/ p5 }$ |
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
" P1 g: k0 ?) J( @}
" ]3 ]+ P5 I$ [0 q' a* [$ p} ) l8 C& ]4 I8 M$ v" F
}
$ I2 Q4 ]3 u, h" g; L</script>6 p7 C8 x" z0 w8 h7 R

; `7 d1 A- Q. m" p<form name="combo_box">3 c: H5 c* O# Z7 i4 H! d
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
) X5 v$ y, P( B1 X' S1 ~( |  <tr height="24">
* ?" R, G0 f; d) l3 g: b    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>0 b9 \  Z' e7 q5 k% H0 {; o
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
1 c4 z3 H& r% l# [! v! j3 b. t    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>. q: q+ e. n' e% c2 d+ j) \+ v
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
7 p" C/ q% @- D& k+ U  </tr>
# w5 |# z7 E/ L3 M, k) {  <tr> / w6 c& W9 u5 c; `* v8 B
    <td>
  z% ?( Q/ F+ x& r0 g9 `! h  {. F! K  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
$ m) h5 B" X, K! G- r  Z5 Q  <option value="0">请选择部门 ---></option>( Q  C$ _5 X: r( A  s) o6 V; u/ R% m
<%) Q+ k& l; x. r/ G
    string sqld="select * from tdept";0 T: z! X' L# R: e/ {% }
stmt=conn.createstatement();! n3 ~; J; E! q; G$ Z  x
rs=stmt.executequery(sqld);( |+ o4 E- z3 B0 c9 u+ \) A
while(rs.next())! ?0 f8 l! x8 H% R  X
{0 `! K3 W; ?+ N5 P9 L) s0 A" D
%>
3 ~# `# X8 J/ I" x. a4 E  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>3 ~6 G( ~2 Z  p5 [
<%' m" @2 v3 Z7 W
}% a, o. J9 M- z0 _
%> % s. ]& H3 T9 H" M
  </select>2 w" S# Y' q5 }1 @% E! r: t
</td>
1 z% v/ R, c2 i% }& d9 |% ?    <td>/ v. c$ W- ]) \6 M7 ]( ^
  <select multiple id=city style="width:150;height:200" class="bgc">
# L7 T! S- ?$ S  </select>* ?) |2 {' u" P
</td>8 P6 B! b' e  t; l3 [1 a/ T
    <td nowrap align="center" class="bgc">& e" ^; d3 v5 a
  <input type="button"  value="<<" class="buttons">
2 y' m3 l" h4 M: d/ O  <input type="button"  value=">>" class="buttons">
3 D, R5 f# Z. D</td>4 k  }! Q8 v4 d' D: }8 I" \
    <td>8 ]) ]: Y3 F+ a
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">6 |0 o6 L/ J1 ~' c$ j7 U5 @
  </select>
) M! E6 W  e/ u- z4 V& ^3 |+ w</td>: L  M" p  d7 H7 r1 s" F; Z3 ]
  </tr>
4 x) G3 B2 y& ?! S0 o. u    <tr class="bgc">
1 O5 x( _; D% V    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>/ U3 d2 O; @& @
  </tr>
( L! i; J! b8 f7 J7 W! Z- i</table>2 U7 q3 w8 b% l% P2 ~5 K2 C
</form>
: H; n: w( ]( P7 L<script language="javascript">( n+ I9 ]) ^5 |
//人名移动
+ L- g3 ?  ?8 k2 z6 Lfunction move(fbox, tbox) {( x# t) p6 l) j1 p
var arrfbox = new array();
0 n# {8 W$ r4 O2 M. c' svar arrtbox = new array();  F0 A+ ?# [! ?( A( y+ {9 y$ t/ A
var arrlookup = new array();
- ~5 v# j3 F1 D2 P5 W( g' V" Fvar i;
2 U5 K! g- X+ m7 p- b3 r8 ?for (i = 0; i < tbox.options.length; i++) {) i" `( k0 T: Y& D( G1 V
arrlookup[tbox.options.text] = tbox.options.value;
! R9 A* q, y! J- R2 x0 s, \arrtbox = tbox.options.text;
5 k4 w) {$ w$ x! `. l3 U}
& ?1 J6 k% Z8 R/ B" }5 h: vvar flength = 0;- s, S1 k/ ~" s
var tlength = arrtbox.length;
3 I* ?+ p! C/ c- e+ x  gfor(i = 0; i < fbox.options.length; i++) {
( v! o+ ~& O5 Y5 L) p6 Yarrlookup[fbox.options.text] = fbox.options.value;
% M4 V+ G- O7 M+ A0 l- t& B( A* Tif (fbox.options.selected && fbox.options.value != "") {, Z5 v7 S* m: L
arrtbox[tlength] = fbox.options.text;9 W8 }# z6 q- Z* U$ N( K# N, ]' T
tlength++;
" h/ U7 s  z4 Y* ]" F}
# L3 `, P$ v+ `0 q) {7 X- L# `else {
$ C+ Q6 G/ T, w+ b  u/ y3 i# harrfbox[flength] = fbox.options.text;4 ~; O* x% a8 P* Z
flength++;
( u" m1 r4 p, K+ q   }
5 [# k' ?8 x! a) g% s" ?& i% s# {}6 e8 V9 E3 N) _& P. f$ M  v
arrfbox.sort();( [3 b  F8 ^& [/ Y4 Z7 W
arrtbox.sort();0 ]; k6 r9 h8 F' k! [

; T; V) E" {% c; k- _& ufbox.length = 0;
! O) }% `2 h0 b; etbox.length = 0;
1 n6 B% E) x2 Q# rvar c;2 a8 o1 |) N  F3 P6 g1 I5 `
for(c = 0; c < arrfbox.length; c++) {6 z! a8 M' z7 n: y1 g' r7 u
var no = new option();  g- Q( ]/ e4 V
no.value = arrlookup[arrfbox[c]];+ {5 `& a! I8 _+ k
no.text = arrfbox[c];
4 |( r- a, {8 _$ y0 @, Wfbox[c] = no;8 P! }4 V. Y# l7 c
}. B' h9 m& V" l5 n- y
for(c = 0; c < arrtbox.length; c++) {
1 ]; F$ e4 q. Rvar no = new option();
( T4 i( P8 F! O7 ~no.value = arrlookup[arrtbox[c]];: O" b/ W6 r# r! y1 U9 n* D
no.text = arrtbox[c];
# i5 {' O. v6 X1 `1 N" utbox[c] = no;' G) Z, h9 S! w5 T& F( n% Q/ d; {
   }4 ~; j" i4 d6 `6 P7 p- Q
}! J) p) c5 F; {1 L- u" N
</script>& x0 W9 t" ^" o8 t/ _
</body>4 T$ @$ s. v) y) l) g0 p: z% E

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