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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
# Y7 ]3 f* E! L; V& p' ]+ E* d% Z         c pageencoding="gb2312"
; _$ |0 L; U3 x%>
5 J" O6 O, e  I/ i* a<style>6 P. m6 X! x1 H" d. l6 O" v
.f9{ font-size:9pt; }4 ~  S; i4 Q/ O& s
.bgc{ background-color:#aecaf9; color: #0033ff }
; e! L% u5 j; t" Z; M.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
; A$ e  A/ i. k( f/ M, e4 y3 V( _- y  border-bottom: solid 1px #4e7dc1;
' D4 H: S* J- e" d  border-left: solid 1px #aecaf9;
1 ?+ J, R2 u1 U) A  border-right: solid 1px #5679bd;3 k+ {8 B0 z) {5 x  m" F; K
  padding:1px;
7 s* u' [# V+ U' G7 o  margin:0px;}
% B; ]/ Z9 P0 R0 U* p; W8 Q$ F' W  u! t</style>
/ @# H# ~6 d( [% R( I1 R<script language="javascript">
* ]- w9 O, m+ i" g( d' k: P9 s2 t<!--
& C- v% G2 V; N3 F4 pfunction rv()- H4 q) J  E0 Q0 \) S/ A
{
: [" ~0 A* r7 R# b  var val="";6 h( v. l0 Z9 e- p7 F
  for(i=0;i<combo_box.list2.length;i++){
- ~( N6 h) [. m- x5 A+ [8 P# M6 f   val+=","+combo_box.list2.value;
3 t  @  q& z9 `& R! f  }  k' {" e1 p1 S3 b
  if(val.charat(0)==","){9 n5 A! |) ~% z# f; S1 E
   val=val.substr(1,val.length);
: w  o% f+ j1 V) e$ a% O. @" i  }
/ S; k5 @+ V9 D9 X, `. M4 P  opener.form1.frecname.value=val;& n: W5 E$ A" L& X! i6 y
  self.close();9 D6 o' ~+ o! c
}
: `; |4 X4 e4 U8 m" E/ l* R//-->0 f: E4 B7 U, \2 i3 u
</script>
  W/ N8 @1 b  \- V<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">) m4 l6 l  o6 i% G; ~0 y% v  W
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
% P# n- [3 z7 ^2 O% A6 Y  U. ]5 L<%
/ Y3 v- i, A3 @1 P3 r  cdatasource ds=new cdatasource();  //数据联结bean实例( V* T$ e' l: Q( ~$ @/ R9 }) f
  java.sql.connection conn=ds.getconnection();. }1 C7 V, e( g( J5 d# F* i
  java.sql.statement stmt=null;& B- G# A' L- N7 u& \
  java.sql.resultset rs=null;3 o( C5 P( B* z0 |4 T: V
  cdatacheck dc=new cdatacheck();4 ]4 a6 _5 a) i( A4 c1 F
%>
4 D+ m9 C- i% g0 O<%7 k" P' d* s+ v: [6 S( {$ c7 @
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";( a8 J% Z: x  p  z* k6 t+ Y
stmt=conn.createstatement();
: w. Y( e( N, y9 S: |2 N8 M5 srs=stmt.executequery(sqlu);
9 K  Y! F. m, I( j$ K%>
3 T5 W. s) R, Q, |4 c8 ~<script language='javascript'>
% x- }% D6 r# m$ E+ O" S) Harr = new array();) ~8 B. n/ Q5 O7 }5 _
<%  int temp=0;5 f! F7 D2 B8 V) q4 s9 C
while(rs.next())
7 F$ T+ [+ A* J3 o{. P/ W8 ~6 M& }2 @9 w; J$ v
%>
. g6 {, r: T% ^$ F2 V) H4 @arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");/ {/ e7 h0 f4 k% n9 S
<%
: A; N# A5 U7 s* x2 mtemp = temp + 1;
* ]) J  T/ [6 m9 H) w2 s}
$ t4 w9 x" Y0 T%>
6 C# t7 Q2 a: ?& Q0 M; b  A9 ktemp=<%=temp%>;) a0 j3 o' T- c7 Z3 r5 k* [% M
function changelocation(id){ # v# q( ?6 }! |5 }$ O% u
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
) g& ]4 j9 u" k. u3 Y' f! C1 `var i = 0;
% ~4 J4 T7 L( w3 M5 i+ O. j! Udocument.combo_box.city.options[0]=new option('-------',''); ! h6 ?* Z- z4 U( Y
for(i=0;i<temp;i++){ ; U# m7 S7 D" F/ d
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
/ O/ A  m  @' k! P, T8 i* e* \# a  w7 tdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
* C/ j& H. c( E} 4 o' u( k% T; e9 C/ {
}
' q1 o& i/ y- D6 p7 l}
6 x4 ~: [5 s  M8 r- `</script>& `" P- A: e( ^9 E$ m0 Q% o
; E" |7 R" B5 m( w4 b1 W4 i" p
<form name="combo_box">
: R+ ^; O0 ?& D! J; N' u<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
+ U: n; n+ w5 F. P  <tr height="24">
  R7 P" J2 s, s    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
# t/ X4 _6 m6 X/ g/ K7 [! ?  [9 o    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>6 \- h- E; Y- p) Z: ^
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
7 a) @) ~- q# ^# T; L9 p) y    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>, N  P2 k: }7 [9 r; P+ V/ a2 b5 k
  </tr># R" \* U- ~3 \7 @! h% @0 C
  <tr>
  o/ I$ ~# P8 D# m  b6 \7 ^! X) U* d    <td>+ k' B% P' @/ P7 u
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">  ^# o; m& l" k/ O( h/ A
  <option value="0">请选择部门 ---></option>
9 x; C$ v9 s& p4 T" r# q* x<%, D2 y! ?5 H8 d+ {# n/ v3 C. H
    string sqld="select * from tdept";
' C/ r& Q% I% E) P% k% v, zstmt=conn.createstatement();8 m: M: e$ G8 A+ x7 c+ m% s. K
rs=stmt.executequery(sqld);
0 \' F$ g9 e5 A, qwhile(rs.next())) S0 }# g+ q9 P% k7 @; N$ ~" F
{/ e( x5 P- I6 i+ v' @
%>
, p  C' m9 t: q) @: D  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
* v2 C3 F5 m6 }# o1 }8 Y  Q<%
0 J. h: V- F- ^2 C}" X  J. F( S! ^
%>
' [+ y# }5 M$ y- T% M+ r  </select>7 w: a+ _# z) [# F4 g' O
</td># c6 D- @0 _& y- Y4 g1 U
    <td>7 z% W- {- X, h$ R5 r0 J" i( P
  <select multiple id=city style="width:150;height:200" class="bgc">
5 s9 q, s0 |) r/ V" [  </select>+ i$ |6 j6 R1 Y& j
</td>8 O% }2 {" K* {8 g4 U+ `$ Q
    <td nowrap align="center" class="bgc">
3 Z/ x$ U0 q3 M6 q/ ?  <input type="button"  value="<<" class="buttons">. @7 u4 S" L: H6 \" _" h! Z
  <input type="button"  value=">>" class="buttons">
. a% k. o% G$ `1 b' n5 n</td>' S) c) {# L( a! e4 ?/ z( o4 R
    <td>
- M7 b) J6 V/ W7 r  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">" P0 }/ z. p( v+ j) w+ D& h0 Z" D
  </select>1 I  t) E  U6 l
</td>
* D, {7 @& e" ]: i3 a1 x  </tr>
/ f( ~1 {/ o; W) p# N. @    <tr class="bgc"> 2 S$ A$ E4 E% R/ z
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
7 t- d9 A+ f3 L" u& v& u  </tr>
# [/ s5 `' j/ Y</table>: T% J! R, w/ Q; C" N# Q# C
</form>+ M2 @4 L! D3 X5 B3 S& s2 _
<script language="javascript">" w% `* m8 u: n- v# b8 {
//人名移动! l! f4 v0 X& N& L. `* {6 m
function move(fbox, tbox) {
# J0 p1 |4 {7 g/ ]' w& l: j  s: X3 Evar arrfbox = new array();( a' }) p# J: }8 i  \* R
var arrtbox = new array();
9 u: R: g3 J% H: ], \: bvar arrlookup = new array();
$ @1 [5 k! s# @2 J/ Qvar i;
8 y: K$ r6 Z( E9 D/ Jfor (i = 0; i < tbox.options.length; i++) {
) x. p* n+ D7 ~arrlookup[tbox.options.text] = tbox.options.value;/ k. |; {0 x6 \# L/ M9 |6 J7 T
arrtbox = tbox.options.text;
* w) W5 l$ \. y3 Z) N}
* u% [0 d9 j2 S) ]' i0 dvar flength = 0;
7 r) g# h- L+ q- f5 ~8 Mvar tlength = arrtbox.length;
/ U  Z) ^7 N& U9 K5 H' s- r1 ^for(i = 0; i < fbox.options.length; i++) {
" E5 s; {6 ]' k, B( z9 X+ G! {2 n% Zarrlookup[fbox.options.text] = fbox.options.value;
8 Z5 C9 a1 r9 Q" K$ v: f6 }if (fbox.options.selected && fbox.options.value != "") {
7 x8 P3 J. _" u8 ~arrtbox[tlength] = fbox.options.text;2 S. o/ O7 w$ c8 y% U$ g% {, R7 V
tlength++;6 i+ |3 Q. M3 s$ \% t0 ~0 A1 z  \" W
}
) B! `. J9 M& s( k- |1 M" Uelse {
# c) S4 P" r& O, e; varrfbox[flength] = fbox.options.text;
) l  S: q6 b) t  T: Mflength++;
! a, F* S$ Y, E  _+ o   }' ]' w# t; E2 e$ i- a( E
}2 e% Z" {7 P# z- u* {
arrfbox.sort();% Y- L6 x! V+ f. ]* \6 `" o
arrtbox.sort();! K5 B" S6 F. w$ a+ A6 X

% j7 n9 c0 j! w5 F! zfbox.length = 0;& d+ a! E* L% j; @4 a
tbox.length = 0;% R, b. o. y  S- d' a
var c;6 L0 W# E. A1 [+ u
for(c = 0; c < arrfbox.length; c++) {* H/ N3 I0 Z  O' F: H# h9 q
var no = new option();
8 b; v- V8 P/ p; _no.value = arrlookup[arrfbox[c]];$ Z) c7 O: a7 ^. j% J. ~
no.text = arrfbox[c];
" N  m; r, a) afbox[c] = no;( C" ^! C6 o  |& M
}( g5 d' d+ T; I9 J
for(c = 0; c < arrtbox.length; c++) {* Q* e/ u( o* h1 o0 g9 z& \
var no = new option();
" g/ g" i% G& ]7 b7 Jno.value = arrlookup[arrtbox[c]];4 b& q# r' ]6 T  ^- h7 ~( [# {
no.text = arrtbox[c];8 d3 B* z, z0 ~- D1 ?6 N
tbox[c] = no;6 ^* K6 v6 ~5 g4 B8 t
   }; v9 M5 f# C; Q4 h
}
! y: K# ~1 R( Q% e</script>
. T# h6 @+ c) t) d8 P' H8 |</body>7 \& S6 Z" e0 @4 W6 ]/ P- N5 ^1 e: b

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