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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"( r3 l' A3 a& u0 x5 c. W0 T5 \/ @
         c pageencoding="gb2312"% G1 Z$ P) W5 Y" [
%>
3 K  v. S0 m  J, K3 i<style>
& z9 n% E( _1 s; n) |.f9{ font-size:9pt; }) A$ S) t3 r: U* i# z! l) K
.bgc{ background-color:#aecaf9; color: #0033ff }$ H' w4 N& {7 E( D# D" ~' Z# }9 g
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;% g$ H# N4 J) s+ y
  border-bottom: solid 1px #4e7dc1;# |1 T8 f# K' v) L: \1 P. v8 G% |
  border-left: solid 1px #aecaf9;
! ?6 b. T; U, |- S  border-right: solid 1px #5679bd;! r5 L  ?7 F* `' L3 r6 q/ V5 o8 i, K
  padding:1px;
3 F* c. V  C5 V& ~) }/ m/ M; _  margin:0px;}5 k) z3 @# K' H* M1 U/ L5 O
</style>
  u& m( F& i, N' n2 _0 s3 n8 K<script language="javascript">  T7 y" ~9 \; f5 ^4 B) O
<!--8 x1 R  v6 D) W; ^' P* t
function rv()6 o+ z* j9 a  V
{- v8 o% }- A  U3 b1 ^0 l  z
  var val="";% V; |1 n0 K& s* R6 L( M4 U" M1 }" |
  for(i=0;i<combo_box.list2.length;i++){! C, \: a/ V  z, i2 Q5 l9 ~  i
   val+=","+combo_box.list2.value;
1 c0 Z9 t1 \  W  }
  F8 ~0 M3 h' _6 B& [  if(val.charat(0)==","){
( |3 X, \& ^& c) V  {: K   val=val.substr(1,val.length);9 q- r) r$ W% }8 J, W( X2 Z! l! g
  }7 w8 H' Q8 }  F" ?( E3 U" T5 ^% W, E5 p
  opener.form1.frecname.value=val;' h( n. H4 \& X. j
  self.close();
; J! L/ _4 j1 a' C$ u( J8 q}
" s6 k* {7 v" o+ K+ Z3 z//-->
- e  g+ G% g+ l  I& P2 A" V</script>4 z' X3 J7 D. p- A% o
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
# d  E( q* o% O& z3 R& s. n- S<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
5 k! Q: s* `' D: s8 [  H<%
$ G9 w: R) B9 N- Q: @. K: }2 Z  cdatasource ds=new cdatasource();  //数据联结bean实例1 @/ ^% Q6 q, {0 v# F, L$ }
  java.sql.connection conn=ds.getconnection();% c# i3 |+ l% y- J: l
  java.sql.statement stmt=null;5 V- u% O5 {7 }( g* q, L, v( K9 f
  java.sql.resultset rs=null;
  A, U( j3 v2 G8 A$ o( @  cdatacheck dc=new cdatacheck();* U/ n0 T& @$ a+ F0 i4 Z
%>
( P, j7 e7 x' H* x* g<%
* p% `& p0 ^8 O9 Ostring 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";
  v9 K+ X1 Q( o, A1 {stmt=conn.createstatement();1 H6 X; O& k$ @: e" k
rs=stmt.executequery(sqlu);
+ }/ K: n2 W. F- s%>
2 j" F) z. @1 @) M! U% N" d<script language='javascript'>
2 U2 k. Q' l" harr = new array();* ?, X% _, u; M
<%  int temp=0;& ]* p3 B( b  ^  J6 }) _; @* r. J
while(rs.next())  S" x( ?: P+ q" c8 \8 I( S
{" H! I/ Q  z# T: |
%>
5 @8 U2 q5 N& q, h+ }- i4 karr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");0 E4 s0 `& |8 X
<%6 }0 _% s) y( B: o  C
temp = temp + 1;
; g% N9 e2 \: L: v/ W8 H}
' h" V  C% G9 S7 t) D%>
, ~$ v+ Y2 r$ w  |2 }" v2 l9 Etemp=<%=temp%>;1 P% M" v/ l: {' W, B# u' e
function changelocation(id){   u8 n" ^$ C) R  N' ]1 Y
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 1 o  f) n$ Y8 [) ~7 c* h# D
var i = 0; # V& @( ^' M* w# `+ W" @8 \
document.combo_box.city.options[0]=new option('-------',''); 8 O( R9 Z6 {3 w. P
for(i=0;i<temp;i++){
; W1 K7 s0 e6 I  a- ^/ [$ C1 G# x/ rif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
$ M, J: G; i# K# |document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); , H$ o& ~" |9 Q. M2 V
}
& P4 j5 P$ T: Q( z} 4 ?+ i. }* m/ `4 W
}
+ C+ W7 a$ t2 f8 c; l' X</script>
7 O' S9 Y% c* Y2 E# w/ j
5 G0 T* f2 M0 g9 j% j- O<form name="combo_box">
$ b$ Z5 }  P% D<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">5 G6 }: C6 f+ G/ Q
  <tr height="24">
) W7 Q! h/ g. a. ?* t    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
# p- y/ o6 Q: z( b! ]    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td># j# {0 X8 Y  p
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
+ h. q7 H1 `8 G' F    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
8 X4 r& m* b: C' i' |5 x  </tr>3 b* A1 O8 t) x; j4 e' n( \( v- T" M
  <tr> ( j8 I; n9 W* E' p$ M6 E
    <td>
: N- i% L( ?% K; h9 t  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
: N" K- ?( W2 z$ k) j  <option value="0">请选择部门 ---></option>
  }+ t1 k5 A3 p4 `0 i7 m6 E' z<%
3 B* a% U3 T8 A- y% f2 [  I* d    string sqld="select * from tdept";
/ A7 h: M/ }6 a% G) \* I% R( s! |8 @stmt=conn.createstatement();
5 ~; g& N3 Y  i( Yrs=stmt.executequery(sqld);. D  C; R8 I5 S8 m
while(rs.next())
) ~% X# u& U9 I! p9 N{7 X2 F8 J) k& V4 G8 P3 B6 @0 P5 V3 M
%>
) W) p0 n" X/ s0 r3 U% m  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
4 Y; l9 I* \2 m; r, V# }8 l<%9 W" O: i& j4 L1 a
}
. T) z! S6 P9 J/ f4 `7 [%> + ]: M2 A# }% z% _+ X; F
  </select>
5 S9 i# M# Z" I' N- I1 O2 [</td>1 ^" ?4 o4 w$ l$ q9 g* G' k
    <td>. Y9 I$ J) e/ g% r. }
  <select multiple id=city style="width:150;height:200" class="bgc">
# y( O% u$ b& `1 u% \& s3 E  </select>' H* z! m6 P1 _+ \" t% U
</td>
$ @6 ?3 X# k5 |; x8 o    <td nowrap align="center" class="bgc">
1 i+ w4 E3 Z/ d+ b$ ]. o/ \. D  <input type="button"  value="<<" class="buttons">
' f& q2 j8 n- c1 @! |5 U. l  <input type="button"  value=">>" class="buttons">
0 g8 p- r/ B" U7 S1 l! T$ O</td>1 k) }* }- X8 |1 K/ w% h5 K: C7 R4 u
    <td>
