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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;", C- L7 G+ j0 ^
         c pageencoding="gb2312"
4 \/ e0 Z' L& e# a) c4 S! P' `%>  |$ u" |( l4 d3 e
<style>' B* c) @  W1 Y$ X* w5 [
.f9{ font-size:9pt; }% R- s  g: Z3 I: C" _5 b
.bgc{ background-color:#aecaf9; color: #0033ff }
7 [' p3 L) h( e3 w* O.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
: W$ u( v' I9 {/ s# I/ K* V  border-bottom: solid 1px #4e7dc1;
. f' I: q# ^+ U& }1 ^  border-left: solid 1px #aecaf9;
; Z  F- N7 g0 @7 G  border-right: solid 1px #5679bd;; h5 \8 ^9 g8 w2 ~- P3 i' r" S
  padding:1px;' O. _* I; h. {
  margin:0px;}9 i% c  t7 @" [( c
</style>
, x" o% f4 E& Y! }+ e9 G<script language="javascript">
5 m& }7 _+ C# K<!--
  S0 I9 O& R3 w! o3 M% T. ffunction rv()1 a  |5 f: |% R  Z) _' A7 s
{
- c2 y; g' Q4 U/ @6 Y+ ]  var val="";3 q- x6 D; `; c, G% w
  for(i=0;i<combo_box.list2.length;i++){" w: n4 d5 j' u( c
   val+=","+combo_box.list2.value;% a1 y* ]3 P3 _7 R& Y
  }" b) h: n8 X4 B/ \: j
  if(val.charat(0)==","){
8 j2 T- S0 ]8 Y; M4 j   val=val.substr(1,val.length);, ?/ h6 x  t4 t$ L7 J4 n
  }, v3 q, a/ q; G
  opener.form1.frecname.value=val;
; o- i1 M: q* h6 x+ c  self.close();
. H$ o5 i% x3 S! }+ Y" g}
  O0 C, f- g$ |0 f6 e' d//-->( _) o1 k1 k0 h
</script>+ I; Y; P. `* `5 {# {
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
. s0 g% ]( v2 w! W* T& ^0 b<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
1 d% x3 b/ e% ?<%7 b* t) g" j& t+ u1 Q% w' s
  cdatasource ds=new cdatasource();  //数据联结bean实例1 C: ^/ Z% F6 w0 J4 p
  java.sql.connection conn=ds.getconnection();
* L0 z0 S8 X' U4 p. c  java.sql.statement stmt=null;1 J% Y  Z0 z( d2 q2 }. a
  java.sql.resultset rs=null;
