返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
$ G9 _& j' t0 K7 R0 l( w( F  a2 ~         c pageencoding="gb2312"* {& a. G# R# L/ p% h# m; l
%>: R3 ]8 b9 n  y# Y0 j; S& @
<style>$ O* M3 ^) L2 h4 F3 }' j& @
.f9{ font-size:9pt; }
7 t( B" R  _- j1 y+ [' @7 i.bgc{ background-color:#aecaf9; color: #0033ff }6 S# `3 x& X8 ~' Y
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;& _* ^" I8 o8 w) [7 V; i
  border-bottom: solid 1px #4e7dc1;: W' G% f2 k  d) z5 [
  border-left: solid 1px #aecaf9;( `' ^+ i: Z5 g1 m# u0 ]
  border-right: solid 1px #5679bd;
; @; E2 d8 Y8 ?4 B  padding:1px;
  Y" p+ x' z; H% N4 N  margin:0px;}
5 d! Y6 O! V8 v/ i8 D% @: O</style>
5 e9 k  `' O- _& d5 D- z<script language="javascript">+ ]  A9 I8 Q' d2 o' N1 s5 Y
<!--
7 ?; U- U& `; q- Qfunction rv()
2 \+ H+ b6 i9 q" N: Z& J% r0 j{! @" C6 z% W5 }/ w' e) ~$ ~1 L
  var val="";; N5 e; k, o$ m. T9 Z6 J
  for(i=0;i<combo_box.list2.length;i++){0 B6 {1 J. A5 c0 ]* H
   val+=","+combo_box.list2.value;
2 n% }4 L3 H/ j& O( N0 k  }! _  N, ^# Z/ i0 B
  if(val.charat(0)==","){! G* x; z4 ]$ \
   val=val.substr(1,val.length);" @# x: F' N* m% j( K+ y
  }
+ P( s0 E( O% i! C  g  opener.form1.frecname.value=val;
: m% E; }! ~3 T6 ^7 }9 ^- Q, s  self.close();
% U  G" ^3 p2 b9 l}" n0 g$ u) v2 |' k! T
//-->
6 T7 N- _1 K! \+ ?, P</script>' u, i. x- k3 O% _6 x( C5 c: G) g
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">' N4 ]! ?4 F: W) p4 s# d+ o
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
5 z2 C( ^3 D6 w5 \% f3 g5 u* Q; x<%
) z7 T& C* B: R9 p# ^- A# G+ B% K2 E  cdatasource ds=new cdatasource();  //数据联结bean实例
& N; z/ T2 b# y  java.sql.connection conn=ds.getconnection();
) @& V: S/ b+ m# W8 S$ z+ j  java.sql.statement stmt=null;
8 A  I4 E( K5 m! b% {' P. O  java.sql.resultset rs=null;
3 c2 J' w. U, E  cdatacheck dc=new cdatacheck();
. r# P; i& Y; S7 s%>
0 V9 u! H" I0 I, k, c<%
+ d( k# E! l- {0 xstring 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";
* V( N) G: Z" F% T, nstmt=conn.createstatement();
' H' n0 @$ j9 Q5 R% Mrs=stmt.executequery(sqlu);
1 z7 T) E  w/ e) O( ^8 s$ ]%>
$ a1 R4 l7 Q- K" C% r1 g" E<script language='javascript'>
1 f. B. E, L6 i% |arr = new array();% x5 _- ^* P2 U8 _& Q2 m
<%  int temp=0;8 Q( [+ t, n9 z0 v! ?
while(rs.next())
  e" ]0 L' V# Q2 Q{- c8 S: c9 D/ ^3 S8 E# {- y5 ]1 {
%>
6 U6 z( Q! }! U# h4 H( n( ^arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");7 ~! R, k/ {) P1 C/ B7 q
<%+ P2 Z0 A* G" H! K% v
temp = temp + 1;
; \9 H* o, c3 R1 N9 N}( @8 T1 d5 w6 R1 A8 Y: d- L- n
%>$ ]1 _  ~  ~* [$ Q5 t% u3 K- Z4 m
temp=<%=temp%>;
$ V& ?: t$ X- j& G; f) i; Ofunction changelocation(id){
2 l9 ]- U( x, `: P" U" ~document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
  I. d) `  r! W: d  ^5 Uvar i = 0;
3 c/ n# ^" w! ?- ?document.combo_box.city.options[0]=new option('-------',''); 8 j0 E! _1 N' f1 L
for(i=0;i<temp;i++){
1 l) t0 N% G2 {; [if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] . V; e2 a' P% V3 R" \3 V/ T
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); - r) P& l9 v. u6 O0 v
} 8 _6 @4 Z( d! ^. a5 I2 K
}
0 ]  h# K2 M0 b& Z' Q} . J* R3 X! v3 d9 ?; `
</script>: i5 W8 I7 ]0 _0 m1 U  i, a* X

; G, F+ }4 \1 K+ n' E6 r/ K<form name="combo_box">
7 P# w1 ]% J' @( W. j<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">+ J3 l- L: Q) f$ O+ }
  <tr height="24">
: C$ U- q" H( |/ _9 @. x2 E& T8 O    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td># q9 V( l) Q+ ^2 z7 }- q: b$ M  \- d
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>3 c0 h/ U# \- z6 |) i
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>: u) ^5 ^, }9 _5 y) ]! ^& O4 T2 O6 d
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>8 U0 D$ K+ f7 m3 @& e
  </tr>: @2 D6 I5 u9 Y5 Z
  <tr>
