Board logo

标题: jsp+javascript打造级连菜单 [打印本页]

作者: admin    时间: 2007-12-5 17:43     标题: jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"* r" A* p# j; U0 e2 J
         c pageencoding="gb2312"
! K& u/ g5 e# E2 ~%>& m. ?" e# ]' V1 M8 l
<style>3 C( @' O9 X3 u
.f9{ font-size:9pt; }! y3 P* U# Q% j! i4 S6 O# a
.bgc{ background-color:#aecaf9; color: #0033ff }& N* J0 t) b* w( i) m5 n0 P
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;$ [+ k8 }8 M2 S/ q- x9 w
  border-bottom: solid 1px #4e7dc1;
; z) F% P" s) g0 u7 p  border-left: solid 1px #aecaf9;
) H9 L* l+ L9 g! [  |$ _  border-right: solid 1px #5679bd;' ?% B6 p' \8 t' i. G
  padding:1px;
- B. Q5 A( |( v* d  margin:0px;}
) j$ C: d. E# h3 z: [</style>
) V0 s7 Q/ z8 _* w+ v<script language="javascript">1 d9 C& P/ P$ d) c) N6 b
<!--
5 H& U" W1 E# n# ]; R7 afunction rv()
, p/ J2 d0 O+ P# Q{
, I' P. t" n! r- k+ C  var val="";. v# {# w4 j' s
  for(i=0;i<combo_box.list2.length;i++){6 s8 l; e5 o0 V  c
   val+=","+combo_box.list2.value;
1 R) {* w5 {' i1 ]- C$ \# i8 }  }
5 ?) m$ |5 y6 w9 ?. H  if(val.charat(0)==","){: w3 D! r& c% U! ~
   val=val.substr(1,val.length);
4 r' q5 D7 ^1 r' `* [  }0 j3 g: D- I7 g/ P/ B- i
  opener.form1.frecname.value=val;: i# X, w- I, E$ U
  self.close();
7 i. p: X! F4 ^/ ]5 K' u- y* E}" r7 ?) X3 ?1 j2 `% C6 Z
//-->
+ j( D+ K! C& L- w& n9 o. l! |1 z</script>
% L, c  w8 M  n$ Y1 Q<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">; ~* ~/ x+ o8 ]5 y
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
7 E6 t. [( X9 X# H( X  {<%  Q( `+ ]) a. s/ ^: g* _
  cdatasource ds=new cdatasource();  //数据联结bean实例5 S4 O4 E/ n* R8 h' e3 y
  java.sql.connection conn=ds.getconnection();2 e  i* J) @3 M7 e6 l8 ?9 o' C
  java.sql.statement stmt=null;
- s# b8 }% l3 g( Q3 ~  _  java.sql.resultset rs=null;6 E+ ~0 w1 B1 A" v4 O9 z3 O
  cdatacheck dc=new cdatacheck();
4 O. L6 _7 X+ P%>) S* V% @+ S0 p. b! K0 X
<%% r5 {7 U% u( V- Q4 K2 q
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";) Z5 o  k" T0 |8 H9 n1 Y
stmt=conn.createstatement();# g% t) M# L" n$ f
rs=stmt.executequery(sqlu);
! f# }+ x; c/ \2 P2 A1 b+ l- [%>  e3 l6 `. O. @
<script language='javascript'>
9 ~0 y! U7 _+ @5 X: m1 @. `9 r$ Karr = new array();
: }1 Q% H) e( G$ L<%  int temp=0;8 R) ^, u1 _$ p
while(rs.next())
4 F0 I7 J4 O, j& j{
( |. C  |. P5 D; y& z%># R# y6 x, r( \: Y- U  u6 s
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
, V7 d- S: Q6 o5 e& R. X<%4 S, c: t9 J! h- V$ G
temp = temp + 1;! M- x& P8 X0 N) m/ `- U2 Q
}+ z/ }0 ]. l) F4 @) [+ f; a6 U
%>0 k: o7 b% L- O" Q5 K7 D
temp=<%=temp%>;. G, K' X. t! S, i
function changelocation(id){
8 A/ I+ ?" X+ f! z& Q+ i0 u5 W+ Pdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 % z5 p3 J. Q$ t
var i = 0;
, B7 t# c* p, r. I( x; Xdocument.combo_box.city.options[0]=new option('-------',''); - Q$ u0 w0 B( V$ ], h
for(i=0;i<temp;i++){ : F8 z; n2 o- b2 B3 ^
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 3 D2 ~3 h1 K* @8 `8 |5 j
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
3 m/ w/ ^; S) T' j}
6 p4 s5 n( ^2 J9 a1 X  d: Z} + |# }- ^3 `" P# W( r
} " p% E9 D" @9 A4 \+ x  F0 d
</script>
& f9 ?6 p; r: O- n* l
) E/ [' P( M% M) r1 H<form name="combo_box">* `$ _2 ~; O% ]
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
1 f+ }* p3 Q! ]( ]- g6 ?% q  <tr height="24">+ b, |& A3 X' E8 H1 ?" G$ Q0 |
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
! f9 q! v% y/ p    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
* j- }  J6 y" C/ }0 |  N$ X2 A    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
* C; [- K! j, U& _    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>; L7 \& U: T# E! H: t
  </tr>! _& s2 o  o1 P3 e3 W
  <tr> " r' I# _* o9 N# b4 x2 H
    <td>6 m% ^. T" n' g& X
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">+ }7 S! b5 X) x* H, U% ]% n% @
  <option value="0">请选择部门 ---></option>$ z3 D" n- k4 s- h: L4 W2 W
<%
8 j# f* q7 b- G3 d+ U* A$ X    string sqld="select * from tdept";) q' J4 l1 ~8 a  L1 U
stmt=conn.createstatement();4 h2 h; E! k! h& A% ^
rs=stmt.executequery(sqld);
8 |# i9 @# w* B' m  Y1 [( {while(rs.next())
. [* u2 @: T3 |% u" Z! \{. h. {+ @+ A4 M
%>
( s. \! f- |" K- R3 I  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
/ \; a0 O2 u( G, n7 K! ^$ i8 ~<%- i, u! f5 X% E+ z
}
& ]( M* }- D4 F0 ~" j" ]+ I0 g* ~* u%> / }, C  {  a2 u2 S
  </select>+ I9 w) n  I8 g
