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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
5 [3 p4 V" D8 F* w# o         c pageencoding="gb2312"
( c% n- U+ h' M( u  F%>
* V! ], o6 f- V  e" p* m& l<style>6 O6 H' M& L" i+ [9 f( ]* k
.f9{ font-size:9pt; }
& u1 l' b% T( g2 m* J8 r.bgc{ background-color:#aecaf9; color: #0033ff }
  {3 ]  ^/ ]1 n4 O+ U8 ?.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
/ h7 ^2 F* |! _1 @& Q. W1 U  border-bottom: solid 1px #4e7dc1;
' C2 \  _0 E+ T" h9 I- \# a: v  border-left: solid 1px #aecaf9;
+ t; F. ?- A5 e6 C# F  border-right: solid 1px #5679bd;) Q# ]% N7 U) M
  padding:1px;
; i* R5 O# Z2 C' s5 L) W; V9 ?  margin:0px;}
- d3 K1 ~9 f' @! k0 C3 k$ N& W</style>
9 ~: ^! t- u: O7 z) r% _<script language="javascript">
! t8 @0 r/ G! G9 M5 s+ ~9 Y, V  s<!--  [! C, }: e8 U& w' a: u
function rv()
* U# Q6 L0 `( i: e1 O0 g3 l{8 @& v5 F4 O/ t( o; Q
  var val="";& \$ i5 b4 Q1 _, m. z( H: \  h
  for(i=0;i<combo_box.list2.length;i++){
5 c4 {& T1 W; ?7 b* F   val+=","+combo_box.list2.value;
2 B0 H6 K4 a7 J+ K$ d) H  }! N% h2 Z& d9 }) K7 @' Y" e
  if(val.charat(0)==","){
. Q7 j5 u. l" G# G3 ], m   val=val.substr(1,val.length);3 Y, g' ]" g; p, I2 `" `! z, @
  }
) I) i% M7 ~$ I& W& r: Q  opener.form1.frecname.value=val;1 Y) X6 I8 @+ G$ b" S! K
  self.close();# |1 u' G$ r' o6 X4 B+ p5 K
}
9 p) i- k. ~+ ]4 e//-->2 t9 e& F3 V( O: A/ D6 a
</script># H+ g0 `4 L9 v. X
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">/ H; t, g' r5 B: Z( V
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />& N( @& V3 A0 ^/ C% l# T
<%
( i& q2 O- F" w, j/ Z0 w. B5 h  cdatasource ds=new cdatasource();  //数据联结bean实例
; z- Y  c2 C  J7 D1 {1 @  java.sql.connection conn=ds.getconnection();/ v4 i. X& u9 }# V9 z/ e" j
  java.sql.statement stmt=null;9 {) d# G  i1 k( r, O
  java.sql.resultset rs=null;- w# v) ^/ r+ x9 V. H
  cdatacheck dc=new cdatacheck();; P) b/ ]8 W1 W* k( _
%>
7 P/ B6 S/ S# }* w4 O* G1 u! ^<%& j  O7 C& Q( f3 S) V: R) u' f
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";( \. G) v! X9 e& m$ J. ]$ w; O$ J
stmt=conn.createstatement();; ~2 l1 f6 i1 N
rs=stmt.executequery(sqlu);. }# K! R8 k7 n( E% ^
%>
, V2 U& `  {  _<script language='javascript'>8 ?' m0 `% o1 w, J0 Y* a
arr = new array();
; T' v( p6 A# P4 E) Z<%  int temp=0;+ y2 |; G& S  [7 k% x5 K! D
while(rs.next()). U4 |' g2 W% w7 \  U, v. d% L
{
: c: c2 U8 \" E9 c3 _) @  q8 u%>$ T, B: z7 E4 U% ^: _
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");* ~7 A4 i1 n8 _  |
<%. g& W4 W% H9 v0 O$ S
temp = temp + 1;/ q5 m# }) A# s! K! \1 ?7 x' a/ A. v
}
/ z8 n! O9 w6 e/ K2 v. ?1 o%>) T& L1 v+ p/ T" n0 r5 \
temp=<%=temp%>;
' d* [8 H& j; p; _9 w! G' Wfunction changelocation(id){ 7 {8 k: W: h9 q: L) |: h
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
! j9 ^* W7 P( G: ~; Bvar i = 0; $ C8 [9 s/ k4 @) f- Q9 R
document.combo_box.city.options[0]=new option('-------',''); " ^9 C, B$ r8 l# g
for(i=0;i<temp;i++){
5 N* Q2 @% N( M( Y0 ]if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 9 `# R0 A9 \* C4 x- Y: h0 i
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 9 b5 O$ T' u: e0 \
}
2 b0 h$ V. N4 X7 J! w* `} 2 n! q+ W' k8 ~$ T2 j
} & Y" f1 I1 }9 Q) ~  M( w4 ?
</script>
1 W4 J5 i/ M* w" Q8 a( i0 J. Y- G' D3 i
<form name="combo_box">2 S6 w8 q; f( `* h
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
7 {8 F9 L2 |9 B3 _: n  <tr height="24">, {- t1 k4 |$ g" Y
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
6 a- J5 H/ {& N8 I6 h7 S# J    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>7 `( t% D9 X7 ~3 K4 A5 s1 Q
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
6 u* A) h' c9 z% H0 s" c( c    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>5 O% d" g$ w5 K7 U
  </tr>
8 ^. t% E2 V. u  w" F  <tr> . }4 w1 n" @0 [5 u
    <td>6 B- _8 s: I! j$ I) Z; \' D* T' k
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
8 P) B2 O( u- K- o$ ~  <option value="0">请选择部门 ---></option>1 h) p) f+ _! z3 j
<%% ^( b9 Z4 x- c0 M% V
    string sqld="select * from tdept";
" h0 d: e# I1 ]5 ]stmt=conn.createstatement();
& Q! D3 ~9 l% d4 Irs=stmt.executequery(sqld);
$ P+ I, I. J' f/ |, V% b8 Ywhile(rs.next())* Y5 V/ t; u' V4 I6 S/ a
{) ^5 J' S5 D6 k$ L
%>
1 z3 m" K6 @* T  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
0 q2 }7 `2 S  \' l/ L<%
0 B& m' w+ o: z3 S}
3 W/ F8 V, h) a%>
% M3 }" E; N9 T0 o+ U" z, x- P+ u4 j  </select>2 ~. S+ U& c4 S0 k/ [: s' [
</td>$ Q5 L! v; H$ E
    <td>' L" f+ n( K: r( ?) c
  <select multiple id=city style="width:150;height:200" class="bgc">$ Y8 F6 B* G  w- \6 I4 J0 Y* I3 a1 V
  </select>
: c$ J2 K3 t% Q* q! V; p% _7 u  T& [</td>! _( ]1 W' l) J: Z; @3 i
    <td nowrap align="center" class="bgc">! z1 R4 @0 {" O  j' }
  <input type="button"  value="<<" class="buttons">
6 h; Y8 f) R0 H9 r  <input type="button"  value=">>" class="buttons">% I6 S, X$ ~- _% l$ I3 Y! k5 c
</td>, h2 r7 l% R% l( m  |$ Z8 u
    <td>% `  \1 `/ \: @3 M3 _
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
, \) E2 c% p* W. H  w0 O  </select>9 i' f+ V3 J& C$ }- v' Q; u- _
</td>
# S! j  d8 v% o: p  </tr>5 i; L* s+ V8 M, Q& ?: K8 G( |
    <tr class="bgc"> 0 n" S1 T- u' ?
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>. E0 V" K! q$ A( I. b' V! A/ D+ L( K
  </tr>: Q$ [# `9 Z6 k6 D
</table>. S/ @4 H+ f  T  s. l7 i& c
</form>% E1 |, s. ~9 e% E/ C
<script language="javascript">
* w5 [3 t4 y  p9 i, x6 ~- i! ?: d//人名移动
! [' N, U# U7 w9 K. E' ?* nfunction move(fbox, tbox) {) H7 [+ {; m1 N8 X+ R" p
var arrfbox = new array();; c2 ]+ ?# b2 m8 \4 F
var arrtbox = new array();) ?  G+ o8 {) t7 `. l
var arrlookup = new array();7 _) R% G  x3 E. j5 ~3 _6 }
var i;2 V* h/ i" b( s- W
for (i = 0; i < tbox.options.length; i++) {% l4 A+ u. z; @8 T& t8 o' N
arrlookup[tbox.options.text] = tbox.options.value;
# r% T! O& ~% i6 s( Uarrtbox = tbox.options.text;
( o8 P1 G7 |* V, X7 N}/ e# F, G7 w, ]( J  l1 z: t; m" M
var flength = 0;
# s, l' {! S! P3 Y: ]: lvar tlength = arrtbox.length;
8 K4 J" g7 ]& N9 r/ ]for(i = 0; i < fbox.options.length; i++) {
, t& ]: G# k2 G2 C4 n: D" Y/ karrlookup[fbox.options.text] = fbox.options.value;
) T# H' p$ }, \! @* v5 n- Kif (fbox.options.selected && fbox.options.value != "") {
" K+ A" s8 `+ r, c/ Warrtbox[tlength] = fbox.options.text;9 q( Z5 e7 G# U: S" z2 P% @( ?# {
tlength++;2 t) ]/ S9 p  c$ B! u
}
8 ?2 y/ E0 t; H# j2 Y4 `else {
, @- c+ F. @9 W7 S* ^, u, Oarrfbox[flength] = fbox.options.text;+ Q& K" u& Q2 b; K* p3 w/ d
flength++;
/ m' J4 I" M+ d0 |4 b% Z2 Y6 P   }
! }) s  F. j% i/ c}' s6 {; F, L3 Q9 c: n
arrfbox.sort();
- Z- c0 _0 h1 r' K, ^0 `3 A/ Xarrtbox.sort();$ L0 g  j, M5 ^$ A6 u. u1 H; w