4 ~; f# ~5 t: R+ C2 ?/ k  cdatacheck dc=new cdatacheck();6 `, X6 g6 p# R/ X. z9 h3 K; I
%>3 M2 ^8 p* [. M* H- B! Q" z. m
<%
  W2 u6 r5 X0 B* S( y# Y3 {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";. {; }' u* d' c/ k
stmt=conn.createstatement();
# g2 W# n( t% n" grs=stmt.executequery(sqlu);
' G3 a, ^* x* H; I1 n%>
1 {" k, O' I, N, c, Y<script language='javascript'>7 @5 N6 T% a$ r' m
arr = new array();
" c) Z9 p* j' S) G6 x<%  int temp=0;
- V1 l8 u1 K. J3 x# f1 twhile(rs.next())9 ^4 X& B; g$ E) y* j' O( s) R
{1 }; v. g- C% r1 f0 d
%>
  Y8 b$ Y5 B0 T9 v9 Warr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
* |  v5 H# Z! @<%. f4 x) y4 J; {* B
temp = temp + 1;) w( x* t" z% m% X& e
}+ x' _& ]; w" l( i0 V! v
%>
7 o$ Z/ p  m7 [$ Ttemp=<%=temp%>;7 u2 U5 l" J3 h
function changelocation(id){
  \& L- P- J; Pdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 8 b8 k3 U4 ~7 Q8 p9 W5 U6 p  L8 r9 q
var i = 0; % b( C. I& l0 E" @% i: `! b) ]
document.combo_box.city.options[0]=new option('-------',''); 3 S( t  l& c3 ?, n; S' D& }' g
for(i=0;i<temp;i++){   N- H# R- _, ^2 I9 o! k( B
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
) P" ^' x, C/ z1 `5 e# _: P, J, c8 Cdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 1 T' d. K' \0 x7 F4 W! S
} 5 g1 @* R. c! R, k; b% V
}
! l  h5 l+ L+ J, `5 r, `} % `- B0 w4 j$ b9 F7 f8 B# h
</script>
& l9 k/ O; j* s- _) V1 G, ~  E  ]8 C+ e# F# P/ J  B, p$ |
<form name="combo_box">
. g8 y3 S, F2 A8 Q<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
8 v. L) M% ^( N% n! t7 Q  <tr height="24">
! Y: |% G' A7 U; C1 s    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
, M0 [9 U+ G; D1 D    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
$ y' p7 F9 x' k; T- Z    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
+ @( T& I( x# x    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>' P# q' G# W5 H  y% _8 I
  </tr>
8 ^4 i1 a% H# g  <tr> ) l- I* P( y3 t0 n$ {
    <td>
0 @& O* v* Z" v* A# `: F6 [  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">0 u8 X5 U' p0 r. u! C  c
  <option value="0">请选择部门 ---></option>$ O3 J: W8 m4 o# ^+ a( L; D
<%
5 }7 V$ L) }4 E  o  C( B2 F$ [    string sqld="select * from tdept";% P( z- T+ N& P7 N6 c0 e
stmt=conn.createstatement();
8 r8 J3 [$ V) u" U7 _rs=stmt.executequery(sqld);$ H. C8 B3 _8 O
while(rs.next())+ l( {6 w" F6 {" `
{
2 u4 V, r! T) c+ v# q%>+ I$ X3 Q6 L) ?8 r0 D
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>' r/ n. v" g0 v  M7 n
<%; }4 ~, B6 V# v7 a* b( U
}
% u) y; {- @5 a* s  \9 T  W2 K%>
; }$ d. `7 N) W  _" V3 o4 t  </select>$ k- L( E( \( M+ y. g: c% ?
</td>
/ t* k2 j2 ?% c, g/ P  E    <td>2 ^1 T1 O8 V: @5 w; T3 b
  <select multiple id=city style="width:150;height:200" class="bgc">
5 d; `3 h* i3 S5 \) o6 Y2 m) f  </select>
. U  L0 U1 L2 _" w8 Q9 L: H2 k# y</td>1 ^; E' ~' {5 @# O" e
    <td nowrap align="center" class="bgc">1 G* q: E  ]6 |' U4 I
  <input type="button"  value="<<" class="buttons">
# ?/ c6 ?  k4 l. \) A; x) j  <input type="button"  value=">>" class="buttons">
1 I  X" _  T8 F  ]4 o( `/ N9 o</td>
7 g5 P. v5 e# W5 H% i, ~  p    <td>0 I7 v/ Q  O& B8 h- b1 Z
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
. d6 n9 W/ ^8 _" D. J. _' X' Y  </select>
+ _, q9 H# }" p/ P  F</td>
6 U% u0 b: P1 V4 d( e& S  </tr>1 V) ]" d$ _/ P" `3 P1 x, Y
    <tr class="bgc">
' m4 ^7 X# i& r; S) ~9 Z    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>1 f" r9 W( a. e- }
  </tr>: p( n6 M: k* B- ?7 R
</table>
0 s' Q( N* ?  [' K</form>
/ o1 Q/ S7 ^+ J, F- j<script language="javascript">
1 c( v: ^& c" U2 q0 t4 n9 ?# S  o//人名移动
5 w( ?' f# T# `. sfunction move(fbox, tbox) {
% c$ ~: z6 F! d) D( s  O" hvar arrfbox = new array();! M2 r9 u8 v1 T/ U
var arrtbox = new array();
4 ?% J3 r; D: @7 L* dvar arrlookup = new array();
. h( [: R2 o$ M$ lvar i;- \) O- r# @) }& S
for (i = 0; i < tbox.options.length; i++) {; q3 W7 y1 b$ W. }. e0 K7 O
arrlookup[tbox.options.text] = tbox.options.value;
) g" R( N. ?; m6 yarrtbox = tbox.options.text;
& Q# a( U3 y0 B5 e- H) E& U/ d}
; _+ `1 b1 q2 [' zvar flength = 0;
! t' O; x$ _$ ~8 q/ _. |4 A, a9 ^var tlength = arrtbox.length;, f$ a0 c; S, ]; r% H
for(i = 0; i < fbox.options.length; i++) {) f: ?, [" S$ o5 Z4 m
arrlookup[fbox.options.text] = fbox.options.value;
8 q/ i2 X0 W* ]  f# b. L' ?- qif (fbox.options.selected && fbox.options.value != "") {4 S3 O. ^) h3 k2 U9 ]3 w
arrtbox[tlength] = fbox.options.text;
' n) v2 s1 q! ]$ b5 G/ j; o# Ttlength++;
+ v) K  T% \2 w& `$ r" C; P4 L* L}+ L8 B- o6 j( J8 o) ]% H* ^. i
else {
4 x0 h. D9 K! S" Aarrfbox[flength] = fbox.options.text;
* I- `5 b$ h# }6 f- o( z/ ?flength++;
' V9 _( o) O& t) A; r/ B   }
2 E6 n2 e$ L! t* o9 ^- r- u8 R4 ^}* H# Y% k  w5 g6 |1 }
arrfbox.sort();4 L. U! e  F6 F* s
arrtbox.sort();
6 \/ |3 f' W. o. ]. U4 ~
! c8 }2 \. t  y5 F% W0 D, u, Y6 Mfbox.length = 0;
+ Z8 A) a6 U1 g- ]# Ztbox.length = 0;- W1 z1 ~2 G6 c: P# {$ m7 w
var c;
0 J( n9 A0 N. X# K" cfor(c = 0; c < arrfbox.length; c++) {9 Q4 ?/ n4 ^* z9 a1 W8 k
var no = new option();# b1 p  y0 h) `. N- l. X
no.value = arrlookup[arrfbox[c]];
/ p) h: f0 P' J" wno.text = arrfbox[c];
1 k2 ^9 G! d: o- f9 C% Rfbox[c] = no;
/ _% f' o! ^+ X. F# j}+ v, L& ^$ o- l7 w
for(c = 0; c < arrtbox.length; c++) {2 t8 L* q# e/ X; o! W
var no = new option();
. u3 S2 Q* j1 K% t2 h7 g  ano.value = arrlookup[arrtbox[c]];
* X7 g( I. Z: u$ Z! Q. lno.text = arrtbox[c];
7 N) c" l2 l3 e, k% t1 etbox[c] = no;, H5 S! n. P0 I( O
   }
" c4 I! w, @7 `; `, B/ |0 o# [" P}
7 C% V) `% f( ?  p$ d2 ^</script>* E) k, k7 D2 ^3 ?
</body>
2 }8 l% P0 |$ _% U, X; B3 n

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