返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"- `" }! H2 t& Q6 S/ c) q9 ^2 N
         c pageencoding="gb2312"
/ Q; G% p4 W2 V  H1 V  G* f( F5 i%>  X& A" {  d3 [9 g. Y, L
<style>% g. i8 x& r, y$ p' @/ `2 v
.f9{ font-size:9pt; }* s/ D- u2 E' q7 g$ W
.bgc{ background-color:#aecaf9; color: #0033ff }
+ Q+ D6 Q8 N! K6 K; W' m.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
* g( @) {! l! O2 p& u  border-bottom: solid 1px #4e7dc1;
' E- O+ h; t$ P- ^6 _2 J6 U0 E7 w  border-left: solid 1px #aecaf9;
" {! d8 U# ], K  k' ?0 o  border-right: solid 1px #5679bd;
5 _% X- x% s, A" Q% I  padding:1px;
& c! y  F2 k' p  margin:0px;}
! S$ t, D5 I7 P4 S1 u2 p1 l</style>" t" e/ ]# Y$ F! }8 |
<script language="javascript">
7 A/ I8 N! t! B" C' i<!--& ~  `3 B4 z9 l$ B
function rv()
2 G# L' ^) d: x/ L) a; D{
4 A' O. I, i8 {  var val="";
2 m9 Z, P. J- ^  I9 ~  for(i=0;i<combo_box.list2.length;i++){( z  s( ?5 N- Q
   val+=","+combo_box.list2.value;* @# w; r% H' {' I$ D& a
  }
" x/ J" S  F; k$ R6 A0 N  if(val.charat(0)==","){" @; w3 e$ A9 r/ q
   val=val.substr(1,val.length);7 x% G6 H; e6 @$ x% v
  }8 Z3 ^. S, R' A  |2 A; F
  opener.form1.frecname.value=val;
% ~9 F3 S! Y" k5 ^4 Y  self.close();; G5 s6 {( B: U$ E+ k8 n
}
4 N3 F0 N+ S0 L/ C' ]4 X//-->
3 ~; X2 \7 ~+ [* D! L+ f+ l</script>  Y" ]! D# }$ c
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
/ ]5 {1 Z( [" @- z3 k/ W% f" M<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
5 }2 g& f8 T) {! _9 Q5 H5 e<%. F  t+ x5 p, j& ]
  cdatasource ds=new cdatasource();  //数据联结bean实例+ p" C$ Q. N# M# k& ]) p
  java.sql.connection conn=ds.getconnection();% f: d" s& m- u3 R
  java.sql.statement stmt=null;$ w8 B1 `" k& d3 I$ H
  java.sql.resultset rs=null;( G* _  e4 l9 E$ G0 z8 l) c9 ]) }
  cdatacheck dc=new cdatacheck();* Z8 g; n) D' n! Y  O; M
%>0 \& `+ V% ^, u+ u" ?- B# |
<%
# B3 g! `. _' n# a, L4 @/ Vstring 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";" i; g8 n; h" u5 s5 u4 P3 J
stmt=conn.createstatement();
. e2 W5 X7 e2 H$ R% Jrs=stmt.executequery(sqlu);$ I' r% H$ [/ K4 ~6 V
%>8 c& L3 [) v5 M% i  \+ m# j" b
<script language='javascript'>
' T: Y+ t- |- v1 C4 l* \" f9 warr = new array();8 j. W7 `8 q5 T5 f+ @
<%  int temp=0;
7 t' Z0 m8 ~5 n6 \' ]while(rs.next())" r9 ]* t6 K7 s  w6 Z& K
{
0 M( j% z7 Q5 M" B%># }. z% t- v$ D- q9 I+ k
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");) ]) U) {2 W; u$ `
<%
, A3 s: I; I6 j( P) `temp = temp + 1;4 D" C2 b3 P4 l; m1 u
}! n/ z5 N$ Y5 t6 B- v. \
%>
4 r8 J8 [% h7 h7 \$ U/ ltemp=<%=temp%>;
9 i; }/ h; U, p% hfunction changelocation(id){ # x, V1 [6 V/ t3 I' d4 C' _
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
6 R0 Y; X/ x# d) |3 o  J6 Cvar i = 0; ' J5 A0 {+ s+ e# M0 V! D( d" ^% G
document.combo_box.city.options[0]=new option('-------','');
5 @$ Z& @) R/ e% [for(i=0;i<temp;i++){
9 I9 M# f7 l# xif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 4 P# l* ?" e/ k
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); * m  S# D. t5 D( P( Q
} ! S' q2 X" t: b1 k; m
}
4 S. q" O1 l) L}
" o$ T: B4 g3 e! X- q</script>
2 X/ `/ @' s" G  F) F3 g1 `
& O% z, \* l! C<form name="combo_box">
. b0 i% [2 A+ m6 a( S<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">9 G8 G& N6 c% p. f
  <tr height="24">
/ c& d* p. Q; A3 p    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>4 n$ b' `: y* K/ }  Z3 e! \2 p' \. V/ g  W
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>6 ]  [4 J  e& E
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>0 A3 }4 V( f# X6 ^2 c/ L
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>: e8 r( u7 h0 R4 U5 |
  </tr>" F  k/ S$ H% t( N/ O2 d% Z
  <tr>
0 q- T+ v# T# L# X+ r    <td>
% t& ^4 G" J) q/ _  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">: w& r0 j- p( @; @! ]  Y
  <option value="0">请选择部门 ---></option>
; N/ w- f4 c/ x<%8 n6 m: v# T+ _: p9 t& {  d% D
    string sqld="select * from tdept";
$ p( a7 {/ I: W! k. K& tstmt=conn.createstatement();' f. S% c+ J2 Z6 n. Z; X- W6 u
rs=stmt.executequery(sqld);
7 I6 }. I/ v1 V9 \' O, Nwhile(rs.next())
6 k: ~( c9 `4 ]8 C{- k& p$ B0 L% W0 \- f
%>% q! D' I* j0 w& M& k6 p  a
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>2 U, V% k  a/ l* ^
<%7 V" b: S8 K6 [$ ^# y8 ~1 B+ i+ f
}6 ~4 Z0 p( A. I" ^1 v3 d- V
%> 6 V, {/ ^& {9 h
  </select>
- v0 k- `  o" T( n3 t% j9 `</td>
- V/ |( O7 n) |9 F2 J4 Q  [  a    <td>
/ k/ s+ p; n# _- T; L0 o% ~, k2 j  <select multiple id=city style="width:150;height:200" class="bgc">
6 |6 S9 P# @3 I  </select>6 n, z% r8 ?; p& K' I7 e$ Q
</td>
# `7 i2 C& E- n8 w6 ~    <td nowrap align="center" class="bgc">
6 B! H7 q+ H' d* J  <input type="button"  value="<<" class="buttons">+ {4 L9 _) K% R+ T8 {
  <input type="button"  value=">>" class="buttons">3 k' g- t$ Q; W  R4 A$ F3 G
</td>6 t3 S* u* }! y' g1 ?  F# O
    <td>
/ T& l/ W: W! K$ M& K# Q8 ?  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
9 h% t! B0 C- l1 F( Q5 I, i, e  </select>8 }6 T2 J. V, \$ Y6 G& ?
</td>1 ~0 {" L' Z& Q6 p- b
  </tr>
! t. r, L0 E* ~. J; h    <tr class="bgc">
7 z; g2 M3 t7 I$ K0 X) ?8 v3 R0 f    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
9 v% I& {/ m! \- t! G, b# x! f  Y  </tr>; _1 }. T3 \! d7 A6 Y6 B/ }0 y' \
</table>
1 y' i7 {. [' U" A. V" S</form>4 g( G% @, j  \* r
<script language="javascript">
# N" Z) p$ t. x8 i3 ]//人名移动
! {; q9 V( S* `; k; J; ?function move(fbox, tbox) {
* R% A' _- a9 r) p/ J1 cvar arrfbox = new array();
/ k# Y9 k0 ]' g( Q9 F* F6 y4 m4 l# xvar arrtbox = new array();* \8 v* `; z6 s1 k1 O
var arrlookup = new array();
5 O3 G4 Y# q+ W2 ?var i;
% A# V' e% Q" r+ \  ?3 m& ^9 h# rfor (i = 0; i < tbox.options.length; i++) {( f0 J+ k+ |6 O6 W4 v- ~
arrlookup[tbox.options.text] = tbox.options.value;' Z1 j" q: t7 x- X
arrtbox = tbox.options.text;2 U  t, p. f+ J% X/ l+ }+ V5 c
}' n: ~8 O) @4 e2 R3 T
var flength = 0;* C$ b, h! C9 ^  B2 P
var tlength = arrtbox.length;
; x7 P, E5 T$ `4 Ifor(i = 0; i < fbox.options.length; i++) {
, b( _4 b; W5 a7 y$ m8 F6 T( ?4 Darrlookup[fbox.options.text] = fbox.options.value;
0 r9 V; \3 w' \! B- K: o$ W2 [if (fbox.options.selected && fbox.options.value != "") {4 J& x" ^) }/ B* C
arrtbox[tlength] = fbox.options.text;
/ `' ^- G8 j4 q6 g- }5 W0 I- r7 Ltlength++;* B2 e9 m2 g: }2 j6 W- i$ Y
}& V, c8 {. G0 P
else {% K3 r6 Q/ U$ l4 W" J/ `* x
arrfbox[flength] = fbox.options.text;
$ m# L8 d5 ?( I* Nflength++;
# n- S8 A% B  e   }) z, j  b* r/ b. F8 I4 M, L6 j
}- p* Q7 N7 E$ u& ?- |
arrfbox.sort();3 P2 a- ~+ m& H& D4 D
arrtbox.sort();
5 ^0 I3 U" h3 F# k* y4 g/ |
9 B* ~1 G3 R7 D* Z7 mfbox.length = 0;# i' M& V2 ~; t% R  r7 ^* Z& r
tbox.length = 0;
, n3 c  O8 _3 x' M9 A6 zvar c;5 X; H/ `3 t8 a9 w% C
for(c = 0; c < arrfbox.length; c++) {! M* A: s" F3 q3 v: `: g* O
var no = new option();
4 K' v8 w) Z9 `/ l, B! }no.value = arrlookup[arrfbox[c]];6 U4 [% {" A9 ^' ^6 `
no.text = arrfbox[c];
2 p- r( v/ f+ e! U4 d4 Pfbox[c] = no;
% ?: {+ Y3 u8 v5 L6 _}
5 H) h: q9 A' d' Z9 \8 H' yfor(c = 0; c < arrtbox.length; c++) {
2 M* Q8 x# U- P+ f+ p+ zvar no = new option();
" r+ W. j2 t+ j4 _# L+ pno.value = arrlookup[arrtbox[c]];1 y* c7 l, z9 p) X
no.text = arrtbox[c];
* C3 x5 o. |* J+ x2 M9 ntbox[c] = no;! p5 u  k1 a- z% j7 m
   }4 G( F' \, Y. D* ^+ d
}: F' R# u& W# ?2 ~" d; t& [
</script># T7 f! K* E0 `8 K- }" k
</body>7 p7 N9 D& Y# l( ?. P7 D

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