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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"6 Y: ~" O, I& V; q
         c pageencoding="gb2312". Y% H7 }; j- M5 v" ^
%>
" X! z0 I) S4 F3 O<style>: T. d9 D  p) A
.f9{ font-size:9pt; }. b# f# o6 ~8 d/ P/ n; l
.bgc{ background-color:#aecaf9; color: #0033ff }7 l: i- M# _1 J) h. h% W" \9 E
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
+ S6 T( h$ x8 ~8 T& t$ O4 P, s  border-bottom: solid 1px #4e7dc1;, {+ h: c% ?8 t: X& A) Q$ |
  border-left: solid 1px #aecaf9;
: U( S4 p; j2 O, ]+ Y  border-right: solid 1px #5679bd;
5 G8 s  j7 X% g9 w* C; R, z1 h5 t  padding:1px;+ p$ H, L6 c) k; v
  margin:0px;}
" M$ b& V# S; ~& B6 V</style>
9 c" v7 A$ {3 _6 t1 U4 O* t<script language="javascript">
# m" ~6 m# \% f( v) m<!--
5 E" m* b; x$ H( Y4 D' Cfunction rv()9 u' Q8 ]2 ?  w# y1 x
{- r) ]! [& Z& {# t. C
  var val="";5 M/ }2 |' @' S; F2 B
  for(i=0;i<combo_box.list2.length;i++){
9 V9 z5 y% P1 e( u6 K   val+=","+combo_box.list2.value;
& O' }1 m+ n6 T8 p/ \/ h  A  }. Q: Y. O0 O! g6 k" j+ s
  if(val.charat(0)==","){
$ D# x. ^9 n0 G; P   val=val.substr(1,val.length);3 F% G: {7 Q% v2 B
  }3 I. P0 p' ?: _- r) g
  opener.form1.frecname.value=val;
* Z0 B) C% Y! S, i- Q: ?  self.close();2 @$ T; S0 a* e% M
}
! H6 m1 v0 s! K5 q+ Y2 Z% f1 r2 ]//--># k3 R% l, J  x  g' y$ W) b7 U
</script>4 F! n; Q9 x2 k2 K, O
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">. ^/ G7 w: ?* B4 ]) W
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />) M" u7 o( u, c* a4 Q0 Q
<%) ~5 z& U  b, C' h) ^2 P( M. ~
  cdatasource ds=new cdatasource();  //数据联结bean实例
! q  J8 W% |4 P- d" k1 j  java.sql.connection conn=ds.getconnection();
0 _; B; Q; y) |7 @5 _8 U  java.sql.statement stmt=null;
/ @4 b( {$ Z+ P; S  java.sql.resultset rs=null;+ R% u7 m; ]! v1 u
  cdatacheck dc=new cdatacheck();
% h! P& ]( i$ \0 l. }%>9 i5 x4 Q/ p& K! s9 A' I
<%7 T9 J& f$ z% U- G
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 E& o3 H( v, M/ gstmt=conn.createstatement();
# h, W* x, }, m  o, {rs=stmt.executequery(sqlu);' f4 y/ A8 n* J7 w7 ~
%>
( `9 _6 k' M3 \2 }( L5 u<script language='javascript'>
7 T2 z) d" f. L, F$ ^& Carr = new array();# C. {8 `% f/ @; u6 I% _" p
<%  int temp=0;' E  z" h( E) D& m$ D
while(rs.next())
+ K) C9 A, `) k0 Z{! D. d, ^! H1 L. w" f: L
%>3 j" t6 {6 V* M, c6 E1 b" G
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");& z7 ]) U+ j: N  z* v* C( Q2 Z
<%
. C  E5 e+ P7 u; p+ ?* U# @temp = temp + 1;
1 ^; m/ z6 [( U0 n; U; e" G6 a( N}
$ `( g8 ?$ V7 z$ ]; l%>
1 d4 B/ C! y6 c6 T# Ptemp=<%=temp%>;
8 V3 {* C, p" W0 e5 S; `function changelocation(id){ ! t" g  n- J' _. h4 K
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 ' g: X: ~5 F3 @8 v. ^
var i = 0;
" j( n4 X# \0 f5 J6 w2 |document.combo_box.city.options[0]=new option('-------','');
( Q7 l0 s" D1 pfor(i=0;i<temp;i++){ 8 j% H( n/ H3 d) X1 g' p
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] / }3 p! g/ d; G, a+ k: z
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
2 F0 Z' E( n2 F8 D}
. Q$ \, E4 Z* b$ o}
* ?' N: P" E- }! u- f5 O% |# V2 Y} 6 {) F. U" I0 S; o( _5 R6 B( X
</script>
5 v- Y) Z: M1 D) c. U, D
$ ^  `* H7 Q4 a) H2 p2 F" S1 j# T<form name="combo_box">$ N. s9 E  G, W2 W( o4 e
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
& Y6 x. O' M3 X- f" p1 f  <tr height="24">3 e. o8 @; L+ a) t/ u
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
! l6 Q) Y9 [. ]" A    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>9 m. S& T* v4 P8 `8 P9 i
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
0 i# \: s' o. v, \2 O    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
9 C# ?/ S' m/ v# {$ }  </tr>! e% W) ^8 ]) H4 k' j
  <tr> ( Q/ h$ k1 e% y- U! x, W
    <td>
2 k% W% _9 _6 F- {2 T  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
1 h, K2 j6 Y3 k' d* v8 b  <option value="0">请选择部门 ---></option>' _( [. n+ z1 X5 d/ U* F0 Z- O) m% X
<%
. K, n8 {, J1 w0 m' J    string sqld="select * from tdept";
: k' L. G) k- a7 z- s. p/ Ustmt=conn.createstatement();  w/ _0 X6 N/ }& S& \& [
rs=stmt.executequery(sqld);* }7 D3 T: X1 T  O
while(rs.next())
$ N& Y0 M5 B* z& {/ j# K7 k{( K! [& ~6 h* m) f9 F
%>* e3 F! \. t/ z' w- w
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
' X& E( F% v# w. X+ D) o<%
4 D& T% g+ _% Y  N( }& B}) z8 ~/ y, s1 N' u; N7 j
%>
3 I* \- W# f. S" A' d, V; A6 ^  </select>
+ n- X) Y# W1 Q8 O4 `</td>
- u$ F2 v( R  Y" d( D* S% O    <td>
9 L/ i4 L( z& X$ O  <select multiple id=city style="width:150;height:200" class="bgc">+ j- t/ o7 E- e
  </select>
& c( e+ I( }% ]. m6 _</td>, P- T$ D, z' q# c; t. A
    <td nowrap align="center" class="bgc">6 P0 j# M+ Y. v  K" A' v( o7 i
  <input type="button"  value="<<" class="buttons">
, X4 y" p1 v/ N: t4 M  <input type="button"  value=">>" class="buttons">6 V# U# l  P7 c" L
</td>0 N$ B0 _7 o0 {3 k6 k& Q$ c
    <td>! W- q8 k  q: J1 K* E) C
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
' O3 m5 `) O# C- k6 r, b! }' E6 n  </select>6 j! v) V9 f2 }# a( Q7 |
</td>) S' P- T  j4 X( ?  g8 W
  </tr>
