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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
, T' ^% D8 s% Y+ O/ F1 ^- }         c pageencoding="gb2312"
. e" x9 V& u) H3 M& @%>
1 {$ f. Y3 u# e<style>
# p/ _3 p  [0 Q.f9{ font-size:9pt; }
. s. h2 T# r, s, ~% P5 U* p& L. h; l.bgc{ background-color:#aecaf9; color: #0033ff }
2 ?  f7 W$ e6 I6 s.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
: d5 S" d: R! C) T! Y  border-bottom: solid 1px #4e7dc1;
+ z# ]% F( f9 M/ T) K  border-left: solid 1px #aecaf9;
# a- s6 a( w; }, }! J1 p  border-right: solid 1px #5679bd;$ g7 g, V# E& G- x4 ]+ @1 t
  padding:1px;
! W5 X' }/ J& A7 H4 M- k  margin:0px;}
3 I: X/ p  Z  ?8 j4 u2 ?- K</style>2 N, w( y0 p8 `$ O: D6 i2 W. Y# @& x
<script language="javascript">0 m  R" }$ }7 r; l7 m/ t+ o
<!--
  i! I' s  S% S( j. }2 }function rv()
4 [3 ^/ g, d6 ^- v" ~2 _( N3 r/ p{  K4 j3 y" d; M: K
  var val="";2 o' g$ q& p3 n, R
  for(i=0;i<combo_box.list2.length;i++){( {- G, ]0 T1 a1 ^$ }
   val+=","+combo_box.list2.value;2 o3 S# r, D0 W# H
  }
" x/ ]) q# \! H! Q  if(val.charat(0)==","){
6 k" j" M" F7 V9 p1 F8 ~   val=val.substr(1,val.length);
& w8 b8 o; u' _$ d: ^$ m$ J  }; f9 y3 b  P, y5 }: V8 R7 c
  opener.form1.frecname.value=val;+ _6 J2 B" B- u
  self.close();9 O$ |: _# Z+ `: X% K4 a+ M" b
}
+ H0 c% E5 ]/ k# n1 ?/ _//-->3 ^7 W4 g; G# v, D4 g
</script>
, u! W  j4 h# o" @( V7 L% E<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
: l: t% @% H2 \<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
6 L$ C% S+ [2 U: E# y* X5 X* b, v<%
! ]! U+ h' `! V  F/ T0 r- Q  cdatasource ds=new cdatasource();  //数据联结bean实例
1 O; h+ C0 j) i( X* y* R% n. E  java.sql.connection conn=ds.getconnection();
2 W- F, y; R' ~5 f. [& w  java.sql.statement stmt=null;$ v5 k4 y2 f0 q5 A3 ~8 w
  java.sql.resultset rs=null;
+ Z7 U6 e! i7 Q1 P+ K; t# e& D  cdatacheck dc=new cdatacheck();
* }& y# C& [9 e7 F%>' A# h0 w2 b2 `" _
<%; X" r* h' W# l' g% ?' m
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 W% c2 X) x- s, t) e* u/ sstmt=conn.createstatement();0 A0 ?; [/ O# ~) M
rs=stmt.executequery(sqlu);$ C0 W. [4 w, Q7 i0 k& H1 \
%>
! q6 c( s7 D* x$ x7 }# ]4 X<script language='javascript'>
6 P: \0 j4 I0 |) ^% S0 j3 A3 Oarr = new array();4 o5 `4 b9 @5 M
<%  int temp=0;
9 w9 z2 \! }! |  Q8 W8 F  Pwhile(rs.next())
7 s3 q- g* s: ?{7 I# E. q7 E' |' c
%>
* A/ S' r9 q1 @# R$ R+ j, m0 W8 warr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");1 t# L2 }: [( s3 q: t) c& D
<%% \/ L! }$ R8 ^& T
temp = temp + 1;
- q' U( r. O9 w+ v2 y- ?/ @/ r}0 F0 ^0 O6 G: e; v4 F, O3 ?
%>" V. j% Z; S0 [7 A( E
temp=<%=temp%>;  w# n1 b2 D! Q+ Z% m- J+ w) E
function changelocation(id){ - i. ?+ V; t7 f: o, }6 v
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 9 r8 l4 |6 K( L6 u
var i = 0;
- j1 }/ ]6 D& Q7 k! `4 M$ Ndocument.combo_box.city.options[0]=new option('-------','');
" I% G& j! g- o3 p* a: `! H3 j2 Ofor(i=0;i<temp;i++){ 0 r* t0 _  y$ d( B- z
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] * O4 r" ]1 U5 D; j, v! e: K
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
9 X7 n) E% e; d: q0 |8 d4 R2 h6 Z% T} * ^2 ~# R% g2 d3 X
} & V6 z& B1 i( C7 C" g
}
( C3 k1 ?6 l6 U8 E</script>( Y, `6 t2 q+ F4 \+ \3 P7 N. O( B
! B. U. C. p' @' k$ {2 T! }
<form name="combo_box">( Y9 L% S0 o5 C
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
) q( w9 q& \& B" ~* R% U+ ~  <tr height="24">" B4 U: e2 K# q1 x) e
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>1 G/ S. l( l1 C1 {* f: `
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>9 f( I; V& {, H0 Q
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>1 M0 |% Q  M! |0 R7 a5 T
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
4 Z9 b8 ]% n& k6 X* D) \  </tr>
3 `8 {5 l5 A3 C$ a. p' d  <tr> * V' W6 [" A8 V- G, V1 r: ~( n& `% L
    <td>
' w- P/ d3 z; ]1 n" V8 ?. w  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
4 g/ d9 ^. U5 k4 ]  <option value="0">请选择部门 ---></option>% {$ V* j! G! q7 M! W' f$ d2 Y: m! A
<%
, g# k5 w/ E$ @1 C7 A4 h) [3 R  k    string sqld="select * from tdept";5 ^" c$ Z( \0 W, n
stmt=conn.createstatement();! Z& v. i! l/ b. `- i! i6 T3 x5 N* f
rs=stmt.executequery(sqld);
  U0 F: u2 B  m2 [' y3 v$ |while(rs.next())1 F) U) ^0 \6 I& X
{+ W! a! ^9 H8 c
%>
9 o' o. a* k, h; f  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>' d1 ], E+ h* G
<%: j/ _6 J: J% ^! j) Y
}
# [; f# y( `. G3 j1 ?$ X%>
7 l/ i1 y* k8 ^* s5 b' X  </select>3 m8 W: m' f& w4 C  G
</td>; S/ m0 A  w6 ^* V  V, n
    <td>
. d3 P9 _- g0 @! Z  <select multiple id=city style="width:150;height:200" class="bgc">3 q: J' ]$ [- ?- N: X/ @
  </select>! B1 m. r* y! H( }
</td>9 K$ Q. s! j* o$ y
    <td nowrap align="center" class="bgc">( F9 }" O" K. ?' ^# q4 k6 t7 _
  <input type="button"  value="<<" class="buttons">
; g) S: \, }! v: ^3 a  <input type="button"  value=">>" class="buttons">0 o. k, j& E8 ^
</td>
) A/ ]0 N( e  \; j    <td>7 P3 w0 \; }: p* a
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">' A& |+ k- U7 n& a7 s5 s
  </select>) I/ E1 y4 D" |7 v( d7 N
