返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"7 O+ e# R; ^' ?- M# B
         c pageencoding="gb2312"( M8 {+ y: T% Z$ z' f
%>
! H/ I7 A- e  F7 w' R# l' V<style>
! o' |* Z- z' z  x3 I.f9{ font-size:9pt; }
& J8 k8 R! }/ ~2 g; t2 i) {.bgc{ background-color:#aecaf9; color: #0033ff }
( x4 @- F' G% y% x.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;  L: q" `) ^' c+ Z3 i0 B) }; Y
  border-bottom: solid 1px #4e7dc1;; D* c2 H, x' X  [
  border-left: solid 1px #aecaf9;+ Z# S/ o7 s' Z8 u
  border-right: solid 1px #5679bd;
6 z5 A+ v1 t5 W2 y  padding:1px;* E7 o- F& O5 F8 R% p& k: T( ]
  margin:0px;}8 [( ?. S2 `7 G
</style>9 I  {5 f* ^; F: c% d
<script language="javascript">
- O9 Q: M  A# R' z<!--# H/ g+ `" k% X3 i; q$ Z. H
function rv(); p6 N7 x0 q( [, t2 d
{$ W; @2 L, l4 r7 L+ U; l# u" D
  var val="";2 g( Z4 {+ ]+ R4 l' R1 m& W
  for(i=0;i<combo_box.list2.length;i++){
2 s8 t( s; {/ h   val+=","+combo_box.list2.value;! e2 w. g+ a. O$ V
  }3 x, O5 a5 F/ N# g/ ?/ ]
  if(val.charat(0)==","){# s! P& G" z& Z, i! G7 X
   val=val.substr(1,val.length);
; G# @% ^9 T. g5 O  }
7 T  f- w+ ?9 I' i9 n) m  opener.form1.frecname.value=val;* `, V/ b) U5 I. P8 n. C+ c3 h$ E, J
  self.close();
& N2 n, t8 \0 L' I% r1 c& q' u}
9 J3 u# w$ {; Z/ o//-->, D+ x0 ^4 @! i: H2 m
</script>
0 f/ U% [4 G% d+ l* x<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">0 m+ X. i3 o. E6 }% l9 B% ]
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
; x* G" W( J" W6 p& L<%# J7 f4 I' J: B& ?& r2 ^' T
  cdatasource ds=new cdatasource();  //数据联结bean实例6 H$ f3 d3 v( g
  java.sql.connection conn=ds.getconnection();" H7 |5 v/ O5 ]
  java.sql.statement stmt=null;) Y, A- h' F$ s7 f: F
  java.sql.resultset rs=null;* A5 G6 L# l2 M( V/ [" U" _1 V0 _
  cdatacheck dc=new cdatacheck();
+ ~5 [1 `4 n" H7 R%>% r, @' s, N' K6 B: }# t
<%  y4 u9 w! e, J, u
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";
! |9 |! ?: u/ [) ?stmt=conn.createstatement();6 q. k# J3 f# h% V: B! s  }
rs=stmt.executequery(sqlu);
  B# e. g; b( c7 o3 E% ^%>
3 ~$ `& L3 Q( p& t" e<script language='javascript'>- f! ?4 u9 u7 [3 _$ a$ g
arr = new array();4 |( P' ]9 |3 Y$ K' g) V
<%  int temp=0;9 S7 s/ H' |/ t' I! u
while(rs.next())# s! d5 Y% o% J$ r' v
{# N; H9 A6 `7 I; t
%>( ~- `) u) B0 _0 N# l( P3 x
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");& H; x  W2 O& S$ z8 ~6 ^
<%( ?4 G, c* X) c% q/ m4 H
temp = temp + 1;; c8 ^0 l9 r2 L$ F( B
}3 e% j* i, K' u8 y7 u1 S
%>& c# X$ l# }# T5 Y; h- l
temp=<%=temp%>;
# h* Y1 g! x" Zfunction changelocation(id){ ( u5 M5 c9 L$ J* r( h; H
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
! K+ b& G' ]3 ~: V- H) o% t4 m- v4 Wvar i = 0;
2 Q- @; O5 ]1 _3 `7 tdocument.combo_box.city.options[0]=new option('-------','');   P6 }( E: }5 _8 P4 r
for(i=0;i<temp;i++){
6 H. P; C0 I9 t$ o7 u* H9 O8 Y7 uif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] , y# ?( ^3 E$ C! w7 i( h9 R
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); & Q2 v& c/ F% D  P" R( f
}
: I* z' F  b; @2 v$ @( G( a}
0 B- i. s1 Z) u1 M}
# ?9 J6 X4 q+ a8 t' U5 @" _6 L* N</script>
" `5 m5 r6 k8 G/ Y6 @1 j) s# P- _/ n" w" @  \/ D, A2 [: B
<form name="combo_box">8 S5 ^# C+ p2 }) }1 }" D
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">2 X# ^5 E& U0 c( z2 c
  <tr height="24">9 H4 t' U/ o4 s+ A: S1 ~: l
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>* y; y+ n8 s% U& y) N+ \, R  n
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>/ _1 w8 d2 s; G  X
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
' Q# C- M) K. t& B    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
2 Y9 o5 e2 }# Z0 W# a7 G* ~8 g  </tr>
% k, K  ~8 b2 |  <tr>
! x; ]5 N$ N) t6 [4 K" g, g    <td>' d; q0 Z5 }7 x1 B8 B
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">7 t5 D+ b9 \& s6 `) L2 T0 q
  <option value="0">请选择部门 ---></option>
1 W2 f6 q. s6 Z' Q2 c* W9 B" o& Q  k<%/ k, [8 I0 D2 R* _4 P) I5 p4 c1 E3 v
    string sqld="select * from tdept";
8 R: }* A: W! D" L/ ]5 N4 ~stmt=conn.createstatement();: Y# m! C$ ^. u$ N+ `. ]% w
rs=stmt.executequery(sqld);3 A  ~$ u# t! e1 U
while(rs.next())0 ?" p- A+ I) b3 r  V0 t' B
{7 |( h1 u) q+ c, Z. O- }" F* x1 ?
%>. T) S% v9 Y5 z% m
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>" s" m# O; m0 M5 u: X* o
<%, C3 `: C9 @& {
}6 v% l2 X& A# F8 F
%>
" `- n3 x+ P9 v; H. z) Q: J  </select>
/ `3 x2 m1 C7 L% @* f7 A; {1 ^</td>
1 z* G% o" F! ^    <td>0 h2 Z* h4 k( i) {& I
  <select multiple id=city style="width:150;height:200" class="bgc">* W6 S& e2 p2 z  d5 H& `
  </select>3 h; O9 K* z6 C, E8 _4 j3 c" L
</td>- g8 O- l+ t: m$ V; R  r8 ~' T" D: f
    <td nowrap align="center" class="bgc">7 T. C* q* p- w2 S) e& {; x# I
  <input type="button"  value="<<" class="buttons">
/ J7 E2 u& L9 u- u1 D, X: R  <input type="button"  value=">>" class="buttons">
& L& w  ?7 J2 P</td>
% p" E2 l" t+ j) `- d" J: ?% Z    <td>( o( x3 p$ i& x$ Y
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
+ c, O% Z, n7 s+ Z* q  </select>- t1 ]/ U& ~) x  J; q' b
</td>
1 `- {& w) e* y  </tr>* r6 V& j8 Y& L% F
    <tr class="bgc"> + X3 K0 M) g! f$ y
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
# y" A% b! m( l( o! R: Y  </tr>
% }4 b( }/ k1 ?& P3 z  x</table>
' V9 j+ ^3 c8 K! F</form>
( B( G* X" j/ w<script language="javascript">
: g# `6 u- m- h//人名移动
. @" `  i! [: D; `function move(fbox, tbox) {
7 M8 K/ c' Y, V) g" I- O7 v' wvar arrfbox = new array();5 ]; i1 k% e6 W& k9 e
var arrtbox = new array();
5 F+ Z3 F$ t; ]# i; n, Mvar arrlookup = new array();
! t! @" v9 |) V7 N+ _var i;
. O0 x0 q! i% Z# P: ifor (i = 0; i < tbox.options.length; i++) {. m" t) L# Q$ z( m7 e1 I# s6 X. N
arrlookup[tbox.options.text] = tbox.options.value;0 l1 L+ z) Y1 H
arrtbox = tbox.options.text;6 k) N1 Y- V& `: S. T; S% g
}& r( t4 J( E5 v- {3 x1 r+ V8 Y
var flength = 0;
7 I8 Y4 R6 Z9 y8 L! H0 E3 pvar tlength = arrtbox.length;
  g0 W5 U- D! k( D3 N1 jfor(i = 0; i < fbox.options.length; i++) {
( Y0 L- W1 t. Earrlookup[fbox.options.text] = fbox.options.value;
0 K9 V  V- E" _1 g7 iif (fbox.options.selected && fbox.options.value != "") {; I) Z2 H# \- m; o( q
arrtbox[tlength] = fbox.options.text;  d7 T: F! @% D# f& d; b. ]" i
tlength++;# a/ b5 W$ Q; Z3 u) x2 |( T' z
}
0 o- a6 e6 H) [% ~/ q4 e2 M; ielse {
  {5 u8 z, o# r7 Oarrfbox[flength] = fbox.options.text;! m2 W  _; o  a& @' J
flength++;
5 {% k0 A, o; {+ K4 A4 r3 i9 _   }* C9 z3 H7 \& U+ F" G* q2 d( ^; N
}# P7 |9 m) c0 u% {/ c
arrfbox.sort();" K! ~3 ^- t% n$ W' G4 J3 ~5 I
arrtbox.sort();
+ H3 i, X- }) v& A
/ r$ [# x+ M/ P7 P+ Ofbox.length = 0;
3 j9 d  |1 c6 r1 t% Vtbox.length = 0;
; R2 f$ l5 @. T, k0 T, j3 m1 qvar c;
7 N! C% V% S0 S$ k3 d( Tfor(c = 0; c < arrfbox.length; c++) {
/ h. ~" E# t, y  U  i0 ovar no = new option();
9 `8 ~4 c5 K9 {' x( }no.value = arrlookup[arrfbox[c]];! s4 r# Z8 \: @0 ^% z
no.text = arrfbox[c];
# Z) h) t4 N' k+ z1 P) a6 kfbox[c] = no;8 f/ d8 I; l5 N; l% q/ V4 O, _
}6 C/ P2 p8 e5 L) Z% ~5 `
for(c = 0; c < arrtbox.length; c++) {
. e5 l7 Z0 s& M, `, _) Q, l) F/ Avar no = new option();0 _! u. ~5 C& U$ E* i, R
no.value = arrlookup[arrtbox[c]];; E$ \1 \  \& m: D" P# h
no.text = arrtbox[c];
4 ^( h, b  o7 f5 y/ x- \tbox[c] = no;' e. z$ v) H  c8 s7 }6 C! j. b* a
   }: K6 \" J6 E1 B0 [
}
7 D9 y6 O+ F: Y" h: N</script>
8 ?/ S/ N( g# Y& @</body>7 a$ q7 I/ @0 W1 T# Q  R

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