返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"! x+ M; A/ @* s6 c* t
         c pageencoding="gb2312"5 n* `' G) j, f6 o, r% r
%>
" |& l" Y7 Y* z  K<style>  c' i$ V" \, P% G+ h: N
.f9{ font-size:9pt; }
. M- s; l) C: D, @2 n( R. ?.bgc{ background-color:#aecaf9; color: #0033ff }
6 Y6 i. K; d1 B5 Q: L: ?0 D/ v.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;) m% C% T  d5 _* }
  border-bottom: solid 1px #4e7dc1;
" ]3 p( O6 Q8 y  border-left: solid 1px #aecaf9;
1 M2 s" D+ ?" I, ]' L: W" a+ b  border-right: solid 1px #5679bd;" Y9 L  B- U) j" |# G, V
  padding:1px;
$ ?4 z0 ^. l% H1 _- Z# R% k  margin:0px;}# v# J4 z3 {+ A0 R
</style>
( V% C3 E6 E9 o! j" r<script language="javascript">' I$ z% T) V4 L2 |: P8 {' Z. _
<!--
5 B/ S3 P* s% K! X; T* D8 k  E/ ifunction rv()5 D+ Y, k! Q/ c" Y3 m6 r% x! R5 [
{1 I  `% \1 v, ^7 q' S
  var val="";
9 U! |2 n) C8 V- q9 z; G% f! ]0 `+ V  for(i=0;i<combo_box.list2.length;i++){' ~: e" h- ?8 d7 z* C
   val+=","+combo_box.list2.value;
$ K% Z! I7 ?9 R! N, M  }% d. _" P: M0 b8 d: C
  if(val.charat(0)==","){
# }% d" M! s# H" M   val=val.substr(1,val.length);; K. `1 p# r1 d5 a- @1 A* x9 b
  }
3 }) T; m) Z) ~$ z% r3 P  h  opener.form1.frecname.value=val;
) H) y3 ]6 i. |3 S; k* a  self.close();
7 E! H! }+ U  {( T0 x}
. j) Q$ L/ s$ w+ I//-->* [" U: e1 E5 S$ F  p* i$ N
</script>5 _& @$ C3 x% w
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
9 z1 o8 E. f; J- n<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />5 t+ J' t  b' A: I# F6 L9 _  q
<%
, O1 k0 c& @& ~# o  cdatasource ds=new cdatasource();  //数据联结bean实例7 ~( O" g* P  i* b
  java.sql.connection conn=ds.getconnection();
- [( u/ p$ Q4 e3 I3 _  java.sql.statement stmt=null;6 `( e0 ?& v- i! _6 Y9 @# q
  java.sql.resultset rs=null;) W1 @0 G, K4 }' p1 r3 N
  cdatacheck dc=new cdatacheck();; y$ p, x9 U6 X' `: _: h0 f
%>8 {* Y6 a. C0 R% ~1 q
<%
% j5 A: l0 H& m4 `" E- }4 h# ostring 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";1 ]! _. V+ z/ R: Z
stmt=conn.createstatement();9 t& F( i- ^- [1 G5 c3 b
rs=stmt.executequery(sqlu);
) m- u1 c# {7 x- F0 |+ Q* Q%>& t# z" J2 `4 x
<script language='javascript'>0 ^$ E9 U7 F9 o5 Z8 s$ R) ?
arr = new array();2 R* ~8 h) j; W1 X( L
<%  int temp=0;4 P9 P1 r7 n3 f& w" L! j$ S( P4 m5 h
while(rs.next())
0 S  Q5 f- X2 p- e- b" l7 k7 C' D2 Z{
) N2 y  z4 V# N" U( S5 d%>  I2 R( k" _$ c
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
  X; q& E0 `$ y& _: C2 B<%
% ~! N' j5 R8 s& rtemp = temp + 1;
* P8 P( G1 X2 \9 p}) F2 R6 V) ?- P0 f+ o; I6 E
%>
3 g( T/ K4 h5 G) Htemp=<%=temp%>;. o5 X+ C0 k8 W5 [, X* b4 u' Z1 h
function changelocation(id){ & X+ L" o* z: c4 a, }! F
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
, N' C! s, ~( z, N9 \var i = 0;
4 a8 Z) w. _# Qdocument.combo_box.city.options[0]=new option('-------','');
. J9 t5 V2 M' z% Z7 ]. o9 K+ Tfor(i=0;i<temp;i++){
0 B7 i- j) J- s" oif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 6 e  R5 j+ G$ Q' T& \
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
% f& o* H  I. H, n}
8 f  p5 j8 h. a1 d3 W/ ]}
0 Y9 L. o: v+ p4 e7 r: K8 ]; F} ! m& ?" i" L2 M
</script>
3 @* d- r7 y/ ]
8 x/ ]/ a) T% Y<form name="combo_box">* n# o$ G; Q4 }9 v
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
8 ]; g3 h! u( ?- H" T  <tr height="24">
0 m1 j1 L! {4 I' P    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>  j5 u$ @+ e7 b* D! Y, e
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
7 H" w) H9 a/ P7 v" q1 L1 ~1 L    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>% k4 A% j* }4 X0 [
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
2 }! D* D  A; S- C5 ^  </tr>
; ]' x: |# Q) B7 z3 _, c$ `+ w  <tr> 1 c" _  H$ {" E* @) ~8 B' O- m
    <td>
