返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"5 h# K( f0 Y5 h  ?4 s- r
         c pageencoding="gb2312"
" g5 y; d! i7 G%>
. X' Y$ j% R& r5 c* \0 L& W1 \<style>2 g% Y# f7 D9 F4 B4 F3 m
.f9{ font-size:9pt; }% ?1 M# t  U/ R! [7 f
.bgc{ background-color:#aecaf9; color: #0033ff }
) Y% H  L8 v: F: K.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;* m- R. |7 O, O/ d2 A' ?1 w$ K, X
  border-bottom: solid 1px #4e7dc1;
+ R% D# z1 q8 `; n3 Y! l( l9 o4 S4 ^5 h  border-left: solid 1px #aecaf9;
6 B6 {8 U& N  b5 M$ ]8 f  border-right: solid 1px #5679bd;( @  {3 Y4 M) T0 O; E' D) r
  padding:1px;
/ u9 i( ~9 o$ d* g7 p9 z/ Y  margin:0px;}
" J+ T6 q2 \4 w/ g$ j</style>7 D! N( n: J" i
<script language="javascript">
# k, {, b8 [. Q<!--
/ h: J4 P7 E/ ]  H) ifunction rv()  U9 C# y1 }' n9 z
{
8 \; Q# M0 n% o+ s$ ~  var val="";
/ [7 v1 Y7 E" G6 d, p  for(i=0;i<combo_box.list2.length;i++){
; g0 h) M7 [( r/ z* N$ S   val+=","+combo_box.list2.value;/ U: S4 o) V2 E& M
  }  J/ ^/ y, G, M8 K: }
  if(val.charat(0)==","){
" K8 w8 x: J; n6 o# E$ n. v   val=val.substr(1,val.length);, B) }: k0 ]! n
  }( g; J% @' n5 F# @( I0 }+ T
  opener.form1.frecname.value=val;- ]: F, i) p9 z; K2 s5 i6 U
  self.close();
  y# l( h7 F! H1 i! S# S}# B3 \1 `% S7 W; W0 R7 }
//-->
+ c& }+ C, s& F, _# f</script>& [& o! m  a7 \1 {
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">) O; @) K! ^: b4 L; ~
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />5 m0 X3 G7 s" S& Q
<%9 U3 M1 p/ J5 Q' Q, f' Q! E3 r' C. J
  cdatasource ds=new cdatasource();  //数据联结bean实例: ^9 Q% d3 q+ }! |9 m+ J; D
  java.sql.connection conn=ds.getconnection();
9 r' X' E* p/ n; Z! |  java.sql.statement stmt=null;3 c) r/ d  U$ U9 H2 }  c) y' J
  java.sql.resultset rs=null;+ e3 o3 _) R9 a) I2 L! p5 ^8 y" m0 }
  cdatacheck dc=new cdatacheck();6 a" k9 t+ O) l
%>8 g7 f! S& W  d; K- w) Y! K
<%
8 C6 A* y# N/ A4 ]2 X8 F# h0 X5 |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";- j$ E! B. X. Y4 \; k% r; v1 y
stmt=conn.createstatement();; ?# P! K1 P# W2 D- I+ S
rs=stmt.executequery(sqlu);0 u0 X: n- j" k5 v0 Q$ c, P0 U; R
%>
0 t  w. ?/ Q/ C/ f0 {8 y<script language='javascript'>
: X# y" l* D* _1 aarr = new array();. I. D7 a) }9 h6 t
<%  int temp=0;( P  r2 b3 o4 L$ N
while(rs.next())% q7 \' O" i8 {/ x$ v3 }
{
' r6 Q% ]  V, m- ?( N. @1 U" b%>
" ^/ J: I: ], _: E7 W! Q* uarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
. o4 z2 K3 [+ }<%
% I/ k! c5 X& L- Ktemp = temp + 1;
/ ]* s9 n/ I0 N/ k0 R" H4 Q8 V* |}
# e; K1 }1 ?% W! e& u+ M: R%>
9 e/ L( M- S  Z/ l1 R! L* ptemp=<%=temp%>;* e( t1 ^0 ~# m8 G. E* Q0 k; U
function changelocation(id){ * u0 T. |8 W2 G" C0 D4 T
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 & @$ @0 w4 }0 j7 H
var i = 0;
' G& w7 y) j) Q; ]4 k7 `2 bdocument.combo_box.city.options[0]=new option('-------','');
2 N% `+ F& p8 |- d: Zfor(i=0;i<temp;i++){ 6 x- W" C) ?# ~. W2 |
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
" u  O# ]$ m( ^+ ^0 ?document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
, ^: ~! U* |) t) x}
3 J3 m! a2 S- `} 2 y! M$ }, m) i8 k. b8 n; Z: u
} . Q5 m+ I. z! Z1 r/ a8 c, e% P
</script>+ g. U" g, ], S" t0 }. v
, X( m" e: |" U4 O8 {' g
<form name="combo_box">
7 q+ |- a" _8 `" J# H<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">: S1 u& G9 X+ R- u; u& d
  <tr height="24">
  U! V/ b6 O6 E/ ?. }2 G    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
6 N# p3 U  A( a- x7 c    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>* W. x% E" {9 {9 g# D5 O# a- L
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>. d5 P$ f3 X' x( Q
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>6 I- ]# e5 N+ f1 ^
  </tr>