( M* Y! e" x0 J4 [( A; P% p( U    <td>; P7 l$ d. A$ E0 B% ]/ V! u" C
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
5 P( i  D: G  L6 a5 b+ f  P  <option value="0">请选择部门 ---></option>
- Q, W/ B  A6 y* k. S5 O<%
2 o2 G! I7 a$ H- D: I3 \' ?& D7 S    string sqld="select * from tdept";
+ V$ t) T. V! C: Pstmt=conn.createstatement();
& s! H% U$ ]9 G9 h% Frs=stmt.executequery(sqld);
$ i5 s9 F3 M' t3 }while(rs.next())
) c3 U0 G8 x- J2 @7 f: D& j{
7 [) R* x- z0 x6 Z%>
; T/ n3 X+ y! R; E. J  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>% L7 j/ Y5 p- B8 `( Y
<%
; Q  z( V  Z0 X' r. H}, ?; S) O$ A- _& x5 {, d
%>
! w# y. i( N1 U$ F; o0 \/ z, d  </select>
# m) T: C1 Z3 n8 H- [# V7 G& ~</td>7 X% S8 j6 c  j0 @. V7 ?
    <td>( W' c! W' {- I7 n
  <select multiple id=city style="width:150;height:200" class="bgc">) b+ v/ t" n( q, N
  </select>  h% }& I3 J: i# [$ G. E+ v2 ]4 v
</td>, ]3 ?( C7 j$ |, F0 Q& L
    <td nowrap align="center" class="bgc">
5 U, N$ ~; Y: w% v& B  <input type="button"  value="<<" class="buttons">9 `3 f, \) E& @. O
  <input type="button"  value=">>" class="buttons">! P, C/ `. |2 q% _" P$ E
</td>
  j# O  v  ]# R- l1 ^    <td>
# j- t5 o- A4 [% F% F  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">" Y% w) |0 u1 i1 y
  </select>
8 \, V9 n" m' ]</td>
8 y0 Q2 x  F# P; ~  </tr>
" C  {, _/ r6 |% ]- i    <tr class="bgc"> ( e2 P. o) ]0 o
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
0 {9 t' ?( f+ q7 i  </tr>
0 O3 \$ m% d* x3 \8 e4 O' C</table>' _* E& J! q0 x2 c& D+ O
</form>
3 U/ `+ |2 X" |# [3 F: S<script language="javascript">- e. H- R0 Z) p7 r, r0 n
//人名移动
9 g( o; A, c  J! Tfunction move(fbox, tbox) {* S! w/ Q* O1 y5 z5 w
var arrfbox = new array();3 I9 c; U  i7 y& k1 Z( _+ S5 ]
var arrtbox = new array();- g& M3 T' j8 o" s
var arrlookup = new array();
/ |" k- A$ e- t" ]( Nvar i;8 \+ _( Y2 |! Z# w6 B# x
for (i = 0; i < tbox.options.length; i++) {$ j6 R: P& ?0 `& C3 ^+ ]
arrlookup[tbox.options.text] = tbox.options.value;
5 F4 l" y* F7 Y  zarrtbox = tbox.options.text;
# z1 P( U7 F7 H' \( I8 o}) a: }% [* P+ M0 _
var flength = 0;4 T" G& K) a! |, R4 L/ ], P+ J5 e4 q
var tlength = arrtbox.length;
5 t: @+ Y/ n4 y, ^5 Afor(i = 0; i < fbox.options.length; i++) {
& R  ~. i6 [/ oarrlookup[fbox.options.text] = fbox.options.value;
# i6 E: \$ P0 ?if (fbox.options.selected && fbox.options.value != "") {
- W5 [: S/ }( U) D" ]arrtbox[tlength] = fbox.options.text;$ Y" Z! f$ ^( l/ b' ^7 _6 C
tlength++;
* G3 f- X) D, q/ |}
1 [! F1 ?7 |- u4 v" g. S1 a7 Q9 aelse {! T/ C* ]+ M5 J, C! S
arrfbox[flength] = fbox.options.text;
: M/ J9 d& c* c2 [flength++;
$ ~, V; I1 k' ~4 U) @  G0 ^   }( v9 j1 r/ v" H% Q
}
7 z$ e+ D) c; q0 H7 _arrfbox.sort();
' ~; C4 N/ ]. P! J) ^arrtbox.sort();6 t; n- ^2 K+ L5 r, [# _

- T7 D2 z7 Z, H  \9 Z4 Efbox.length = 0;
( u2 s$ c) B9 |. [9 Ytbox.length = 0;: F6 g2 F5 q' K% _2 Y% x
var c;
# h- U3 _' n5 Y: s1 \# rfor(c = 0; c < arrfbox.length; c++) {
# d7 B7 w( W6 G, @% Q4 x/ Zvar no = new option();
" f$ z5 b* `! ^no.value = arrlookup[arrfbox[c]];2 C7 B- J- ]4 r& Z
no.text = arrfbox[c];
. c! |+ \" t! Y9 K% k1 jfbox[c] = no;
! l" m# h  A" p}6 J) c% n* P# i
for(c = 0; c < arrtbox.length; c++) {
, @2 t5 _( i; c3 I+ m! k" fvar no = new option();8 f6 Q) ]/ M1 G5 R8 i
no.value = arrlookup[arrtbox[c]];& J! a- J$ c, R
no.text = arrtbox[c];
. D" z- T; U! ~5 ~& q# ^: h  wtbox[c] = no;
# n- L2 T9 R, E   }/ g" L( x# w  a0 e5 H& w$ R# P
}
9 s% \" o! t5 @5 v0 U4 X</script># a7 v  ^/ m( d% f  Y- B: s0 y
</body>/ L8 a, D8 q1 \

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