3 @" h+ |9 Z0 r, Yfbox.length = 0;; `" }  M* L: F: D" ?5 Q) N2 n5 e( v
tbox.length = 0;' p& W6 y6 o! T3 w+ m
var c;
" E& v0 i$ J( O6 {% b; h  _for(c = 0; c < arrfbox.length; c++) {+ m3 B3 q& o) V0 [
var no = new option();* P( P, r  G6 O1 A
no.value = arrlookup[arrfbox[c]];
0 {1 C7 B4 ]4 G5 n& J' Bno.text = arrfbox[c];
- \* v6 A& W+ k5 C* yfbox[c] = no;( _" Y0 R8 f/ M1 D' l8 l
}
2 m8 B( f# e. d0 yfor(c = 0; c < arrtbox.length; c++) {- ^9 E* R& x& ~4 u, z1 `" u: b9 V
var no = new option();5 x! A  m& ~6 K3 T3 A! n, q0 j: ?
no.value = arrlookup[arrtbox[c]];1 ~* w  L; y" v- Z+ z1 J- s: E: N
no.text = arrtbox[c];" V2 f8 v$ ^$ ^8 J! c
tbox[c] = no;+ ^% P: j1 H  d  q$ b  {
   }
; |5 T6 }* q  ?; K( t}% @6 m* c- k: Z3 M0 ?! u
</script>
# \% x: F8 P$ I7 E+ L3 }! r</body>
; A, x' h3 P& B$ N$ ]2 I  C3 n

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