* s' W: Y" c. ~8 L  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">& z; T8 v$ ^* @7 b* ~8 ?6 B  T3 L7 p
  </select>: r  Y+ X0 F) }  v
</td>
; Z7 K  o& ?( u) I6 J0 V  </tr>
, w: K" F; t6 {2 T9 j$ }    <tr class="bgc"> 1 V( K- {: g$ Y( S' X
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>" B' P) d6 u# N$ r
  </tr>2 V. }: I' X0 ^9 A
</table>
& y1 k& l: u2 q7 l' [$ J* S' |) k1 U</form>
' v+ k) F' }5 t1 B1 a1 B<script language="javascript">, }" w+ l/ s8 l* b+ [: K2 L
//人名移动
0 U7 q3 e6 S6 I" y6 k& Cfunction move(fbox, tbox) {2 k( p: a' x" o* I/ N
var arrfbox = new array();
# W0 \" j: ^6 I# k( V+ Lvar arrtbox = new array();
# t: U( I% m7 S6 p) F) j, ^var arrlookup = new array();
# [' a2 g# `+ Evar i;0 M& ]% Z4 G0 [0 m4 T% u4 u
for (i = 0; i < tbox.options.length; i++) {, w* b( a7 F0 G: X& i1 \
arrlookup[tbox.options.text] = tbox.options.value;
% y" ?' e! x/ y" L" T, I  {6 rarrtbox = tbox.options.text;: O# a! b6 L$ Y- `0 a# `
}% \7 k0 i* W5 ^$ J5 p# o: X
var flength = 0;3 f- d+ B, N, {" T. I
var tlength = arrtbox.length;
+ ?# R' c/ R8 J& w# T6 Jfor(i = 0; i < fbox.options.length; i++) {
5 u( g0 U4 h! p$ v$ qarrlookup[fbox.options.text] = fbox.options.value;
- W6 }2 b, U0 c! Q" ~" I8 t0 \# Rif (fbox.options.selected && fbox.options.value != "") {
1 v: x" `; A0 C2 P  karrtbox[tlength] = fbox.options.text;
6 }9 m" z# n4 z) Xtlength++;
, s, m; X1 A! ^}
1 F! X- Y: k  I9 I4 R7 Uelse {
8 H+ }" B& U9 w, Marrfbox[flength] = fbox.options.text;
. ?& Q; x( J) t) k& \* W# [flength++;4 d9 A+ G1 h) \' V( d
   }+ l/ F( \5 Z0 _2 ?/ Y. J
}7 v0 P6 l# g, B0 N$ Q1 ~
arrfbox.sort();
+ c" j4 t% w( w, barrtbox.sort();
- M: l: F( I' S3 Y& O
0 {0 S1 A! ?7 D0 ^fbox.length = 0;
7 r5 B3 _" ?! j( A% ntbox.length = 0;
, d0 w1 N% _* q% Wvar c;0 q' ?7 D$ K) `: E: o5 L9 p
for(c = 0; c < arrfbox.length; c++) {6 n8 l; X9 j: _1 v3 j! [9 h
var no = new option();
6 g% F1 c0 T: k( Sno.value = arrlookup[arrfbox[c]];, W% b4 C. w6 w
no.text = arrfbox[c];1 @5 x# O8 @/ x" K! S* d+ i
fbox[c] = no;. U. B( X9 C; \4 l: B' B6 Z- F/ q# ^, m
}- D" R! q% B" G% N" ?
for(c = 0; c < arrtbox.length; c++) {9 C0 j! u/ g. U3 ~  L3 O1 Y6 O+ j
var no = new option();, z6 [4 c3 S- a# R1 V
no.value = arrlookup[arrtbox[c]];
( h$ |5 d7 ^# j2 d1 eno.text = arrtbox[c];8 F; R; c2 [# e
tbox[c] = no;0 [7 h4 d! r# E' |
   }8 |2 S0 B3 R0 ]8 P+ P  P$ w8 P6 q* m
}. J3 i5 N* ^8 W) E$ ]
</script>( I/ R1 H! P7 a9 |7 {% E1 a1 J: O
</body>5 D" }  X3 z- o3 X

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