获得本站免费赞助空间请点这里
返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"/ S: `! G7 m$ c- L" X% i
         c pageencoding="gb2312", d6 O! z  K" c4 V1 E. h' r
%># W# @; [/ k9 q+ p! k# _4 a
<style>
; t7 z$ W2 R' g: w1 {& [' g.f9{ font-size:9pt; }
7 E; S7 o# ?0 Y9 x4 W.bgc{ background-color:#aecaf9; color: #0033ff }
9 q+ U4 C$ {& }- q2 \1 A.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;7 C0 ]: K8 E" I, N
  border-bottom: solid 1px #4e7dc1;
5 e& F9 N6 k6 L6 ?  border-left: solid 1px #aecaf9;/ f( J2 _) [0 A7 i* ]) U  U
  border-right: solid 1px #5679bd;
# ]' q1 A1 ~" e6 D; ^; A/ f  padding:1px;" w: V$ y8 n9 v. r! W# P8 T1 d
  margin:0px;}; @6 e- V- t5 v6 }* q; o. d
</style>
& T3 Z0 H' x& J<script language="javascript">
1 U& \3 g* t" n3 Y$ J2 z! p* g<!--
; |# q# k1 Z( _' Rfunction rv()6 a- f& j7 R" P& G0 \, R' M
{/ B7 |- {& w1 H+ ~, u9 \4 V6 }
  var val="";
: J+ h7 F$ a4 j  for(i=0;i<combo_box.list2.length;i++){6 E& F9 i! q. `9 N6 o! u
   val+=","+combo_box.list2.value;6 t' D7 H( l" q5 L7 A
  }
. U, w. q7 D# N# Q9 t5 Z5 H  if(val.charat(0)==","){
* s8 R# X* w3 c+ T   val=val.substr(1,val.length);
1 l4 Y( z: a2 R1 I  }0 I  q! s9 m, m8 F
  opener.form1.frecname.value=val;- e; e$ H: U- R
  self.close();+ ?: K' s( U: z2 t
}
# s- O) s  j5 D. F$ p//-->. R* z" k2 }: V/ T
</script>8 `! R$ r. g" }0 I/ `9 ]4 D5 I
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">) R5 n1 Z- r" k4 y$ e
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />. r  H- }# O- k8 f" O6 G3 L8 ]
<%
% J. _' A4 T) D9 X. K, s  cdatasource ds=new cdatasource();  //数据联结bean实例, D, P2 k' r% ^9 P3 h: Q% k" c
  java.sql.connection conn=ds.getconnection();& U0 S4 c; e2 E* e$ ~4 l
  java.sql.statement stmt=null;5 k- S% y6 |" I3 ^) ?+ C' V
  java.sql.resultset rs=null;
* g# L0 n& c# q* O: B  cdatacheck dc=new cdatacheck();9 o7 Q- d. @( H* `0 j& r' n1 M2 \3 {
%>
6 R$ U. z7 f7 t; x/ k<%+ [$ d- ^! ]' f) v
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";# ?8 `0 X+ I, {9 k9 N/ x2 C. k
stmt=conn.createstatement();
. D# {/ K1 e: y9 S8 K' e" E+ W, O4 urs=stmt.executequery(sqlu);- b$ N' U4 |' Y7 j/ R1 p
%>
  `# t% X. D* t4 s  L' r<script language='javascript'>' {9 M8 y/ a' D$ N
arr = new array();) R5 H7 h! X1 Z7 L- s" ~
<%  int temp=0;
8 l) {- h* O2 O( [while(rs.next()); J2 A8 o/ _% p& ?* ?
{* \5 }# O/ V8 s! V6 l# [
%>
1 o" \) h* D% G8 k" _2 I1 f/ x! Larr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
; x* c5 Z2 @$ e9 C3 ~<%
9 F, r7 s" c" g) t$ {( l6 Z9 b. Atemp = temp + 1;# i9 R  E4 C' X: u# X) ^5 @
}0 g2 V1 S: _  c/ Q
%>
4 h6 @2 c1 p' I/ `+ J0 ltemp=<%=temp%>;- m4 I- \  N& |6 v9 b
function changelocation(id){
; {+ [; r. z6 p1 W) B+ Idocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
) f" @* y! C8 _; @9 w% |var i = 0;
3 Q2 z  y8 u6 n; t$ C9 M$ sdocument.combo_box.city.options[0]=new option('-------',''); / u! c, I) y2 Y# a$ t' u2 ^
for(i=0;i<temp;i++){
; y9 Y. N$ T# |; J' ^* B3 d7 K/ \- W" sif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] * F: r, Y) o. b6 W& y, X
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); " Z: }# A; M6 H0 ~% I6 t$ f
} ' Y# U  t5 z6 |# }( |5 C) L* @2 O
}
/ p" s, U( M; k! }; F6 ?} ; p. x  R" G, Q! A
</script>
; J  t. N. W! ^2 O5 ~" [0 ]0 x6 v& _
& n9 @: f' i/ Z4 E/ x" ^<form name="combo_box">
( w3 S1 b) }0 i# s<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
6 |" j" F0 g8 a, z- ^1 f0 R  <tr height="24">
* b) `( }% u: C% B- B7 F2 O    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
$ P% v6 n' i, @    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
7 m1 L; q, B/ O* n( ~  i    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
& M4 h/ b* v# W" \    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>7 P, ^2 j- A: S3 e9 j; T' j) _
  </tr>" ]2 S- A9 J2 f; o2 h" |
  <tr> , @( D7 m3 B) l: P/ u$ ^
    <td>
6 s9 c7 u  q8 X  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
4 ]# O0 l1 n, s4 O( }/ @* V  <option value="0">请选择部门 ---></option>
( S' J# _# e* v( L<%
! F& }. I6 E0 X  q7 U) B    string sqld="select * from tdept";
" L& Q1 {1 z; q, ?+ K9 e) w! cstmt=conn.createstatement();
! i9 c" R! V0 s  qrs=stmt.executequery(sqld);& N5 c- {+ `$ h3 F8 K. b
while(rs.next())
. o- b. Z2 B! H3 f{2 J" J4 }7 j8 l5 y" m# {. ^
%>
- W! d: e( R- G; E6 w. n3 j5 D6 l& Q/ J6 m  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
. K! F4 X. O% ?/ x6 i9 D<%
9 K! j$ c2 X1 j2 ?2 g2 B$ j, j6 r) C}- d/ G4 I! R: f( h! D4 h
%> : F3 I9 [  P$ S( G  [& U
  </select>
  i# d5 A: w/ W( E</td>) W4 s9 J$ N/ Z9 k; v) z2 v
    <td>4 F! W5 j8 d2 b* i+ @5 L( U
  <select multiple id=city style="width:150;height:200" class="bgc">
% ]6 J. D( s3 I  </select>
& O3 \) e& B( U</td>) E& d2 P" Q5 x1 \9 }5 I& P  Z$ b
    <td nowrap align="center" class="bgc">
7 u' C+ n9 b9 j) O8 \8 _" K  <input type="button"  value="<<" class="buttons">
* s7 S" Q  F) h5 Z& J5 ^+ M4 n  <input type="button"  value=">>" class="buttons">/ L; _, h2 h' i+ `  C: f# B
</td>
2 }$ ?- @6 J5 s& R( G    <td>3 c- u- N) x) W8 E
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
% d( H1 _( l' ~0 ]8 i  </select>7 W$ I$ y! D5 `+ z, B
</td>
  D* `2 O0 Q0 x9 P/ F  </tr>
# E8 O# ]! @; j1 P: W2 O( G    <tr class="bgc"> ! ?& u9 g: y+ Q
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>0 P' O7 c4 C- }3 B3 i5 v: d/ V; a
  </tr>; a- I+ Z8 N1 V" }
</table>" [" j& C3 _/ d1 N- j% O/ [
</form>
& w3 f( U& a5 v7 |+ j+ n: B/ S<script language="javascript">7 D  F/ ?) ^  l4 e4 D+ i4 _6 K9 U
//人名移动6 `) l% N+ r# v. g
function move(fbox, tbox) {
# R8 f3 Y& K# C) E  I3 Ovar arrfbox = new array();
. I& V. n/ K4 X/ Nvar arrtbox = new array();) ?& t3 x0 K7 F0 e9 W" W, w
var arrlookup = new array();0 A& n: _4 T3 A7 f
var i;
, d  v' K7 g4 j/ j5 U& r7 bfor (i = 0; i < tbox.options.length; i++) {: W4 Y9 x4 ]2 p6 i  A7 ?( F
arrlookup[tbox.options.text] = tbox.options.value;4 X' J6 A  U; A+ `  {# O9 h9 N
arrtbox = tbox.options.text;. u* G* p2 ~7 _" c4 q3 m3 Z
}
$ z, o7 U6 [+ ]) ?var flength = 0;8 e& M; ^3 s/ M8 l! Q4 k
var tlength = arrtbox.length;8 y2 v  Z* F8 e8 J' e8 g; b8 L  Z' a
for(i = 0; i < fbox.options.length; i++) {
/ x& b8 W& @) l* E0 narrlookup[fbox.options.text] = fbox.options.value;
1 ^" g+ z7 X8 `+ |5 Y  Cif (fbox.options.selected && fbox.options.value != "") {
" U! z2 V2 Q& m* Aarrtbox[tlength] = fbox.options.text;
% O* g" U! V* }( _) R2 Ttlength++;- H3 k9 r$ C9 E7 P* U* j, t0 q! `
}
& r/ `7 ]1 c! u: v3 b) relse {
6 N  m+ _& \8 r# e8 s4 k$ M4 Iarrfbox[flength] = fbox.options.text;$ B2 ^/ v* u) J7 I" H) j
flength++;$ e& U) p( U! s$ {/ _
   }
' p3 Y: `" v4 D9 k* ]! |2 F7 U+ y}
& J% t* p$ i5 d& D% w$ uarrfbox.sort();% A5 ]" H* H- f2 U8 H2 `; k+ G8 ~
arrtbox.sort();) ~1 L/ i* r! ?. v0 u

