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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
. T6 q. ]6 M5 s( u9 R7 R         c pageencoding="gb2312". }& p, |& T( x( P) p1 _
%>
5 L. ]1 h0 D1 x, d; |# N, b<style>
' K  r0 S9 \# _4 |# A.f9{ font-size:9pt; }" a/ e7 Y1 S/ H1 @) U1 ~
.bgc{ background-color:#aecaf9; color: #0033ff }* S" z6 b8 Q; Q7 q6 v4 y) z
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;+ }4 f0 R! F6 G! L
  border-bottom: solid 1px #4e7dc1;
+ J# c* v) a% w/ t  border-left: solid 1px #aecaf9;
+ M0 z# p1 J; e/ H  border-right: solid 1px #5679bd;
7 c; g! e( [8 @1 W* n  padding:1px;
$ L. O# I! S, q6 n9 g: R  margin:0px;}% y6 i" O" [- P3 z2 X0 I, h
</style>
% {+ S4 C; ^/ Y  X  ]% E<script language="javascript">7 K; ?* ?6 ~5 q" x1 @
<!--
5 Q$ O1 a  s' I* T; j( jfunction rv()6 K, c" q% n: x' |, B: \! n
{
. l/ h5 C7 m* x, S$ \  var val="";1 e* V" S5 B/ V; f: E6 |$ l3 d4 T
  for(i=0;i<combo_box.list2.length;i++){9 `1 I+ G* u5 X( W' S) l
   val+=","+combo_box.list2.value;
) V3 ?" X# F* u3 @. U  }
! `1 V# A1 V, F, ^8 a3 _6 D2 ?  if(val.charat(0)==","){
; S* V9 B- w! A- w0 V+ g   val=val.substr(1,val.length);
* _" ?: q, R' O( a! `& A  }
0 h6 [7 h0 y6 x  opener.form1.frecname.value=val;0 X7 t$ u4 v/ \/ z! H
  self.close();
! {1 ]5 n0 `0 e2 H1 R}! p: b8 V: |1 Z0 n  b1 @- h
//-->
& `: M; ]3 U* I3 d! I</script>
' M) L% t5 f8 H5 q8 s# ~( j2 ^<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
$ B8 \# [" W( X5 j1 K0 y9 o<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />1 J- |; d( }4 g8 h' u
<%
8 d. F! ~4 [- }  cdatasource ds=new cdatasource();  //数据联结bean实例
3 F( ]6 x; J( l, A3 B  java.sql.connection conn=ds.getconnection();2 v% C/ I* M  g" g
  java.sql.statement stmt=null;
! B0 w/ U2 f# t4 T2 e3 }% _  java.sql.resultset rs=null;
  g8 j4 k: E) q6 l  cdatacheck dc=new cdatacheck();( c% R2 `, N' I4 Q5 k- Z
%>
9 ^) M3 c0 }% R( G5 F( f& @' h<%
) x- t  C4 a5 u9 ~( |" Z% M" W# V5 \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";
- Q) T/ F/ Y3 lstmt=conn.createstatement();1 E- r& }+ d# }9 U3 p% h/ G: y- R
rs=stmt.executequery(sqlu);3 ]+ J" X  M$ s. B
%>7 Q1 x1 _/ }. M: z
<script language='javascript'>8 K. W8 L: |: ^
arr = new array();3 t+ O7 \& G- W/ {  M7 o$ t
<%  int temp=0;7 s$ a3 t. P+ [5 x( G2 f, }
while(rs.next())
2 ?; P4 d  `9 C: p! I{- d  [# J' r3 S+ B4 |: T
%>
- l# ~9 b$ Y' tarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
8 `! g/ ?6 }  g( t" ~) a& v* m; }<%
2 ~8 q, Z) x" d" I" o* I# C; Z5 }temp = temp + 1;
9 }  U6 F" B1 t0 _$ X1 N}
3 q' I2 C2 Q; }* T7 O2 y1 L# _$ ]) g%>; Q4 k% A2 H9 C1 _+ r) }: H
temp=<%=temp%>;) v' s# i+ _6 _& F/ j& `, k1 ^
function changelocation(id){ ; b5 V3 c$ B7 Q4 k
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
% X% u% f* w' G  b1 J. ~var i = 0;
0 T1 z( E0 E7 |, d+ `! w6 qdocument.combo_box.city.options[0]=new option('-------','');
3 L& h% J* Y  S; tfor(i=0;i<temp;i++){
. P1 e8 }8 d' w: a: u5 }if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
; n; e: l( P( F$ a, L; U* gdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
% @: j; v; S) k) P% ^& |- Y# Q- D5 [0 s}
" n2 S) @+ d! j! F" m* o1 Q}   ~" T7 x3 h, A* U" }
} 7 k* W: t2 ^2 q  d( ~1 t) x9 j
</script>" k" t+ ]. p# L9 u
5 b/ k8 C* ]2 a7 L5 Q* T0 i6 V
<form name="combo_box">
+ Y$ X) k+ R& j9 }4 e<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
8 x! _- T9 n5 X4 e% m" q  <tr height="24">4 i3 y8 u. O0 W8 T; P
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
) _) R: H) t/ u8 U5 N7 k    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>/ W9 K1 i  F" i/ t
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
/ u; [! o5 @" T/ X: p) G" E6 N+ h    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>+ B) z  |$ d# [8 f; s
  </tr>
8 U7 Y/ F! B7 b( V, K1 }6 k  <tr> ' m: c% v8 R3 ^9 g+ }( w# @* P
    <td>/ |: @8 }0 P9 y
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
, Z! g; t6 `- D, D# T: \7 \' E  <option value="0">请选择部门 ---></option>
; Y  G, Z5 V. k# g; p<%" U& T5 L8 s  b. V
    string sqld="select * from tdept";( |. w- g- k: S0 x1 v( `: E
stmt=conn.createstatement();% n! V0 f% y! o; {0 [
rs=stmt.executequery(sqld);
2 l' x2 K( a# e- [' Ewhile(rs.next())9 x( z) Q2 T6 R" W
{
+ \2 c* [) p& h( y0 t' h% H%>
8 I1 z  k- i# P4 x+ n5 K  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
2 ^" t8 Z) H2 X$ a! ]<%5 \; L$ B$ k% j! y! s
}0 ]2 M- f$ A& h: V  r# |% Y, h
%>
' k5 R1 Q% n* Q0 T/ ]  </select>; M: B- d, H6 f$ e1 B+ W4 @
</td>
- G3 G3 U" m  }3 P# @: w    <td>
* P" t3 E7 y1 P  f  <select multiple id=city style="width:150;height:200" class="bgc">
( `6 S6 e( q# g, ]' A) Z6 B& y  </select>
; m9 X+ }; \$ ^# h. x; Z1 [# c</td>
: ]  ^2 ^. ?9 T' U0 S9 k* Q    <td nowrap align="center" class="bgc">: o7 M+ f/ @8 D; u& k
  <input type="button"  value="<<" class="buttons">
8 s  }7 l3 b* x* `3 x6 v  <input type="button"  value=">>" class="buttons">" o: Y' j) f1 n
</td>
, ?( ], E( c) a- Z/ P    <td>
' \+ R0 C, H2 W3 D  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">1 N% A( H* N* Q9 s, \
  </select>( g* k% `0 w) N2 V2 h% ^$ ]6 K
</td>) q& c% ]4 ?- E5 `4 S* z! ]
  </tr>% Z% J% g8 N9 f3 K+ }, h5 h9 ?
    <tr class="bgc"> 8 v6 q* u5 W8 J4 K, q6 u
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>: n) z3 ?  ]/ \/ {  u+ G" o
  </tr>
( m( [. ~6 ~1 Y( a! t6 _</table># ~; [4 {, v; [0 G" P% a
</form>
" |( c" W. w' W7 c( A' s<script language="javascript">; }- ]6 W) _1 E& K) Q2 Z
//人名移动; ?# C% N( t1 d' ~
function move(fbox, tbox) {: J0 V$ q  B  |0 G# N8 w- n
var arrfbox = new array();  \" L6 l. K4 Z3 K9 J- ^+ P1 V$ A
var arrtbox = new array();7 R. [' Q: `8 B* i& q
var arrlookup = new array();  j* L, t) R, `
var i;
; X: `; ]0 c" K1 hfor (i = 0; i < tbox.options.length; i++) {
$ I. X$ Q4 J# O* ]  K7 L, d/ Qarrlookup[tbox.options.text] = tbox.options.value;$ C) Y% }0 j4 C
arrtbox = tbox.options.text;
7 I  H: m9 F- I1 O- F3 ]# C) I}
  c' O& h, R* L5 O" xvar flength = 0;
5 w2 n$ I  O) }2 pvar tlength = arrtbox.length;  ?6 `& A3 `% i
for(i = 0; i < fbox.options.length; i++) {
4 H7 z- e& Q; |$ F. d8 Qarrlookup[fbox.options.text] = fbox.options.value;2 T5 q7 f  C% J1 x9 X) B( n
if (fbox.options.selected && fbox.options.value != "") {8 E4 [2 _* L3 v0 r  E! b
arrtbox[tlength] = fbox.options.text;
6 P) L: ]$ t/ ~* p7 F5 m$ Ntlength++;
5 ~# ?' r+ D- `6 a}
! ~3 Z2 v* l( r( V6 m' delse {- [7 A( H, Z  n# K
arrfbox[flength] = fbox.options.text;5 H( u. _" Z7 A% T4 f) C
flength++;
1 U2 m0 I9 _( s! ?2 T   }
( ]0 K7 j. U, C$ }6 b; g7 Z}2 g( q/ {. G. U+ M+ `8 L
arrfbox.sort();9 n( b# p- v3 B7 U8 z0 p
arrtbox.sort();
& n$ x! f8 E7 C- H/ K+ b" x" W
1 ^' ?% H6 g, h: u9 d) Z3 |5 M  B: dfbox.length = 0;
6 G* A+ O; U/ ^# @tbox.length = 0;
- |4 N; K; s7 n2 s7 F3 c1 W: Svar c;
1 g3 R4 ?, t, f; }) g/ h2 Dfor(c = 0; c < arrfbox.length; c++) {# M. t( \: ?* S
var no = new option();
$ z* R) H: U: H8 W  Q" }/ [no.value = arrlookup[arrfbox[c]];, k7 Y! p/ @, i
no.text = arrfbox[c];
- h( Y% a# t. a4 Tfbox[c] = no;) a, K, J5 L% `/ \( C" O
}
% @4 ^0 Z5 l1 d" L- ?# ifor(c = 0; c < arrtbox.length; c++) {& y6 e0 z, ?! `
var no = new option();
' J) Z( T4 K+ J- l- y  L% nno.value = arrlookup[arrtbox[c]];
. B2 H4 H  E6 y# \# tno.text = arrtbox[c];
6 g8 J7 u, r! d7 ]1 I% k2 Wtbox[c] = no;4 z: [2 n( a( x9 B2 [" E
   }
) f+ F! @+ a" n) e}/ }* e4 O* d! y- K/ Y
</script>7 F# E4 M% }/ V6 p5 e7 c$ P
</body>
* S2 l- D$ o0 I

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