返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
4 j5 _2 G. h! V$ y+ Q         c pageencoding="gb2312"
, A+ p4 z' C& q/ U%>
* ~1 R0 W. t( Z, b" O! d- [/ H3 I6 J<style>
) i$ z! K  _9 @& a; j6 f+ Z. T.f9{ font-size:9pt; }3 |3 J& K' j1 P$ G
.bgc{ background-color:#aecaf9; color: #0033ff }8 `; `5 _% u' p. o! F/ i
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;  d9 W/ W- G- m' G8 c( L% ]
  border-bottom: solid 1px #4e7dc1;
) \4 K. }( ~; S. [* M) [  border-left: solid 1px #aecaf9;3 w8 v' q( x6 E' D, N1 t; J' P8 m
  border-right: solid 1px #5679bd;
% S& A! z$ q- R- e* R0 u4 z  padding:1px;
* |, g$ T1 Z/ b$ b& [/ r9 A  margin:0px;}9 Y" i2 Q- _1 R! _% t9 s' r
</style>
; B5 F+ y6 y: I) D<script language="javascript">( d& ^! H: s& i2 k* k
<!--
+ N) N. G. e) I' x, @" nfunction rv()
/ B. u) B* E. m, ?( a{/ O  b% Z: B* J4 A
  var val="";
# y2 h, O% D! P1 l  for(i=0;i<combo_box.list2.length;i++){" K* j5 X" w2 v, F5 a
   val+=","+combo_box.list2.value;
, r( H& j' I5 n9 o  j' Q  }
9 M( ?" ^8 g; Q: R  if(val.charat(0)==","){
( |' G3 s1 ^3 l1 [" J   val=val.substr(1,val.length);7 C0 Y3 |8 S+ r' n2 E8 a
  }- t4 W( C* u" Z# M7 J# E) P
  opener.form1.frecname.value=val;
+ \' M5 Z! D% n9 v& z$ H  self.close();/ g/ ]* N: B6 P/ {. N; \
}/ q! |! N  |' G6 F$ r5 I6 W
//-->
( e+ \, _  [: V, Z( d2 [</script>+ `3 }6 i. L$ d' o' O+ J, {
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
$ t2 n* s+ {% l" _0 n5 N<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />9 f7 U% V. t& H7 g& b
<%
, ~4 i- o6 r) n$ ~  cdatasource ds=new cdatasource();  //数据联结bean实例
8 w. ?7 Z  [+ N$ @1 v8 E  java.sql.connection conn=ds.getconnection();! i! `! x& n; H+ Q1 {
  java.sql.statement stmt=null;+ T7 {3 `# ?- l& i8 I( B) b9 d# ]
  java.sql.resultset rs=null;
5 a1 a# f6 j# H4 W. y0 S) N5 h, @$ U# C  cdatacheck dc=new cdatacheck();
6 L  e( f- b$ M! r- f/ p. D%>( k4 |' X; h2 T% e3 }
<%* ?1 P1 o) A; j/ ^6 c5 d
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";6 S3 Z% H4 R- `9 Z7 S$ [& g
stmt=conn.createstatement();
0 A' T0 Q( U  j- c/ D: {: Krs=stmt.executequery(sqlu);/ S! ^# X0 R, h7 D& J; |
%>
. v$ p! a8 Y7 S4 i+ B<script language='javascript'>
7 @( O( F2 t  k! \3 yarr = new array();/ [" r4 d8 I- R* o' _. a8 f
<%  int temp=0;
! k: i3 K6 M: t- O) {+ z9 [- X- [while(rs.next())
* n0 f& t0 u: P# S2 u{" Q3 M; y2 }# D3 F0 l( k. E( p
%>, t4 s. s' X$ @; K1 z3 K% X3 V
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
* l$ O, \! n8 K0 c% l1 |( E% ~. H<%
( U9 O2 j, e* S) W: {/ V1 a7 etemp = temp + 1;
5 M$ R: W! R8 V$ t3 d}
% e8 V7 Y9 W: ]8 t5 }1 n9 {! y. m%>/ v# h1 e! ^9 }" l
temp=<%=temp%>;
) E5 D6 i6 D# F' u1 ^% D! m& k+ @8 Xfunction changelocation(id){ 6 ]! p& m) O; M# f- I7 p
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 ( s# w1 U4 e% {2 e% k
var i = 0;
* D. }/ A3 Y) @: w" o2 E1 udocument.combo_box.city.options[0]=new option('-------',''); : H3 B' T9 k" p
for(i=0;i<temp;i++){ 8 w6 B8 o( r6 W- x: T
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
$ d* Q" N! ~. mdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
0 i7 z( R: h, w# {5 O}
8 v7 N  d; I' q7 k* f} ! B- t( K2 x7 u' n1 x1 B
}
  W0 q5 M8 }( U</script>& S- T2 C4 c' w- P- A7 H( F8 P

) P$ P# M( m" _6 {& p; X<form name="combo_box">  P! R6 Q' W8 ?
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">0 \6 w9 D3 h! w( ]5 s
  <tr height="24">
/ U* |: j. q! R) U- n: ~8 ]    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
5 ?% }; Q1 {/ u' a$ J* ?, k    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
: b& }! H5 y3 J0 i* ~2 Y    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>4 x" F: \8 ~4 o7 B" l5 Y3 r
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
6 Z# _0 r% w9 w! [) u4 Z  </tr>/ Y" b6 ]; ]  I9 q1 R0 ^
  <tr>
+ A& q/ ?  g* B  C/ d( Y' W    <td>% h4 M: m7 [1 G/ b
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">/ H/ D  o: ?2 @# o7 d! ^1 W1 f
  <option value="0">请选择部门 ---></option>& K  T$ V. ~# z$ P& q: K* b
<%! T: D) q. Q* }5 b# }
    string sqld="select * from tdept";- h+ Y0 x- d; `; f0 T! q
stmt=conn.createstatement();
: p! l6 `8 C, a. ]rs=stmt.executequery(sqld);
0 O4 X4 ]. D( D- mwhile(rs.next())
9 F. f' Q2 i% b% H  D# X{
3 n* B9 i- o8 _* q' Z%>
5 f' |; ?3 c: L  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>6 ?9 \8 f" x0 \4 I1 ?  N3 m
<%
- a+ [% n" L1 y# d: r6 h}$ S3 z, Q9 b5 O. z5 S4 |/ R
%> % y, A3 ^8 }: a% I4 K' C) \8 o
  </select>" S$ p# }0 L. {' @" J6 u
</td>
- q$ n' o! S$ ~+ Q+ n) P# q) b    <td>
, a4 @5 j+ ?) @5 }9 @  <select multiple id=city style="width:150;height:200" class="bgc">
2 V7 d5 z, j" y: P  </select>
' P! }# i! ~* Y2 a/ ^* J</td>$ W8 D0 {. i# }9 m8 _! R* C. |
    <td nowrap align="center" class="bgc">. v  j( K0 m9 \* t) q9 ^3 L; ]
  <input type="button"  value="<<" class="buttons">  a8 Y& r7 o: P: o; g9 n& G5 X
  <input type="button"  value=">>" class="buttons">" J+ j' F  T2 M8 r0 y: @3 L+ F$ O
</td>
- a  ]4 A! ?5 _2 W    <td>! o# w) b: g) D9 @, c
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">  q- p$ M# D! a9 w+ x
  </select>9 ~7 }( ]( Q) J- p( A
</td>8 T+ s  ?3 h* K; G2 Z" g: U* e
  </tr>4 {' Z& A1 i. B8 m( {& H
    <tr class="bgc"> 0 A! p  w+ x4 r' A
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>* A8 y/ i  V& T- ^
  </tr>
+ _/ a/ b& A6 E; g$ q- C6 O) y/ d</table>
. `- A" D/ y  q% n9 h5 u</form>1 h- j  @: X* i, J2 F8 O  J
<script language="javascript">
4 ^( F: b5 v5 Y, |; ?//人名移动
. r% Y& v6 v6 O% rfunction move(fbox, tbox) {1 [8 D- E7 I0 h" {9 S
var arrfbox = new array();
3 a; s+ J% m* xvar arrtbox = new array();" U, [8 v% m6 J9 \+ C* X7 c# B
var arrlookup = new array();- {& G% z4 g& x" H" b
var i;" p6 m' f7 C9 ]! g5 u9 K; T0 j
for (i = 0; i < tbox.options.length; i++) {$ @% \# ^6 }$ S6 T8 g1 `9 w
arrlookup[tbox.options.text] = tbox.options.value;
! ]9 T# a- L0 a( ^arrtbox = tbox.options.text;
4 t4 n% B: O- z6 E7 G- A9 `}
9 Z+ S& R3 q8 Z/ Z6 Q8 s( c0 Mvar flength = 0;/ v7 C. H" D+ c% D! A7 T& u+ G
var tlength = arrtbox.length;
1 m; S  }3 j# Q% Z, B% ]( tfor(i = 0; i < fbox.options.length; i++) {
% t" J/ {& e# ]8 j. u" r0 ^arrlookup[fbox.options.text] = fbox.options.value;7 W. ?! {+ e( z8 M" z( Y. p
if (fbox.options.selected && fbox.options.value != "") {
4 j0 B1 |9 {5 H5 ]& r: Rarrtbox[tlength] = fbox.options.text;* H4 e0 A, F6 V$ i# g  y' y1 F
tlength++;
. a6 f. ?( i5 V3 X4 o, s9 M) n$ N}
! }3 R/ g7 b" delse {- R3 |) d: T' p4 c  Z
arrfbox[flength] = fbox.options.text;
+ |6 u: J) A9 C3 C0 N" a* Yflength++;0 V* k4 a$ S5 p8 m- u; Y- A; ~
   }
( F, R2 a7 P. K+ `+ t; w1 P, C}2 N, D$ L4 v2 X! ^' s5 j; O
arrfbox.sort();
+ H& B1 [( e! }" karrtbox.sort();- b% V7 h8 W* G4 J: E  e' k
- o/ Y" D" o' {" p( O
fbox.length = 0;4 @6 D* C4 x! l
tbox.length = 0;
+ W! z4 o) Y  svar c;
5 a: }/ A7 t& w% p- l) ]+ k1 @for(c = 0; c < arrfbox.length; c++) {6 ]6 \2 `0 E9 ^5 K4 Q$ z
var no = new option();
5 ]' ]; e9 m9 V. N: \% n9 pno.value = arrlookup[arrfbox[c]];
( J9 k. h* j( s8 H! Y0 C. nno.text = arrfbox[c];
& O- V2 \* H" p' \fbox[c] = no;$ M5 o3 g+ G% S, e
}: r' F5 G. _% N# U8 y
for(c = 0; c < arrtbox.length; c++) {0 t3 w+ D0 R  j) c3 [1 D% Z
var no = new option();6 w* d' g) |* o1 v$ l! s
no.value = arrlookup[arrtbox[c]];4 u# j. @& g( h! K/ f- ]; t. x1 B
no.text = arrtbox[c];. X  s  o4 Y* A8 t) l" ^
tbox[c] = no;' h* {4 ^- W1 T: Z5 @% c$ B& |
   }
" r, d7 D  \1 A}4 g( @7 a* w, j) m( F3 Q
</script>
, @- z2 A1 T! b. t) Q6 J</body>9 ~: X( [' [' w) F

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