( r2 H' @) U+ {9 |8 u; N  <tr>
/ i" F  J. J2 H4 z$ r; ?# Y1 V6 [/ ]    <td>' y. ?9 p" X% k: p% N
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
' l, b4 k2 e9 E9 f9 `& V/ d  <option value="0">请选择部门 ---></option>
* A: ^* C3 {/ B$ y- Q4 G% K<%8 q( ?5 r8 v" l- P- C
    string sqld="select * from tdept";, d6 @; P* {3 N& r7 p6 V
stmt=conn.createstatement();
0 f2 Q+ l4 b1 K1 s0 mrs=stmt.executequery(sqld);
( X4 I1 n8 l$ H5 j7 Z# s8 A- U+ Awhile(rs.next())3 ~2 p1 H2 Z4 {: w1 q
{* K, x  t) W! F2 N) H
%>
+ O6 t, e* C/ i4 p0 T9 U  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>9 D) c# {( d; n: O6 C& d; {7 {
<%6 R& X; D' ^$ x, n# t  f
}
: k' _8 J, J3 \%> . T/ y# u, U: P- X$ V/ F8 k2 b8 i' ^
  </select>
2 L9 a& \+ i7 i</td>  q" X$ p' Q! C* W: G! }
    <td>% k8 Z9 E, Q- D4 [& A' P* s
  <select multiple id=city style="width:150;height:200" class="bgc">) A5 m/ f. R2 W( \& S2 _) M/ I
  </select>
. V4 d2 H! g- p3 T1 u</td>: u/ @, ?  |1 V0 f; u& {& X+ S
    <td nowrap align="center" class="bgc">
9 S1 [) x! A2 V6 o( s0 j( f5 C  <input type="button"  value="<<" class="buttons">9 [+ r: H3 q, u# {& w: E1 r
  <input type="button"  value=">>" class="buttons">
* p1 a0 {; j; U/ w0 e; H</td>
1 l$ \# }. k1 {9 e4 p    <td>1 E2 e4 C9 I5 y9 g$ Z7 ?
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
8 d# F' J% L. K4 S  </select>
# n" {+ O) E3 {; ?# g</td>
0 ?- P( {% W) I* O1 X- ?  </tr>) j# z4 S: j* V, K. V3 x% l+ ^" c
    <tr class="bgc"> 7 `/ _) r9 x1 h" D7 U4 ~# H6 ~, s4 }
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>) L0 x5 v) P5 }1 `% n9 }) T5 A6 N
  </tr>- g. I. Z8 ?8 d5 a4 C
</table>
" B$ R4 }6 v( C( Z4 }</form>
4 V% Y: j% }( f8 T<script language="javascript">
- m" r, R4 K' r' f6 Q' I9 r% H//人名移动+ T* [3 L2 R( y& r8 v5 D+ d
function move(fbox, tbox) {
3 a7 L( x# @( Uvar arrfbox = new array();5 v2 W7 s9 u( J6 |4 X, d
var arrtbox = new array();5 x( {, Y+ [! E6 {9 E/ H) E
var arrlookup = new array();$ r! o/ c" }9 }5 k
var i;1 ], ?+ F4 a/ C* K5 r' ^  A0 V
for (i = 0; i < tbox.options.length; i++) {
: u2 u* b- l7 B  x# X4 F: Larrlookup[tbox.options.text] = tbox.options.value;1 F9 F; o' Z9 H* b
arrtbox = tbox.options.text;2 `9 L1 B; G0 c, ^9 N) v
}
& b6 L2 l. h6 qvar flength = 0;
+ O5 I0 F3 t+ Fvar tlength = arrtbox.length;* T/ \( s: T8 c4 A: g! p2 e+ h
for(i = 0; i < fbox.options.length; i++) {
, O& L7 W2 k1 J$ N: v, Narrlookup[fbox.options.text] = fbox.options.value;! {  G( M  N' G1 o$ Y
if (fbox.options.selected && fbox.options.value != "") {. l- K4 K$ t. N1 L5 p
arrtbox[tlength] = fbox.options.text;
' j+ D, @3 `, |, Jtlength++;& {, v, s$ Z3 O6 O$ E' @
}
% `" G2 |' [) m0 G/ {else {6 ]* g2 G4 |" g7 ?* @; |" l
arrfbox[flength] = fbox.options.text;: ?8 t6 ~1 a- K5 n3 A; J
flength++;
# s( a6 v+ x0 I8 V' u   }
, M; X% s( \+ E- H  ]6 Q}5 ^" n" M! R5 U/ l
arrfbox.sort();
! j! H# i3 Q/ ]7 y) Qarrtbox.sort();
6 I; H- v: ?. q1 O
8 X+ ^* n4 ~. o! Q1 {fbox.length = 0;
; _: i& x6 \0 P* g. n7 utbox.length = 0;
9 ~4 y  |( w, e" l8 n# @" ~3 [0 I$ svar c;
0 E0 d' T3 l6 j+ ?# n9 O& zfor(c = 0; c < arrfbox.length; c++) {
  R- i& v3 Z% Z- e  r8 f0 Yvar no = new option();
) L: ]) U: C+ h; X: M) e4 M. pno.value = arrlookup[arrfbox[c]];7 q9 I# I0 N  ^1 L" B
no.text = arrfbox[c];+ z3 T- @6 F7 `; \
fbox[c] = no;
6 I8 h) G: U0 V; p}( n4 r5 B: |! L' [* ^) j
for(c = 0; c < arrtbox.length; c++) {
" g' K0 B$ H! q- xvar no = new option();' [1 @+ j! s: m, N6 w; ~; E
no.value = arrlookup[arrtbox[c]];
, d& X6 O) g4 m; `& \3 Jno.text = arrtbox[c];
6 S* `0 b! ~% d- `) [7 }tbox[c] = no;7 F" h* o+ C8 H( }, K8 C5 {
   }
$ u9 ?7 [" r/ r. u2 p}
. p; x- I& f& r! p8 z& Q1 H# v</script>: V/ s1 a) D1 L/ H4 O2 r4 ^
</body>
' C% A, D% f5 @: c. R5 }

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