返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"0 W( K- M1 F  A2 o& |. g
         c pageencoding="gb2312"4 h9 d; |' G' I, \
%>" C; w, b4 F; V- {" l( u2 H( t
<style>
+ Z0 h9 `1 Y1 g& E* y% R; N$ E9 A.f9{ font-size:9pt; }! H4 a9 n; }- D- d2 ^+ Z0 r
.bgc{ background-color:#aecaf9; color: #0033ff }
( P# {6 B8 L5 [% J% j+ R* S5 @" `! ~/ Z.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;3 }+ ^  t$ L% m9 F0 C0 ^
  border-bottom: solid 1px #4e7dc1;
4 P$ ~2 g$ ~1 j2 J( v  border-left: solid 1px #aecaf9;+ f+ U7 C0 p# ?/ `. S( u
  border-right: solid 1px #5679bd;! Z  _+ V- ?# W  p! W
  padding:1px;3 K  Y" Q2 u/ V( s! Q& f: c! {  R
  margin:0px;}
1 t7 @' c6 w: q1 V- i</style>3 n: J0 y7 ]# @6 C$ x0 Z" U
<script language="javascript">
' J& c" T: Q3 j$ O9 P<!--5 a+ J7 x5 C* G% l6 w' v
function rv()' W# e+ e- q+ q, G
{
7 R. ]& n" S+ \; L, g7 A  var val="";
* E6 H' Z6 w( N; ~3 ^0 D4 y  for(i=0;i<combo_box.list2.length;i++){
. Y3 F( u* D# T+ s9 a2 |9 x   val+=","+combo_box.list2.value;  J" v: M" B2 j5 a6 Q
  }+ [& d9 s! v3 a
  if(val.charat(0)==","){) b' Z( w! z1 L
   val=val.substr(1,val.length);/ U+ ^$ Z, w( u2 S  j1 j5 w5 p
  }
, s0 R1 _- O4 j8 i% `: a  opener.form1.frecname.value=val;
1 t7 \' w4 k# M- U; r4 J- S  self.close();5 B6 \5 x' c) Z% v7 N8 V1 |2 ]
}% }0 n: `. i! ~5 P# c0 h
//-->
! ?  m( ?5 u: B</script>5 ^9 m; L% Z0 J/ o' I
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
: }& t/ m( c. B% x, N, U<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />. ]2 z+ ^4 B! ^, U! O3 x- {  _
<%9 F7 c4 G- j  h( c& |
  cdatasource ds=new cdatasource();  //数据联结bean实例8 ~; _0 G; s: h4 B! S0 Z0 B/ |
  java.sql.connection conn=ds.getconnection();# E* [/ i6 @) N' |! U
  java.sql.statement stmt=null;2 ?3 I5 }9 m' ?3 ?$ Y' x! L
  java.sql.resultset rs=null;
4 |8 Y9 Z; P7 `0 s8 t% U- }  h8 n  cdatacheck dc=new cdatacheck();
6 T, ]' W0 u. g: @%>
( g+ _. N- |. B# x4 w8 D' f<%2 A2 u% |: e9 K- p
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";
( Q, T  ]! L# y0 }* x% kstmt=conn.createstatement();% g% ?: U, Z. }: x& f: m) y
rs=stmt.executequery(sqlu);
" @: H9 s$ X# a3 n# h%>
" f* m( q  I8 b# p+ H4 v% o& H<script language='javascript'>" [$ v/ p0 e- k5 N: ^( k
arr = new array();% S" t. g, {: E8 n+ {/ g
<%  int temp=0;0 g, Q3 a5 e* p9 ~& p" @5 g6 \
while(rs.next())
/ N, n! c5 D+ b; d" B{
5 B8 J. G% i% F: S. E1 |$ g- q%>1 F$ q! m2 h2 U! M! ~
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
- l6 ]3 _" f$ t4 h( }. l6 k<%
) J' Z9 s$ D" D! stemp = temp + 1;1 {& U4 m$ \0 q; T' G
}
" l% @  w+ K  v%>
% t+ h2 M6 b2 X% btemp=<%=temp%>;
2 K7 P" s7 [/ {) ]! ?4 x& Rfunction changelocation(id){ : v1 d3 C  Y9 S: G% A! P: I3 z4 y
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
, H1 S+ o& `* d9 x( Ovar i = 0; # j  D2 \( h/ D7 d% p  `
document.combo_box.city.options[0]=new option('-------',''); + @; G3 M7 W& L) y8 X
for(i=0;i<temp;i++){ , f! M' }( L8 u; _; A
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
0 X5 O2 N" G& v7 [document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
5 u- ~. A, i) t} 5 O2 L( p! d! S1 j. Y$ @0 ?
} ( S. ~( q  f: b- y' V' M
}
& H# V: h% B# a: `' b% i</script>6 x/ Y. L3 d9 M2 `2 m% }1 q5 M! k
& z$ l3 N0 e! c+ Y9 V9 T- E
<form name="combo_box">8 d: M+ v' Z" u
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">9 c$ }  v, j( ]( E9 v' m* I
  <tr height="24">; c( W6 B- Q) \% o' B2 y; m
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
+ V4 f3 F- ], p0 z5 p; ], s5 `% S6 j    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
' h$ N9 B5 x# _9 m$ K/ B- g4 d5 j6 c    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
2 }8 K0 W- F3 C2 W% S    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
) R2 @  J( Q' F8 l. C' Z2 Y; H  </tr>
( e$ `5 N7 O8 E0 X1 J$ `  <tr>
# |% }- l' ~! `5 s# w    <td>4 [( w9 b; w: F1 ~; ]( H0 u
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
" U* I0 s& o1 `* Q; `3 g# {: {  <option value="0">请选择部门 ---></option>0 |( D4 S* U4 r1 c% @" o2 D1 q
<%- f: I; h! c/ H& T# q
    string sqld="select * from tdept";0 h5 b' f: s/ V& e
stmt=conn.createstatement();
+ g9 \3 N- x! O# t( M4 _rs=stmt.executequery(sqld);$ P  D5 L6 |" {& X2 z
while(rs.next())
* @! m' J) g6 a/ s( H{
2 w% M; c- ~3 Q& W0 Z%>1 e/ a( B, x+ R2 e& b8 V  _
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
9 b& F9 t" \& b( U<%% r3 f1 P5 V0 v
}0 I" P1 C+ ?/ V: Z
%>
! y/ ^# W. d6 _5 f/ o  </select>& f& f0 u/ n3 `3 M0 ]
</td>
+ b" J& @9 p0 Y) ^' k9 o    <td>- l6 N9 E$ J4 B. x0 |. }* R& I. |
  <select multiple id=city style="width:150;height:200" class="bgc">
0 t1 H! Y: _4 p# ^2 t& B4 n3 N  </select>  C/ b! t' F- G7 S, @9 ^
</td>
5 K5 o: b* L+ S0 _    <td nowrap align="center" class="bgc">5 \& Z3 a6 i7 f2 e  b. x- L
  <input type="button"  value="<<" class="buttons">
# J! u) s. p2 i; ?8 H: n5 w9 g" k' F  <input type="button"  value=">>" class="buttons">
" j. B* P( y% y! V3 N. [1 u</td>
( j- U/ c; ]  {! C& ~% _    <td>( ?. M8 t6 L) p9 h$ x$ O
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">( j9 ~7 q& `# A1 C9 o
  </select>& @; G+ c/ x, s/ j" b
</td>
3 M( @( h7 _9 I" r: Q  </tr>
+ z5 u- O4 X3 f0 h2 m    <tr class="bgc"> - r5 j# b! F: a0 @9 I+ Q: Z3 d$ }
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>2 _2 ^. C' P) Q' j
  </tr>$ p- X* a) o! o" o
</table>
' Q/ @$ k9 ^  m</form>
; o8 O, U! h5 j. x6 ]( p% F<script language="javascript">  b. D& j8 l' j) p6 r9 I
//人名移动) J9 h: E7 y# [$ S7 A
function move(fbox, tbox) {) j# o: x! `# K7 B6 _9 `
var arrfbox = new array();
+ g& d, y3 m! A' f! B) I7 ?) n% ?var arrtbox = new array();
! Z; M. \, g, M' H. Y0 \# Cvar arrlookup = new array();
. Z7 P& o4 r& \var i;
' T- g0 X& d' u  v, K6 Ofor (i = 0; i < tbox.options.length; i++) {& `( Z4 a7 R4 |, S9 y$ e
arrlookup[tbox.options.text] = tbox.options.value;
- o. I6 c) n% ~& D! ^0 i2 O% }2 `arrtbox = tbox.options.text;
/ z+ X8 g+ b# Z* w9 W}5 a2 d( u8 D  \% w( F. b/ ^
var flength = 0;1 D. g5 @/ ^. A1 [! W
var tlength = arrtbox.length;) W" g1 {: v9 |* W/ e& e
for(i = 0; i < fbox.options.length; i++) {, q! M% J8 {* M) q
arrlookup[fbox.options.text] = fbox.options.value;
# v3 k2 A; ~& H/ _. l5 {' d$ mif (fbox.options.selected && fbox.options.value != "") {+ q6 ?! E. l* l; B1 M
arrtbox[tlength] = fbox.options.text;+ n8 o& E4 A# ?
tlength++;0 T5 h& D# w& a8 `6 O3 |+ |; L& b
}! M- j) B) u1 [2 U9 Y
else {
7 C$ s& k) e5 T( V& w+ J5 f- earrfbox[flength] = fbox.options.text;
, ~# [5 O' H6 B1 r. a6 oflength++;7 Z. [9 I! l) d; u
   }
8 {! y( Y! N; R* N}6 j6 s" |1 x5 u+ S7 L- ?3 j; @
arrfbox.sort();
# b: f( G- B: ]/ w. \$ x! _arrtbox.sort();
0 x; Y  |; p4 r" J; x6 ?. C3 w; p1 n# Y6 Y/ c# ?' b
fbox.length = 0;
" X5 n% Z1 h& L0 ltbox.length = 0;
9 ^0 o! a! Y4 X. [var c;
: C5 d. r$ l( `* T' n0 h$ xfor(c = 0; c < arrfbox.length; c++) {+ K8 U- a4 X7 K& h* n) r
var no = new option();
1 _5 W! n4 {1 Z+ Vno.value = arrlookup[arrfbox[c]];, I0 B8 W* i+ u0 c" U8 ]
no.text = arrfbox[c];( q5 [! _# X; c
fbox[c] = no;
: f7 ^$ ]5 q2 q8 w+ u: n2 \}
' ^/ ~- X- P4 p# Lfor(c = 0; c < arrtbox.length; c++) {
- g$ ~' r  B0 S+ ^  Pvar no = new option();
- W8 _4 o$ ~) i9 V6 Cno.value = arrlookup[arrtbox[c]];! d6 E! ]( b% N% d
no.text = arrtbox[c];
2 M  ?1 W& o$ n2 c2 _7 gtbox[c] = no;; @' L& t0 M) O0 M$ d3 s
   }
9 l3 y6 ~. ^0 a# T$ r+ `}8 x/ g9 ~: ~5 v, [  G7 \  o
</script>
& Z( X" a2 {! j; h4 ^" W3 o</body># F9 v# g* i* F- h0 r' r

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