$ d7 e. k( r) c6 D& U$ P( z    <tr class="bgc"> % U4 u1 o4 n. L: `: N
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
' H# p: o% b: N$ I  </tr>2 x+ d: w0 J7 M" r2 f3 t) ?
</table>
0 }5 z) L: G% \1 Y& n9 J</form>1 s# X4 I: B- K4 E' s2 }" a. x7 t
<script language="javascript">3 Z! {& G( K4 n
//人名移动$ M! |* V) ]# @* F" w: h* E
function move(fbox, tbox) {& N0 i/ K$ r: E' O- E  ?* M
var arrfbox = new array();) e% n/ r- v  V. o0 A( B
var arrtbox = new array();( |9 B+ @, f0 C+ P2 d
var arrlookup = new array();
5 @& A9 C% e6 r: j6 ^- Qvar i;7 X* l: K' o2 l
for (i = 0; i < tbox.options.length; i++) {
4 I9 L9 p- L' Yarrlookup[tbox.options.text] = tbox.options.value;
* C) x: ~! J% marrtbox = tbox.options.text;0 y: d2 u0 z% X
}: J+ r0 G- M$ b  l3 m! I
var flength = 0;5 N/ t( Z# Z0 j2 a9 C- ]
var tlength = arrtbox.length;# A6 Z. t) j, T  e: |
for(i = 0; i < fbox.options.length; i++) {0 f3 r4 f9 F2 w4 J
arrlookup[fbox.options.text] = fbox.options.value;
! I; p' E- v3 v. h4 [8 a' L5 ?if (fbox.options.selected && fbox.options.value != "") {
/ E- G2 Y1 F' u6 Sarrtbox[tlength] = fbox.options.text;
2 R- e, n3 k5 Q, G8 M6 `tlength++;- l& v- o- d6 Z, h! {, g, a
}
- E( a0 e3 V3 O* i' g; \) k& Telse {
& O3 E3 z) {1 l0 K6 r. `arrfbox[flength] = fbox.options.text;
2 A1 a' E* l( A9 Xflength++;# D3 l! G2 ^- R: p# Q2 P% h1 Y
   }
7 e7 J: S7 M! u6 k" M}
* i- @5 ~& a& d0 u/ _+ n! }; m% W9 _! Karrfbox.sort();
* U% Z: v% N; H) P' W% m( Sarrtbox.sort();
4 B' m4 J; M" {0 t$ Q) Q: E% P" U0 y2 t
fbox.length = 0;: a. N* t2 t4 c  P% c2 r
tbox.length = 0;% E. e+ l: v+ d0 ~8 J1 D. D
var c;
' h) m3 ?5 T! A) S1 j$ `for(c = 0; c < arrfbox.length; c++) {
" e8 C, l0 b5 nvar no = new option();
+ v+ I& F8 B) o* @4 Q* U. Tno.value = arrlookup[arrfbox[c]];
& s2 C& M) e' d8 |! `8 q- wno.text = arrfbox[c];
, O- D9 u; o- M1 _. C+ L' Y  Wfbox[c] = no;  U% b, x. t* H) H
}
* C3 T' t8 q* ?for(c = 0; c < arrtbox.length; c++) {  O5 i2 s5 I3 H0 W6 \6 I
var no = new option();9 E" J# }, p4 C: Y  n
no.value = arrlookup[arrtbox[c]];& ]+ E% r7 i4 S
no.text = arrtbox[c];) s* V, z  W. v' M8 |
tbox[c] = no;% }+ _7 l% W. J, q4 V2 ]
   }
$ r& Q( w1 o8 A; K& o, N}7 g; u! ^' _0 Z, m  Q
</script>
3 G6 z. [! G$ o+ G6 G8 B! \$ L</body>, v, e0 K% x8 [8 K  R" `- S7 d' \

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