</td>
$ s3 a! E1 n1 y  </tr>
7 x. k' c# M2 u' L    <tr class="bgc"> ; B) z6 |4 K- s) G& i, E
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
, i1 }& v) D' R" `& Q$ p  </tr>6 Z) L: |3 v1 W
</table>4 i  d" ]) q+ Y9 D5 A; s
</form>
! s8 J  i) q7 Q5 `" Y; b( G/ c/ B<script language="javascript">
, S3 d! T$ V8 P/ F//人名移动
# U$ [1 [% k! U% Q( N+ H& }; Tfunction move(fbox, tbox) {9 w1 z3 k* j+ D+ z
var arrfbox = new array();
& ~1 t4 R) Z% B! gvar arrtbox = new array();$ w5 _8 |8 j2 `* t9 F/ A6 r& E
var arrlookup = new array();
" y8 _: A2 ]1 |% }" m) J( m$ ~9 y+ tvar i;
7 e# R( g, u" I: `4 z7 _for (i = 0; i < tbox.options.length; i++) {( E+ w) V2 J( ~9 D" ]
arrlookup[tbox.options.text] = tbox.options.value;, V  s4 z; ?" q! x* b: Q5 a( V
arrtbox = tbox.options.text;0 P% w% t) Z8 _2 g
}
3 q0 k- [( W% `! wvar flength = 0;
! \, P  Y/ y; Q, \& v" P1 f; o- Dvar tlength = arrtbox.length;
0 o1 w$ J) M8 a' R  O7 yfor(i = 0; i < fbox.options.length; i++) {
+ U# \' d7 q9 u$ R" |; l7 _" tarrlookup[fbox.options.text] = fbox.options.value;
; @# c1 _7 O+ p+ e- r1 n' Lif (fbox.options.selected && fbox.options.value != "") {
( V. H% a& J) j% Yarrtbox[tlength] = fbox.options.text;
; y' I+ `1 u- l# Ytlength++;
0 Z% {- S* T* s+ t( m/ ^! g0 {}+ k, w" h, k0 r: a- `
else {/ D, N* V: H  q) w) O
arrfbox[flength] = fbox.options.text;
5 q: X1 i5 L% u  r- ?9 vflength++;: E5 [, O0 O7 @1 @6 N3 ]# C
   }# h" p8 w0 r1 p0 n9 ~+ c; ^& d! |
}
/ g5 m( \$ ^$ ~7 |; u8 ]+ narrfbox.sort();1 [3 z$ b  |3 ?; w  W9 L( `7 ]2 _
arrtbox.sort();% l) S7 v- n* w  H

! V' G: b" L6 L# e/ ]. D9 Ufbox.length = 0;
1 ?7 Y7 F$ k  ]$ d! ^1 R* G: V/ Ztbox.length = 0;( \- \4 U" V! B% }- b
var c;. z& |$ ~1 Z) n0 ]5 n7 R
for(c = 0; c < arrfbox.length; c++) {
  l* m( z* i9 O  z( g) Evar no = new option();; _, f) H( t- c7 O/ P
no.value = arrlookup[arrfbox[c]];
3 R6 A; s7 V3 ]; S# gno.text = arrfbox[c];, d3 o2 F5 e1 s$ z  ^- p* ^5 k
fbox[c] = no;! u7 |  l# I1 u0 W1 T" ]
}
8 D, S$ o/ K* f5 x- ~5 jfor(c = 0; c < arrtbox.length; c++) {
; @0 w& }, n+ t1 F8 c, |+ Bvar no = new option();! _4 Z5 e, s% t3 G/ }2 M
no.value = arrlookup[arrtbox[c]];* _( w/ I( t; B
no.text = arrtbox[c];
/ O% v4 }# l6 G2 \/ ?& c: ^4 I  Ctbox[c] = no;
  W/ ^" n5 t. n" Q5 l   }
( F. o. ]4 Y. G( U7 N4 {5 ~}
1 [* {4 }3 [4 Q, R) B5 X. ~  u' k</script>
* A4 \2 v, M5 h( }1 s+ h</body>8 V6 C) T5 ~* A% _

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