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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
# O* W6 z) f7 E  S9 k! X         c pageencoding="gb2312"
7 R3 Y5 B! l" n%>& F; `0 U; D3 Y# ~
<style>' e6 ^1 C# V  y1 l  W' \5 }
.f9{ font-size:9pt; }
$ c8 q# \$ ]- v# s* R& y.bgc{ background-color:#aecaf9; color: #0033ff }
6 Q$ a) s' ~$ t- e- _0 _, m.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
0 q/ l* j5 A* f, L+ m  border-bottom: solid 1px #4e7dc1;1 j! L. e  b  i& M5 @6 z8 m& s, o9 @
  border-left: solid 1px #aecaf9;3 a. S8 T' u# }( n0 ~$ u8 z7 z
  border-right: solid 1px #5679bd;
) r7 R4 A+ ?4 R- W  padding:1px;9 E9 \8 j0 ?5 Z' m* l
  margin:0px;}. v0 ~% P- O! ]1 ?4 E- c
</style>1 A/ N5 j( x. N- O
<script language="javascript">
- P- ~  X# ~: p5 O' a0 `1 K8 [<!--
* o8 b5 P6 @. ]function rv()
) h& i- q9 K# x' [: _. H, `& ]{% U$ g+ X' u% `. H! u
  var val="";) |; x  t( r: ?* {  z4 P
  for(i=0;i<combo_box.list2.length;i++){
# Q6 |4 ^! X( }* |   val+=","+combo_box.list2.value;
' J& _7 P8 h4 n4 n' W. j$ R% ^" ~  }; L) }: `1 x; g% m; t
  if(val.charat(0)==","){
# K' T: `& w$ k9 ^) b3 o8 a% B   val=val.substr(1,val.length);' g, }; t; ^/ U" ^  K8 I, |
  }, t: E& v2 D& v9 f, m. q- y% B
  opener.form1.frecname.value=val;7 r/ t% k: a% P* D
  self.close();/ P1 x( A; [% Q! Z  t6 U
}( M+ N% h1 @8 ]. d9 M
//-->
( `/ H  z- r* f5 N7 C</script>
, V' h2 J! d* W6 j. X. [<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
8 ?: m. C9 v( }<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
+ |. G6 u! |% \9 z" p, Q<%+ I: ]& ?0 i+ R& s1 o1 j% V
  cdatasource ds=new cdatasource();  //数据联结bean实例
& {0 i/ y* \1 E  java.sql.connection conn=ds.getconnection();% w4 ?, D0 O$ c7 a
  java.sql.statement stmt=null;' y# |1 Q6 t1 p* H
  java.sql.resultset rs=null;
$ _( k! Q5 q" N( [5 B  cdatacheck dc=new cdatacheck();* k2 g) Q3 y" T
%>
& W5 o9 O+ o) X* m<%, ^$ l" Y9 U) q* h& F  K( C
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";- ?& z, r+ {% C; r  O; y
stmt=conn.createstatement();  L4 [  |; ]' a" B9 }: b
rs=stmt.executequery(sqlu);
: A( n7 [8 C7 H) l%>
. O; x/ C; T0 I) W<script language='javascript'>! X! n- R0 @9 A9 c7 F
arr = new array();
0 T/ X/ G# B' m2 v" |: U# h<%  int temp=0;7 Q4 H6 |9 O; a
while(rs.next())
! x) p' _2 H- y! C" x! q& R{- d4 ~( Y/ ^% g' y
%>. z6 H  U6 X% p, J5 S. P6 n6 s
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
! F1 e9 s& m. l$ k: V<%
, _. X3 Z0 a2 U9 ptemp = temp + 1;7 U& `- T7 @+ r- Q3 s2 V* d. S
}" o! D& `: f. X& e1 ^  T
%>
  U' V- b. K& z$ V) v, w0 s( wtemp=<%=temp%>;
; }" {0 M0 [2 zfunction changelocation(id){ 4 R0 D  f/ z+ O" Y4 Q4 `1 B
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 / y; c5 Z7 a, t- m1 e
var i = 0; - c9 @6 H* J, o3 K  M
document.combo_box.city.options[0]=new option('-------',''); , m& x4 {. V5 t/ S: |
for(i=0;i<temp;i++){
) E! }5 T$ g+ Y. {2 Eif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
" k6 W1 f0 ]! odocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); ; }! E+ M) e+ ^& @! X/ w( }
}
) l* \! x" n$ w* G+ [3 y# W} 1 `, a" M: @( ^$ h; F
}
& S/ T( p2 T  E# a1 Z</script>
# m1 {6 f( H& c! a: j4 t3 m  N* T* F1 ^( c
<form name="combo_box">/ Q7 c. q3 G" X8 B* {+ c( f
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">& L  q- ]* [: ?1 H$ ~
  <tr height="24">
+ W; h# V( e! ]0 M    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>5 j! n. @  X# p6 w! j2 A
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
  k! U; a7 \. T+ i% R    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
+ {1 o! h; r' `3 ~8 z    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
; G9 k# P( b* C0 q6 t- y; l! T, N  </tr># F  s5 q% @' q5 e: s
  <tr>
# y/ m/ ]/ d- D: p$ P5 s- M! D# j    <td>& m& n/ a$ y8 ~& \
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
+ m3 r7 N; Y; J1 }9 g$ b  <option value="0">请选择部门 ---></option>
- L* H7 M) M; R8 c; I- W<%* w8 u! N( y8 H
    string sqld="select * from tdept";
" y7 b0 X& B: C% H) Z* Sstmt=conn.createstatement();
7 X, F9 ^+ \8 f4 ~rs=stmt.executequery(sqld);
  M! P  B- K- g& K6 o% c% zwhile(rs.next())
% t: o5 S" D2 o2 x! d% e{
- F4 D$ t2 Z5 {* `% L%>
  \  C& {" I* r7 f7 u" q  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
0 E' m/ L7 S$ s% W( f<%3 F' W/ D! K7 [9 S& B
}2 |: p. V: W  [7 d
%>
/ G+ j0 a, `, P+ l. A8 D4 |  W1 D5 Q% h  </select>, Z9 i! B) `9 t$ @4 {
</td>
! M9 r" ]6 |* E% p9 c* q1 ~    <td>, b/ F$ T9 L! c" k9 W% W
  <select multiple id=city style="width:150;height:200" class="bgc">$ U+ l0 F8 P; R; C. G
  </select>1 f5 k8 v! |, f, B' ^
</td>
% G. R  q0 f* e5 F' m, s    <td nowrap align="center" class="bgc">8 ~' H. [1 t+ y
  <input type="button"  value="<<" class="buttons">5 a# ?2 ?' F; F5 I4 ?! O
  <input type="button"  value=">>" class="buttons">
1 h! F+ U' H$ x6 g</td>
% p! k' \3 B. Y    <td>
6 C# W( ^9 [# G9 B8 V0 r  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">0 D/ s0 y0 R2 D( A7 l/ `( X
  </select>
2 d7 `( P3 Z& q; w</td>
, o0 U' D5 n* w  </tr>4 L$ L: ^2 B5 Y% [+ a+ P
    <tr class="bgc"> / f3 Y3 y9 p# F0 U3 U0 G- o
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
: o2 Y6 U4 z8 p) A0 z  </tr>
) W6 x, G3 ^( M" G</table>/ Z- K9 d. {' J. l9 j. e5 E1 L
</form>9 N3 {  L& V6 f& ~
<script language="javascript">
4 W% z7 L$ n; R: ~//人名移动2 n7 V) E" ^7 ^
function move(fbox, tbox) {" l& {1 h1 a" _4 a" F! `  h' X
var arrfbox = new array();2 w$ P  n& n% U* |3 _& c
var arrtbox = new array();0 ]5 n6 Q$ a# N1 _9 [7 [1 O
var arrlookup = new array();
. s, I6 B( O" \2 p, z" T: wvar i;) _8 ~2 e4 d% @# g
for (i = 0; i < tbox.options.length; i++) {. U( U+ L* A: ]6 L; ]0 e* [9 x* e
arrlookup[tbox.options.text] = tbox.options.value;
+ R, q7 S$ l$ _* b: V/ K" e! C( darrtbox = tbox.options.text;
( g7 ^& @' j7 |. @) |}
2 G( @  r  l4 N% Ivar flength = 0;
1 v9 f" Y! U3 H  Yvar tlength = arrtbox.length;
$ E8 C+ @6 i: f1 ?for(i = 0; i < fbox.options.length; i++) {7 @) ^5 b$ ~2 C
arrlookup[fbox.options.text] = fbox.options.value;" V. k& b% _, Y9 g3 E
if (fbox.options.selected && fbox.options.value != "") {
9 |8 z9 Y% ~1 T$ N: \9 Iarrtbox[tlength] = fbox.options.text;  B4 G1 F3 B( q4 ^, ?8 D) V
tlength++;
0 p1 K2 b0 Q) l2 }, \% E" C}
$ H7 ^  [: U. D* Z7 a" felse {
  j! O* m& |- j% u5 _. D# marrfbox[flength] = fbox.options.text;
( \- [# f) d3 h- |3 y5 |- yflength++;
1 a7 ]0 E4 j8 F5 a9 s0 O! K   }$ t* O9 B5 n! p/ g# |8 d
}
3 }: Q/ Y9 E+ w! k0 I% a3 g/ G7 Darrfbox.sort();. P" N) m- I$ ?& l9 T
arrtbox.sort();: ^' k# C1 y: A5 i: s* j/ h
* R8 T6 d( Z- @/ D7 o7 `& W
fbox.length = 0;2 G7 p8 g  p& D0 I
tbox.length = 0;
. g8 g* {. K2 b+ {- M. T& svar c;# R" q) A, [; D( b% g
for(c = 0; c < arrfbox.length; c++) {
0 {1 T  q5 g* Q8 S- ?$ }5 z' ?, Uvar no = new option();& x& a$ P- k/ D6 ?
no.value = arrlookup[arrfbox[c]];, O& e0 n3 X9 ^/ w& A7 W* v
no.text = arrfbox[c];" }, X# P+ I) _/ h# k+ F9 ?
fbox[c] = no;5 r, {) W# S' k; z% f+ H; }  E
}  F% v3 q+ ^0 C) n9 B
for(c = 0; c < arrtbox.length; c++) {) s8 l& R6 ?5 x0 K( @: L( }
var no = new option();
! O, f" @+ \. z3 v$ ?: Ono.value = arrlookup[arrtbox[c]];# P- D& a& D" B4 z7 }. U$ I
no.text = arrtbox[c];/ F5 l; T+ V) y( n1 W  q4 Q: A
tbox[c] = no;
0 F- L5 V: N: h   }/ a; `- ~3 C2 @/ _- e! p
}9 v' t% p# N( c/ ?+ o9 q0 H
</script>! q5 M& V; t7 ?/ P. i/ m
</body>
1 R7 {+ W2 J: {

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