返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"4 G6 w/ v' T! H+ O. _1 z& H* J9 \
         c pageencoding="gb2312"
2 N% ?* M/ x3 i: o$ v* `%>4 p& s  L9 ]' [+ [. F
<style>
4 r$ a2 a' S+ i.f9{ font-size:9pt; }
5 L" g# F1 T2 a( y.bgc{ background-color:#aecaf9; color: #0033ff }5 J% _8 E" G# ?& b1 n/ k
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;9 b0 e" a' U# [2 G9 h
  border-bottom: solid 1px #4e7dc1;
' q+ u5 ~4 u- }  border-left: solid 1px #aecaf9;' `& W/ G% `1 x! Q( C
  border-right: solid 1px #5679bd;) W% ^+ p5 V4 {: d: [6 t
  padding:1px;5 k( `* U2 d- z0 g& d( L
  margin:0px;}. h' ~" I( @  N9 ]: {
</style>
2 u0 p1 P9 u) l& `  b; L- Z<script language="javascript">
7 C# m" u: L! U# n<!--* e& I5 z$ V! s) J* S0 N2 S1 H# a
function rv()2 L: R* K+ g$ Q; R! H' p2 O
{
; \# P& @# |0 Z( I+ Z4 x3 N9 E  var val="";
3 [6 h. b! l0 ^% Q, F* \  for(i=0;i<combo_box.list2.length;i++){
  T; v% V5 G4 |2 w4 w. Y! g. d   val+=","+combo_box.list2.value;/ n, D! D0 w& ^% t
  }
# H4 I) ~* o; N/ p/ U  if(val.charat(0)==","){
8 ]' y1 _* U; |/ a0 g1 e9 w! |   val=val.substr(1,val.length);6 _; e5 x8 {5 \1 _% i
  }
4 s0 J; _; _' ~6 ^) K6 X5 L+ |: v  opener.form1.frecname.value=val;
/ L5 N. L5 Z9 C. Q* g; {  self.close();, p/ Q# e& s9 R! S) E+ p
}
5 j. i: V1 F) A, L//-->3 P! G% O* a2 Y3 o% W& }
</script>
+ w' y& w. Q* l$ i+ E' w& h8 r! J' r<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">) n4 M0 W( _4 _% ]/ R
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />. t: E: p1 X- G+ b; j' b+ ^* E
<%0 v" N1 G7 ?, m7 T% q. E. C5 b" r
  cdatasource ds=new cdatasource();  //数据联结bean实例4 P; ]5 B$ ^) J
  java.sql.connection conn=ds.getconnection();
0 Y9 d7 M3 c3 t. p  java.sql.statement stmt=null;
1 c2 }2 A8 J& ?  java.sql.resultset rs=null;
+ i+ w1 b5 Y" W  P  cdatacheck dc=new cdatacheck();* E, l0 g1 n3 {7 E& q4 ?; e
%>: @; ?4 P% m6 j/ P; B
<%: f! _* S1 }- ^6 l/ x7 B" d
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";
& x- \! L3 C) o; e3 I3 a7 \& @$ Qstmt=conn.createstatement();2 I- i  A; E# v" |( S# |+ w
rs=stmt.executequery(sqlu);
9 T  ]$ S9 x/ L, r# v) G%>
$ V/ F" C& Y5 L<script language='javascript'>
; t& }/ ?* x* zarr = new array();
4 B; B& c0 K7 D<%  int temp=0;
4 y1 l. U- \6 z3 W8 Cwhile(rs.next())6 f( g6 u) U: A5 ~' C6 @) D' L
{8 ~" c# l- \+ d( M+ S1 U
%>4 A3 V5 v- d, Q6 L' ?# [" l! r
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
7 V- k5 ~. P, x9 w. W! _& F, ]" E<%
3 O0 D+ L# @+ L+ U- itemp = temp + 1;. V; ^1 ?4 _  I& g
}
% J$ T8 V$ f( V6 d5 O' w%>4 l" u, o5 j! J5 V+ E+ z- G9 w% J' z
temp=<%=temp%>;; t) `0 ~* C  p* l8 m
function changelocation(id){
8 |( j0 n" h0 h: N) f! [, }document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 , ~- N! m5 X; H
var i = 0; % c) m. z* E5 L  u! [( e. I. \: q; a" M
document.combo_box.city.options[0]=new option('-------',''); 7 p& o& V6 J7 ]4 J
for(i=0;i<temp;i++){ * u0 A+ R' B; F9 Z8 m, W
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 4 ?$ u) Y" c" _9 T# U; u
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
1 X6 k/ |( {. T+ K7 J2 z! P9 D+ Y8 u}
2 `. y7 x, D( }7 M4 I0 U}
2 w) z% _6 m: c- g2 P9 }# K, ~( H5 x} 2 I* p/ A  e  M, y
</script>
- b$ v0 k: I: v7 {1 h' _# j3 r/ B; w  j
<form name="combo_box">
' `. q# K7 V7 Z% ?/ N: `1 P<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
( v1 y8 {7 d  C9 x  <tr height="24">; M' f, m3 t- j: Q0 H7 K
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>" g9 }0 a  D9 r6 t3 X; _6 u
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
, |, K# p8 A% f8 ?3 x/ z( e    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>! @; e4 H  c& b7 p$ Y+ k& M
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>8 F: ^( B: [. A5 S; y
  </tr>0 z! r0 H  F: u  c8 G+ V/ K
  <tr> # j7 b3 z$ t; ~1 X
    <td>
* p0 N4 k4 Q$ j' `8 D* d  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
7 f3 Y$ S4 t" v  <option value="0">请选择部门 ---></option>
" s/ ^7 c* [4 e4 Y; @  j  F<%
6 M' D0 `" B$ w- _% h    string sqld="select * from tdept";
; q% A$ ~8 W& N; Ostmt=conn.createstatement();& l( C1 ?1 u2 z
rs=stmt.executequery(sqld);
; e; s0 I0 O- ~& Bwhile(rs.next())9 G. b# K8 Y/ l0 a* O) K
{
0 ~6 ~* Y: e# c2 q& ~%>& I% ^7 X& _4 Q
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
4 |* d1 k/ Q' d* u. i- b, i<%
+ q2 f# D1 C4 M3 s/ @}* S8 m* A4 P$ ]7 C1 B; Q. L
%>
, ?2 V0 [. L: L' K$ F# Z8 U  </select>9 I2 i6 g+ J$ i9 Q5 d
</td>
, K$ B) E7 S+ S# Q. F7 w    <td>4 K/ u  E; T: s! n# B8 n. ^1 K0 \
  <select multiple id=city style="width:150;height:200" class="bgc">
8 E4 b" y, \; X1 o/ j+ x& A  </select>! M0 l* Y% m) G% q) l& F! [
</td>, J! T7 a5 g9 V, a  i3 X+ N
    <td nowrap align="center" class="bgc">
) Y5 w! g2 M$ \/ `5 ]6 C+ k5 G  <input type="button"  value="<<" class="buttons">% Z" W8 O: C7 M5 n  P* n5 L7 j
  <input type="button"  value=">>" class="buttons">
& @5 C0 s% b# f" O3 U+ S</td>5 R. Y/ Y0 E1 }6 v& }9 u
    <td>
- D2 E# |. U$ Y  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">, B4 |, e2 X) G8 U
  </select>! F; ~6 ?) `, h, \
</td>
! z$ L& V: k! m. f- B) L1 ^  </tr>
3 B9 O& t0 z6 P5 p% T    <tr class="bgc"> + x2 ^6 P+ x1 `5 z# h; L0 f
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>; g4 Z. G$ O! G- O" `( ^  P
  </tr>
' q$ L" ?' s; @</table>
7 l- W! z/ j  v" F" A4 i</form>) d4 S* x2 e' @) ?" A2 a
<script language="javascript">
2 U5 A* m7 U- v6 u$ ]//人名移动
. K3 H; z. T8 u0 Y8 s6 G: W/ _function move(fbox, tbox) {
8 Z  y) ^6 q- c2 I6 p. y% S. Q. Cvar arrfbox = new array();
* g. P; }3 Y& C5 x; Dvar arrtbox = new array();+ A( o5 x1 W. p  Q$ e* u: M7 p
var arrlookup = new array();; t0 ~; O" }/ E8 v5 M$ u! M
var i;9 r& W% L3 i! M, v+ F9 Q4 q
for (i = 0; i < tbox.options.length; i++) {
6 I5 I+ Q3 [7 G9 ]/ ^arrlookup[tbox.options.text] = tbox.options.value;$ k" m2 f) ~/ L& |, u
arrtbox = tbox.options.text;
& b- q/ z9 f  S9 @$ m& b}
# B. F9 u4 j2 y1 e, gvar flength = 0;
0 ]& b! O) \# }0 F# i2 ~var tlength = arrtbox.length;2 m2 V! y1 C- n6 E8 I
for(i = 0; i < fbox.options.length; i++) {) _) {8 d3 F4 R: K6 e& c
arrlookup[fbox.options.text] = fbox.options.value;
+ P- p. {% k( }( L- y- @if (fbox.options.selected && fbox.options.value != "") {2 K% l& p, P6 U0 c) e) l9 g
arrtbox[tlength] = fbox.options.text;
: N8 f6 [2 d, Q! _tlength++;7 T8 V  `% B8 R# p, q
}% U9 ?' @  l1 ^, y: G- C- v
else {! X( g0 @8 p& @% F% }6 K. v9 }
arrfbox[flength] = fbox.options.text;
7 _6 T- g9 g) r1 {flength++;
0 n# K  K! o" W/ U' a3 @   }! @* ^# R9 n1 V
}9 \& @  J% u% M9 f% Q3 h  c
arrfbox.sort();3 |* s. `% g5 a
arrtbox.sort();
# R" q9 j* R( d6 S* J8 J4 b7 E  t& r4 S: f7 w' G  H
fbox.length = 0;
- Q8 W" a; u: A% u7 W. _9 ttbox.length = 0;
2 W5 O5 g4 T6 z$ `2 z: O( dvar c;( ^5 r% E) v, l; s8 A0 [' Y
for(c = 0; c < arrfbox.length; c++) {# h: J& k/ I. Q/ ]+ Y. ^9 d
var no = new option();
* X5 M7 ?7 B) |no.value = arrlookup[arrfbox[c]];/ V; A$ i8 w1 L% ~; }
no.text = arrfbox[c];
4 k0 F1 K+ x' v- F- M9 Qfbox[c] = no;' S: N5 R+ }9 T7 Q5 |
}
2 X6 T2 w/ ]+ S7 Z1 p, a# ^( ^+ qfor(c = 0; c < arrtbox.length; c++) {
& h$ ?, [* D: T: \5 R& D3 Hvar no = new option();; k- N9 i# x6 p
no.value = arrlookup[arrtbox[c]];# r" X  }& C7 K$ F2 o" U0 o
no.text = arrtbox[c];
  p6 Y3 B/ Q" d9 y, }tbox[c] = no;
" G2 G9 E/ C$ b( ~% C8 V   }
0 A5 [" m. c+ M( S  w# n% ]# M; J}) s- ~, O6 u0 d$ |7 m1 x- f
</script>2 Y- j( U0 u! v' U
</body>% C3 b: Q. r7 r% a- b; w' d

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