3 I" {# p& O. hfbox.length = 0;( ~$ K) p  H! [9 k. p
tbox.length = 0;
; V' ]; h$ f- V, H$ ~7 Svar c;2 L1 f2 x4 \7 V* Q
for(c = 0; c < arrfbox.length; c++) {% l+ R6 C4 m( g+ M$ o  e! M! H0 ~
var no = new option();  V* ]& w! N+ @" o% S% u  J, Z
no.value = arrlookup[arrfbox[c]];
. s+ e' U& v7 ]no.text = arrfbox[c];4 }# ?) @+ r/ c3 E. y
fbox[c] = no;
  ^% y4 T8 L- z7 D: m, Y8 x# Q; p}; i& J& L" l4 a9 F- v
for(c = 0; c < arrtbox.length; c++) {; J9 }6 S" u. \) j7 |. D: G
var no = new option();
$ d8 [0 C* M" Z9 c! H* M* F- Jno.value = arrlookup[arrtbox[c]];
' X  {8 [. L$ }( Mno.text = arrtbox[c];
8 C! x, Q0 J0 otbox[c] = no;
% L5 W: w% e. A+ m2 V   }& q" I0 G0 C5 s" m+ B; i4 E. e
}
+ \, Y7 p. [# L& ?  q</script>
. s9 U. t+ C( R1 ^$ R</body>* z! q: D& F& ^: b/ A# [7 O4 n

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