Board logo

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

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

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
( ^  t+ }% h' @, l5 V, R         c pageencoding="gb2312"0 J& _$ O1 A. A- U& ~, F7 ~
%>
' {% S$ y0 H- j3 i<style>
# `( R4 k1 X" I$ ?# d- R' ^.f9{ font-size:9pt; }
5 ~0 ~1 \$ G& z, i, q% ]. v! j.bgc{ background-color:#aecaf9; color: #0033ff }
! w( F+ V& a/ E: x1 U6 I# Y.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;- M$ e  p7 E% _" D
  border-bottom: solid 1px #4e7dc1;0 i1 r  P- f* A; z
  border-left: solid 1px #aecaf9;
: d2 w) u9 a& ~7 F  border-right: solid 1px #5679bd;9 {1 n$ w, n1 J+ ]
  padding:1px;+ {: a* H' B/ E1 J* C
  margin:0px;}# ]! X/ X- r1 Z& |& [9 C1 Q
</style>
% z7 E! r$ N' c+ h7 D<script language="javascript">2 A9 g, g$ ^% @
<!--# F" e- @& }! w0 _
function rv()5 ^! W3 D% v: S3 g& r
{* p7 l9 b! `4 Q0 n. [
  var val="";
9 z: B7 D4 K2 {& z3 y% q" a7 ^  for(i=0;i<combo_box.list2.length;i++){$ J( |7 S. s5 B
   val+=","+combo_box.list2.value;
3 O: h( u) k0 o7 _# f  }
9 O7 g0 k( d$ u' A& g  if(val.charat(0)==","){
! s, E- }9 F: `) \1 d   val=val.substr(1,val.length);
% \6 _; N& B2 I2 c; m  }7 N$ c2 ~5 f0 f- f
  opener.form1.frecname.value=val;$ B. J" o7 }) M) u. z# D( @, m1 |
  self.close();