5 u! `! Q% j+ u: X; P; h2 A  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
" }3 m+ ]! ^+ u' s+ a8 E$ s3 i  <option value="0">请选择部门 ---></option>
. ]5 T6 C( M' z+ x* Z  {<%1 c9 \, \% v7 [
    string sqld="select * from tdept";
* O) U& ~3 p) c$ ^+ C: Tstmt=conn.createstatement();
; M' d# r) P; |, prs=stmt.executequery(sqld);- W7 |9 A$ p7 K# j9 `; d
while(rs.next())
. v) `& t6 T; m$ y: a{' M0 s! \! r) F3 ~( D! [
%>
) q3 i! Q# \9 D5 P4 g3 n  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
4 ?8 n. r, D! _, Q6 I5 ~<%
5 V9 _' ]" l( s0 U4 g, u}
' w& `8 @/ ?/ \& z. @%> 5 J+ i5 v$ t! D+ \
  </select>/ v; j* l- O, P: w  E4 J& j0 i" N
</td>
1 T  y9 k; X; f' T: d0 ?    <td>
: [! X; X  h% S  <select multiple id=city style="width:150;height:200" class="bgc">
3 n' Z7 u- Q8 ]3 q  </select>
. n# }( k  t, Z: K</td>
9 U5 g2 [# ]6 p# w% O" ?    <td nowrap align="center" class="bgc">2 l% Z& u! x2 p, y9 j
  <input type="button"  value="<<" class="buttons">$ a9 J* \6 u& N# b. ?) B
  <input type="button"  value=">>" class="buttons">" }& L: M8 [- q- x. \
</td>
& C/ F( `6 W" w) g    <td>2 {2 p( j8 n' H/ ^7 l
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
; v% i* Q0 b, h  </select>
: ]2 D" J3 h3 q' U! C/ ]7 S8 \/ I</td>9 u! C9 x. Z9 d9 A) O$ K! T1 l1 m
  </tr>
9 U8 i/ \2 Y/ O7 k; n3 f/ a' [    <tr class="bgc">
' k2 E4 q# A0 i7 V    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
  f3 q& ~* u5 K9 I  </tr>
0 o) |3 p$ A. b0 }$ L% k$ h</table>
/ k: q, X( z9 m0 d/ ]: }</form>
2 a( O6 E* v' t+ S; h# k<script language="javascript">
) g; X# c4 Y, {: }: `% }/ n  Q//人名移动1 U6 {$ U# _& i# d' s7 J
function move(fbox, tbox) {
, v. Z; ]! c! q2 E  l6 o$ W* ]8 s/ Hvar arrfbox = new array();
6 m; s/ {" ]$ y1 Pvar arrtbox = new array();
& z) M; i4 i4 `; I1 o* d5 P8 yvar arrlookup = new array();
4 @: P8 S) c* x4 ^5 @var i;
, a: k! e" F* Bfor (i = 0; i < tbox.options.length; i++) {+ a& T1 p5 \5 l, y, [& a5 ~  m
arrlookup[tbox.options.text] = tbox.options.value;
5 z6 |) b; Q& ?! h, L# U4 a5 _arrtbox = tbox.options.text;* O$ o2 d) d9 U  _3 Y0 ~( R# e) y
}" Z! @6 G) m# N" a
var flength = 0;
' x- V; q" }; B4 B6 D+ s" ?9 Xvar tlength = arrtbox.length;
1 f9 f- U: |: ~0 {for(i = 0; i < fbox.options.length; i++) {) {0 Z  i3 n- K
arrlookup[fbox.options.text] = fbox.options.value;
7 m5 s2 @  h) \# uif (fbox.options.selected && fbox.options.value != "") {' b- X! S4 s! I) d2 g0 K1 m
arrtbox[tlength] = fbox.options.text;
: ~( m- W. Q' Z" O, Ntlength++;4 |; N" k' ?/ H5 ~  i$ I2 M' v5 f
}
& r7 M: o  e9 L. t; x' Xelse {
6 Z7 v! ^0 k' ?" harrfbox[flength] = fbox.options.text;
% v9 o- v2 _! fflength++;
# Y4 M% `2 U. J3 b* @   }
9 d9 l" C  G+ s: h3 D6 ?}
+ T* B  s' f& Y, g4 M; qarrfbox.sort();
  t$ u# T( w3 e4 B. a4 Garrtbox.sort();
* Y) e. X8 h9 H+ V# X: P6 Q) R& s0 s1 @  D, H3 c. s! N, J
fbox.length = 0;. ^) O; d; ?* N0 _& \
tbox.length = 0;
( Y( L: F. Q3 N" w/ o1 qvar c;! v! N- _. E% z" S$ Q
for(c = 0; c < arrfbox.length; c++) {
) {  e- \9 n6 @4 Xvar no = new option();! |0 G. m- F2 |: A
no.value = arrlookup[arrfbox[c]];( W  H$ L' s4 W- z' P% y
no.text = arrfbox[c];; Y4 R  i+ H9 k" \, f
fbox[c] = no;
$ C+ y. c1 O8 c  y4 Y* r3 J}
8 Y9 L  c) \$ ~2 W$ ?for(c = 0; c < arrtbox.length; c++) {
. t9 `4 ?% G/ `1 M5 H& i0 h- yvar no = new option();
- j7 }, z& n8 N! t; [6 [no.value = arrlookup[arrtbox[c]];
1 }7 ~- y! g6 R2 T1 qno.text = arrtbox[c];/ B- N: f# P- C0 c8 \% p9 e' t
tbox[c] = no;( j* S1 U1 [2 r  E
   }$ l& d. G  R) O) n
}7 P: b$ \* X' w) \7 ~
</script>
% w8 Z& d: E& V9 f</body>2 f  C5 Z, ^2 b0 x

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