返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
& _$ L( v: d- ]0 t% g         c pageencoding="gb2312"$ t+ x( q* r) Z
%>
1 `) j( V7 k+ Q; l1 B) q<style>6 K6 h; o* f/ m5 z) K1 `7 b1 `
.f9{ font-size:9pt; }
/ ]' N1 e* C- Q6 r.bgc{ background-color:#aecaf9; color: #0033ff }
; D. F$ S3 f$ g2 c. ?.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
+ Q3 N  T1 \( G( A+ c7 ?8 w6 o4 ?5 u; J  border-bottom: solid 1px #4e7dc1;
0 o- S8 r4 ]# o" c  border-left: solid 1px #aecaf9;& [3 y* k( R/ y- s* l
  border-right: solid 1px #5679bd;7 P* @/ \) J8 r( P+ b* @; g9 G5 q
  padding:1px;
& P+ `! N$ i7 T, |( A* j. B2 u  margin:0px;}5 u+ ]5 F) D% D& {( @
</style>7 \6 I- i- I/ B9 T
<script language="javascript">
1 b" w7 B1 I, p/ a* g<!--9 \/ Y/ c( N; N" B* T% ^( C
function rv()
0 k9 D. C$ ^/ Z0 ]3 |1 B2 x( K" |% _{% b- k( P1 u: N+ A
  var val="";' q( b3 c! r8 y
  for(i=0;i<combo_box.list2.length;i++){4 G$ U( x6 {) l8 t& G
   val+=","+combo_box.list2.value;9 q1 H; ^5 ?" K
  }4 k% U/ R. {; `  c4 R8 _) H1 J& ?
  if(val.charat(0)==","){. \9 S! V& B* [
   val=val.substr(1,val.length);3 |3 W8 R" {3 A! i! z5 d$ Y
  }
: }$ C+ n9 v9 p) k  opener.form1.frecname.value=val;
# \" s: _7 x0 f0 _  S) ^% e  self.close();+ G9 J0 O4 j  O
}. C, [$ T; `+ c" o2 j
//-->
4 z4 P* T0 Q. k! m# ?</script>
4 M$ A& |% @6 h4 |0 k9 ?6 Y9 i<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
' |: T7 A) F; y: j* |) I<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />4 U) X& X5 z6 f) v. i6 a
<%. b/ `; [9 @2 k( d' u, F1 l
  cdatasource ds=new cdatasource();  //数据联结bean实例
. \! ~/ \3 I2 P" H0 g  java.sql.connection conn=ds.getconnection();' Y3 }  O$ j! l( [6 b3 O
  java.sql.statement stmt=null;1 K8 l1 j9 ?. |
  java.sql.resultset rs=null;
3 {: v8 A9 V8 R, Y+ E* ~2 y  cdatacheck dc=new cdatacheck();7 K: r0 `2 M/ @# ~# D8 ~
%>: i8 P! T* Z3 z8 z6 q
<%
8 z  Z9 d# k$ g% ]" v- a4 L2 wstring 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";1 S3 T+ A7 h. y! z, p0 K
stmt=conn.createstatement();
2 J, B( G; H  s; Q' L. Yrs=stmt.executequery(sqlu);
) K4 a& B+ L( v8 s0 s%>
0 Q0 @+ j# }0 P0 n; f9 V5 i<script language='javascript'>0 f! o, `2 h- h4 D- V$ m
arr = new array();
" _6 f0 V! f: C% N, P  f' [4 N4 i<%  int temp=0;
- e" c$ A- t( mwhile(rs.next())" C& ]3 n% `7 Z9 g
{
% U9 e9 d0 f# n, P, A%># R. M9 D$ T; W) u) Q
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
( R, l3 m; [( a+ P<%
- Q) H4 E' W' n0 @temp = temp + 1;
4 P2 S* t* H9 I4 J}
0 Z, C% D' i& l, k; n%>
* M+ M7 h( H8 J6 Z: o: btemp=<%=temp%>;
5 G& K1 O4 Z4 s! Z3 ^' @( Yfunction changelocation(id){ - N) B* ?3 T+ D. j/ E2 [3 H, [
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
3 X$ g/ L0 y1 T  e! Yvar i = 0;
  d2 N3 \/ W) E& O/ [document.combo_box.city.options[0]=new option('-------','');
0 P' a1 p+ }, b4 L- ?- Z" ^for(i=0;i<temp;i++){
7 F) V5 ^. Q/ D# M, L& qif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 1 B9 r* d7 g$ z7 ]. d) h2 W! P' E
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
! U0 `9 }; p% I. P4 H6 U}
( S! _6 F0 K* l1 Y. x}
4 J4 _* P8 x! S2 e0 H, f8 r! y} 0 c( ?- F% Y) ^( A3 s9 c/ S7 T% X
</script>  H4 W* T! n9 \6 Y& z: y
0 K4 b0 Z* ?+ B& i' q  ]9 d
<form name="combo_box">! [6 v4 M9 F' S( v
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
. [9 w% M0 i' B2 }& e8 q  <tr height="24">
3 [2 d. y2 A5 K' O- U* _    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>) g8 t$ o$ {% |% G) f$ t
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
& I: S; @. w# R2 l: @! B    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
- f8 J$ B: \' w: q/ R( Z7 u    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
# P! h+ s- c0 w2 @( L3 Z6 S  </tr>* G4 s) M0 k7 b3 Z; @% ?( X9 b
  <tr>
6 D3 h" S! \2 s# n+ j6 m3 ~    <td>
' b* k0 P: K/ j3 ^! G5 X- |. e: G  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">/ n7 ]! h% Y+ b3 y
  <option value="0">请选择部门 ---></option>
" K4 G1 B1 j0 W8 M" b" U5 D7 f( j<%
0 b- Q; J' E! C" c4 n. Y    string sqld="select * from tdept";% L0 L4 b. x- S# c
stmt=conn.createstatement();
- T$ W7 v8 M- Y1 j6 e8 Prs=stmt.executequery(sqld);/ w" s; T& P( b0 Z5 L* [( O# ?: z
while(rs.next())% z# }& o: }+ I
{
4 @2 _1 z& V) }, p) T%>
1 L/ ^$ S4 [% [  ]3 ^; w  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
5 ]8 w! P- W0 E* |<%2 u, I2 K$ r+ u, d3 t
}, m' U& J$ q1 C+ r. f
%> & {, c  Q3 t% k# `* J0 j" W
  </select>
; Z" G; t6 R9 v3 `</td>) H- z- }* q4 c& O  \+ @
    <td>: g1 j7 @" K; P. r  ]9 _
  <select multiple id=city style="width:150;height:200" class="bgc">3 R  p+ L  R+ t0 W( i1 K
  </select>
8 `/ P& [- _" U) C6 ?</td>
0 t) S; \, ^1 }% m8 Y4 E! W    <td nowrap align="center" class="bgc">
8 f% ^( s' Q% J$ J4 {# H  <input type="button"  value="<<" class="buttons">
- G# v' |2 V2 R! Q$ E& ?" T$ H0 o  <input type="button"  value=">>" class="buttons">
; A+ R, q* Q, `! w* H) N</td>" ?. b  b/ O" T7 q
    <td>& [6 T, P0 i1 b7 y+ w' w
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
/ h  H0 y$ E. F2 R4 W  </select>) X& s; _) c) c) B5 Y
</td>9 W" e9 l; r+ ]5 }0 I& {
  </tr>7 @" o3 h" ?/ u" D; y* ^! ^
    <tr class="bgc"> # x" Y0 S2 F2 i% E
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>& B1 n" [/ b3 h8 h
  </tr>% {# g' i$ V" u  e- ]/ B# S4 u- j
</table>2 E7 \* s6 d$ Z* k6 j
</form>9 ]8 N1 Y1 A5 o/ @" R9 g0 z+ j
<script language="javascript">
( o" ~+ U7 a/ T3 b6 P//人名移动
) K& R& }' [; f3 K. a  W* c, H2 Lfunction move(fbox, tbox) {7 M4 N5 x2 k& ?5 ^" P, z$ o
var arrfbox = new array();0 X  {) O) R( @, ]; m3 [# b
var arrtbox = new array();/ F2 c" }  C/ w" B; T
var arrlookup = new array();9 m5 K3 L4 L2 E" W8 l& a
var i;# G' Q- b4 h6 p: t" D
for (i = 0; i < tbox.options.length; i++) {
. L2 j% q. c+ Y# z. [7 narrlookup[tbox.options.text] = tbox.options.value;- M1 Z" z8 ~7 K
arrtbox = tbox.options.text;0 i2 S+ p2 a5 I( O' }4 h5 k
}1 b7 o8 [* Y2 r9 v/ c. S
var flength = 0;1 r8 o8 M" q0 x* {) h; C
var tlength = arrtbox.length;6 @0 N; m. d9 V6 H" }
for(i = 0; i < fbox.options.length; i++) {
3 K1 D0 ^) r# earrlookup[fbox.options.text] = fbox.options.value;
; D' e1 X$ V5 p# T8 ~1 ?$ jif (fbox.options.selected && fbox.options.value != "") {
- o/ P0 P! h4 w' Z' z9 F. warrtbox[tlength] = fbox.options.text;
* a1 R% o$ d% J4 N+ Ztlength++;$ S) r8 q0 [+ e+ V0 C# H
}% J) m4 h1 @( `9 w6 p. X8 [& m2 F! v
else {
* g! o% i0 t9 @. s+ D1 Karrfbox[flength] = fbox.options.text;
& _9 @( K' N! T7 p* p. v6 sflength++;
5 V* N- u/ x5 p' N   }  f( h0 N  K2 A1 n7 Y
}/ |/ E& `, J  v4 j$ K. C
arrfbox.sort();; e% C/ X; R3 H+ P. }, z- f1 a6 V% ~
arrtbox.sort();
1 n6 v7 D: [2 F7 J' |/ h8 F% J: F9 e' U1 y2 l& E: A
fbox.length = 0;
" }2 p5 c# a# s6 @* i  V* {0 a* L) M1 htbox.length = 0;+ j# b# K" k7 M9 l' h* l; [! a
var c;3 `- O' Y% T  w0 @: t' ?# m
for(c = 0; c < arrfbox.length; c++) {0 L/ G9 r+ P, p  j5 r2 k
var no = new option();) g6 P% ~. I0 o& q1 ]" S) G7 J
no.value = arrlookup[arrfbox[c]];, _' R  {+ g+ I2 P. T! [  x* |5 e
no.text = arrfbox[c];! F) u9 H* Q) M
fbox[c] = no;- t1 b; V3 [6 N4 o8 a
}( g2 |! K3 Z0 D
for(c = 0; c < arrtbox.length; c++) {& _$ o1 _' X1 b' [9 N- G/ \
var no = new option();
: L% E0 ~% i% d/ tno.value = arrlookup[arrtbox[c]];
# {- I2 m1 S7 jno.text = arrtbox[c];
% z( m" y, @* `5 `# H) t; d0 B; gtbox[c] = no;
% ~" ^) L" j9 _4 y/ ?4 q   }
" v& B8 _+ C' W* ?5 G- q9 o. Y( U}$ X2 w) i& K8 i7 T/ t
</script>' `$ |3 Q1 z: f2 h) q& `
</body>, a3 f, [& @; G, [

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