- n0 c, b& I1 L  j6 R1 N}5 }0 e$ g) C1 p7 B3 [
//-->
0 n8 S6 X- X3 g5 V0 E& h</script>5 N, X/ C5 y! r! \8 J4 @" S
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
7 E( i6 p2 d2 i+ n( B; V' B<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
! M3 ]: t, a1 g  W<%; O: s$ i5 \9 q6 r
  cdatasource ds=new cdatasource();  //数据联结bean实例
9 L5 O  W; u; \8 Q2 p  java.sql.connection conn=ds.getconnection();1 X: Q" [/ Y5 B9 M2 A) L5 ]
  java.sql.statement stmt=null;9 Z/ t% D3 Q0 b7 T4 b
  java.sql.resultset rs=null;
  M8 f( E9 w  g# u  cdatacheck dc=new cdatacheck();
- C2 [: n, Z" q%>. {4 J& A" |1 u% w# Q
<%9 @$ d5 P9 n7 K1 b8 A' ~1 ?
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";
; }# `2 w  _! h, A9 R2 ustmt=conn.createstatement();
8 ]+ _1 g9 W5 j. s3 X8 y; f' Ers=stmt.executequery(sqlu);; S0 V! x* c2 C5 e0 u% Q
%>
" J+ p6 `7 G9 M& l<script language='javascript'>
: }* a& q6 _: w% m6 k( B( Yarr = new array();
2 T! v2 k" l7 H( b7 g# A<%  int temp=0;
) j+ q/ l5 P$ `, d2 Fwhile(rs.next())% M  s1 q6 E. u0 U
{
6 w" I% O9 A& l+ t+ K( X& j%>
9 p; J( ]0 O6 f" r: v, O( t! W: oarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
# U! y. f8 B, d  D% F<%
- w3 f9 M2 S" e6 T7 W( V7 U. a4 rtemp = temp + 1;8 ^  T, r: {  L0 \5 `- p
}
" s; r: W1 R0 B8 C%>
8 g3 p0 {+ `& qtemp=<%=temp%>;" P& @% @! i' v& J; [
function changelocation(id){
* a( B* H5 ~& Y; Ndocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 2 B. O8 a6 J$ S5 ^" ]6 d) P' b) `
var i = 0;
% j3 V& l/ h& U* {: t( qdocument.combo_box.city.options[0]=new option('-------',''); 2 ]7 b# H+ Q  U; u  p
for(i=0;i<temp;i++){
7 D' t$ }& g7 r" T. I. r5 nif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 7 w& o3 \: s: g
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
; I7 _6 U- L+ x# Y8 K* j} 5 n4 |& k) L- x0 \/ \/ m
}
! v- }' `( h8 g0 k7 ~$ d} + q; A! l; @! t. W7 U
</script>
+ `  K& Y' F2 \) L( H& a6 j6 P( [# I7 t1 \9 V
<form name="combo_box">/ d. g$ ]& C6 X4 L4 k& W
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">* r  S3 I6 H2 U( F1 y
  <tr height="24"># _! I: L1 ]# J( }# d
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>2 s0 Q) Z8 r1 g  @9 A$ b( i& n9 c( E
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
& d. ?: d! R& L6 o7 k/ v4 B7 p& I6 B    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
: Q- z5 l$ D1 D  K    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>6 K# t" m( O) k: Y! @
  </tr>; r5 c7 ?2 I+ Q$ ?3 u& @$ q" u( [
  <tr>
. m5 _1 A3 x. P    <td># @2 v5 }5 Z$ @5 E7 v
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">' E6 z. \; Y, S9 \. ?
  <option value="0">请选择部门 ---></option>
& C+ Q) h8 X  }  [$ e; f<%( P5 {9 L" K3 r7 o- y7 b$ h9 p
    string sqld="select * from tdept";+ h3 z8 A7 a' y' g6 M( D
stmt=conn.createstatement();
5 Q, x* r5 X: d& [% g* @rs=stmt.executequery(sqld);
( B! `8 |  U) e' E' N- A- Fwhile(rs.next())
- j  a  ~9 D' {9 j3 y" g3 u. S( p{
: V% L  v2 ~+ E( N%>
7 X3 Y4 T% s0 |/ A; l& B6 y  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>/ T! u; H; M% l( @0 d: S
<%$ ~9 E4 }5 s) ~: L
}
; I3 h: P, V- J2 a6 b6 P%>
% N/ l" K; y0 b6 F  Z: Y  </select>! W8 Y7 @4 |7 j
</td>
! T7 b6 Z" S8 B/ ?% M  |5 j    <td>
8 P8 e: V9 ~- r  <select multiple id=city style="width:150;height:200" class="bgc">. Q- Y8 v/ Z$ {5 s' \9 P6 R+ j1 D
  </select>
+ t% A& B! R6 ]' a+ [) S0 v</td>
2 b6 E: [5 V6 u- ~    <td nowrap align="center" class="bgc">
. \4 e2 S, x) n9 Z8 G$ h7 `  <input type="button"  value="<<" class="buttons">, l: r2 d9 L( p6 H- o, M
  <input type="button"  value=">>" class="buttons">- w. T. d* L7 T% ^
</td>
1 O5 D3 N' w4 W    <td>
( I2 c2 w+ V9 A" u9 [7 q  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
& ]& n0 V( a' D1 Q# O  </select>
+ M' H+ L! q) j: m</td>
0 E" N+ N0 m* O+ ?) f6 z  </tr>/ Q  b3 }% S' Z) E' ]
    <tr class="bgc"> 3 i- n) m7 U. l3 a
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
" h' L) C3 Q2 @2 ^9 c: }  </tr>
; N3 B% A6 e8 V7 m" e+ s</table>
7 t7 y5 F: X! q" V# Y  o</form>. B7 B& t5 C+ r( U  F. Z
<script language="javascript">
9 k0 Z5 R* P9 M+ E$ e) V//人名移动; o0 m5 T2 n" w  y" {5 Y
function move(fbox, tbox) {
* M- q$ a7 C1 V! a5 B' Lvar arrfbox = new array();
) g% i: B9 m" ]var arrtbox = new array();: f, `! O! h4 h9 @, c; z& e' B6 A
var arrlookup = new array();1 R  L* o7 k0 S7 Q( g" D0 L$ Z4 _" v
var i;. s$ w( X! ?2 o. a2 f1 K# N/ _; ~
for (i = 0; i < tbox.options.length; i++) {1 o  \9 t+ E4 h% a
arrlookup[tbox.options.text] = tbox.options.value;
% z' b" l2 }: s! g8 t0 N  k! ?; Carrtbox = tbox.options.text;& c. W: B/ g6 x2 c* D. U
}  ?& |! u2 s: s9 O' T
var flength = 0;+ w: X" Z/ V% g6 t+ j, k
var tlength = arrtbox.length;8 v$ v+ C  ^+ W$ ~. s
for(i = 0; i < fbox.options.length; i++) {
$ T! _. D3 K) t, ^+ Y+ Yarrlookup[fbox.options.text] = fbox.options.value;0 D2 g  A4 [, Q
if (fbox.options.selected && fbox.options.value != "") {
! Y" w' O) L/ O1 |6 {, V$ Y$ W/ v& Xarrtbox[tlength] = fbox.options.text;
! v& |. J$ m! ~! P2 Stlength++;
4 ~% H# f; j' b% @/ o8 E/ P. c6 r}
  w1 A5 r9 @9 {+ G9 Welse {
# z3 r; f8 e. a* Garrfbox[flength] = fbox.options.text;
/ D2 j4 H( n- G, D" L& dflength++;8 M. m! B( W( Y; q8 u+ P6 B
   }; r( h4 i( i1 b; {3 t' k( O
}
/ ~3 Z+ L2 ^+ p% P$ G. Narrfbox.sort();' ~2 {! x& h0 |: c) u: j
arrtbox.sort();
7 t/ ^+ `2 N- d! G1 F
1 @( ?, a  T5 sfbox.length = 0;
1 [' Z, c5 f0 M+ h, K5 h3 o9 Ztbox.length = 0;
8 X3 C6 U; E: h3 p$ Z4 Vvar c;
6 p5 I: o& ?8 m9 \8 _for(c = 0; c < arrfbox.length; c++) {
1 y( T- n' l# E$ ?& t% B" k7 tvar no = new option();1 r" h- @+ l8 E3 o5 D
no.value = arrlookup[arrfbox[c]];; a2 e9 f) y9 o4 d0 f/ z
no.text = arrfbox[c];
. D) p, a( E8 {$ C, F  h5 h! u+ b1 wfbox[c] = no;' j7 J+ O6 q+ I' ?8 O! r
}* {! C5 v( z# l8 ~3 ?( R
for(c = 0; c < arrtbox.length; c++) {1 u% V! ]- k5 ?5 g0 Y/ B! A
var no = new option();- D# M# l) Y$ b( Z
no.value = arrlookup[arrtbox[c]];# d* ?6 F2 [1 x4 i6 h+ D
no.text = arrtbox[c];+ ^3 W4 O! Q3 V, I
tbox[c] = no;7 |( u6 R$ @: y$ g& @2 r2 i
   }
1 ]/ N3 Q$ x5 h5 Z0 w}  m( _( B/ L. G  D
</script>4 g# a+ E6 c3 Q: l2 r7 B$ H
</body>8 L6 a6 C1 F) t% K. x3 [1 E





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