</td>
# W4 e- ]0 Z  N+ D6 V$ u' V    <td>
9 O) f! U3 f2 t) u- A/ s  <select multiple id=city style="width:150;height:200" class="bgc">7 f" j+ a8 w4 }- c9 s9 }# ~
  </select>
* k* \, z$ M. U$ k</td>
0 P6 J# K' G( j+ T    <td nowrap align="center" class="bgc">
2 X* ~2 [- h& u7 q; l  <input type="button"  value="<<" class="buttons">& ], L! n# W! t& q" R- O$ c
  <input type="button"  value=">>" class="buttons">0 d7 a0 L+ a# b  {1 ?9 @+ p9 a: B
</td>
+ n( V0 b% v) T( S9 @    <td>
! o  V6 G) Q3 P. e  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">* a: F2 a. [' e" ~
  </select>3 |8 T( w( @) @. I
</td>! |& S- r# l; \* n5 n! h
  </tr>2 ?: e& I7 y3 L, @6 ]  M1 l, d
    <tr class="bgc"> , \$ g6 R1 E6 E7 r
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
, q2 C5 K/ `: q" c8 ]" H0 J, p: M  </tr>! M' x8 g' A2 F
</table>
: b. O3 }. a& O1 T) j  G) S+ I</form>
! l: ^( H( I: N<script language="javascript">  }$ e' H6 \0 r) ?, j& C4 d
//人名移动7 O& ], c9 f. ^# }$ Y
function move(fbox, tbox) {' B( |0 e; _  }0 n/ ?
var arrfbox = new array();0 t* y7 T* p( d" ^+ D
var arrtbox = new array();9 N6 t( e/ y- ]2 m$ ^
var arrlookup = new array();
# k; N2 [8 _$ O/ k7 f$ x! mvar i;0 t  Z: N! Z+ W' |* u' N
for (i = 0; i < tbox.options.length; i++) {
1 Y# c9 D) A- n: L! aarrlookup[tbox.options.text] = tbox.options.value;
9 \9 p  B  }' U8 Marrtbox = tbox.options.text;
3 r+ A- H6 P9 D1 ~0 ~. q}+ x/ ]5 A0 F' ?' z
var flength = 0;0 u: c# v- D5 s, k+ o
var tlength = arrtbox.length;) V- B; \3 v: z+ V- L
for(i = 0; i < fbox.options.length; i++) {. R8 G5 J! i$ W
arrlookup[fbox.options.text] = fbox.options.value;
) e2 H" G% P/ E, K' t" d$ mif (fbox.options.selected && fbox.options.value != "") {
2 g/ y7 }; J7 R+ O4 B5 yarrtbox[tlength] = fbox.options.text;
) Z; z0 U& I* e' n0 G7 Gtlength++;
4 E3 @* O2 J. M# g1 `}$ @4 \- A3 _9 \! ^; W8 Q5 v& x
else {) [! d7 T% v' x- G7 p) u* J+ T
arrfbox[flength] = fbox.options.text;4 q6 B' o9 O6 |1 X7 G# H' X
flength++;& g0 s( _% c* s9 T3 N& M' F
   }
/ ]% T+ w- O# `5 C6 t& @7 V}2 n7 d! K4 `0 q& p' k
arrfbox.sort();
" X& b+ {5 e* J; k3 Z( }( U9 Darrtbox.sort();, c! \8 x% e* I" g
& ?- A* H' W. m6 p0 Z* W1 H( n
fbox.length = 0;
. U& z( v: [9 \8 m) E7 dtbox.length = 0;
" J' c- t: h$ T1 n1 nvar c;
4 R. ^8 o/ a% w( x) Q' `9 S' [+ xfor(c = 0; c < arrfbox.length; c++) {
) q4 y  E+ P( m1 y5 v# w9 [* h/ q6 Y6 P. evar no = new option();
" ]  u4 |: S) T6 h# E+ hno.value = arrlookup[arrfbox[c]];! ~& }# h( j# j% ?: A
no.text = arrfbox[c];) g# |, b6 c' N+ j: H
fbox[c] = no;9 j' t! l2 o% ~" o7 t7 I4 [  b
}
) l' {7 m/ H9 t2 X/ J! k8 k/ p0 Zfor(c = 0; c < arrtbox.length; c++) {& v0 m* R, \3 l. }, C/ v7 Q
var no = new option();
: b: m* X7 h* u' t9 _" B- Lno.value = arrlookup[arrtbox[c]];9 R# y$ E0 N0 f+ `
no.text = arrtbox[c];; A; F% n0 V* a$ B$ Q: C
tbox[c] = no;: U% p4 K3 N1 d/ w* Y
   }
1 \5 v5 Y4 ]2 y) k}# C* X( E6 V- ^' ^
</script>/ x1 F) O- \, e6 `1 c1 n! w8 v
</body>
  F) n. N% K7 [2 v0 v7 _





欢迎光临 捌玖网络工作室 (http://89w.org/) Powered by Discuz! 7.2