返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
) }0 f. u+ x9 P( y         c pageencoding="gb2312"5 T% b* R) f7 {6 m
%>) l5 E9 F2 d) g' ^2 ^
<style>
; D: A$ x* Z: O.f9{ font-size:9pt; }
' Y+ j! Z- C% G( d+ i.bgc{ background-color:#aecaf9; color: #0033ff }
/ p4 C# m9 V3 ~+ q# P.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;( Q% A9 O7 C4 q' i3 @
  border-bottom: solid 1px #4e7dc1;- v( E! u& D5 ~
  border-left: solid 1px #aecaf9;
5 f6 A/ i# J# P  border-right: solid 1px #5679bd;
7 {$ T0 {; l# D  padding:1px;) j9 j% Z2 B0 {+ Y* j
  margin:0px;}' s* U2 R# _& T9 U! {
</style>4 K2 O0 T, q. j2 S0 c3 {9 Y
<script language="javascript">: g9 C5 O* X+ N$ I
<!--
  i( U6 K0 ]9 `) K% Z. sfunction rv()2 Z1 B- z; b! T( B
{$ R: ?) M6 K( l, r/ w
  var val="";
6 `' {8 Z6 Y0 Z7 u  for(i=0;i<combo_box.list2.length;i++){  u/ K( `' q, A. r1 p$ K0 [
   val+=","+combo_box.list2.value;
) u7 i- ^9 p& Z5 C; j! g5 }2 ?! r! b  }5 u+ b$ S' K4 C" q3 R# Z0 c
  if(val.charat(0)==","){7 H. i( }, d- R; \+ |$ {
   val=val.substr(1,val.length);
5 S, O6 Y" X6 [' q4 r  }
  F5 l& j9 m' ^! G' A% ]  opener.form1.frecname.value=val;
7 @- X' v) w2 J6 M; p4 u  self.close();
( Y' L$ b. Q/ x& e8 x' q5 R+ P}1 B% G" O0 x- W5 y' _; |  k
//-->% g" C' H  e% E7 ~
</script>
1 o# R- e& B" m+ C: u% R2 i<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">. _1 P% ~4 Y/ B# A; t
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />% o- ^. K0 i3 S! E" a
<%8 s# G  F7 @3 l3 X$ L
  cdatasource ds=new cdatasource();  //数据联结bean实例
- B$ v( h7 d' Q6 D  java.sql.connection conn=ds.getconnection();) o. p% U! l7 T1 s- G( @. W. z
  java.sql.statement stmt=null;
5 F7 o/ I8 p! e. P/ f4 u5 j  java.sql.resultset rs=null;* L) C8 j. m& |' }' m
  cdatacheck dc=new cdatacheck();
' f- I' X3 q/ s" F) `%>
4 l3 m/ S. E8 L# }- G" V4 y9 f5 z<%# B0 L; V0 v$ ]$ n+ j
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";/ A( |3 T5 X8 y
stmt=conn.createstatement();8 s* S: V! ]5 q: E! ~* `
rs=stmt.executequery(sqlu);5 f1 u7 C) l$ z
%>
- B4 @" E5 c( z' X1 O<script language='javascript'># W5 F% h# c, f1 B. p8 e2 b
arr = new array();, T! @+ }8 Q4 i. Q
<%  int temp=0;0 F' E! ~6 `# B$ v- ^! w
while(rs.next())
3 H+ g5 I) Q7 i0 w2 q{
- c( h, m- M- f1 `%>
1 ~4 [- T8 ]- K4 Q% u# Sarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
2 G/ t& }+ P7 R8 w4 c8 g) c8 Z1 }<%
, M1 h  d7 N0 M3 htemp = temp + 1;
' J) s  Q% W1 A$ [' N# l) a& E! d}
1 }; @% C5 O) X0 U5 M%>/ D1 h/ D; {! w( u
temp=<%=temp%>;$ a# s# _7 Q  g$ S. h
function changelocation(id){ 6 \6 p, y8 E$ A# i; {
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
3 \( q6 k/ m( n! Q/ D' m) lvar i = 0; 9 R1 u6 U/ l! x+ }* ]* N) K
document.combo_box.city.options[0]=new option('-------',''); 5 _1 I4 u3 ~- c, E0 a
for(i=0;i<temp;i++){ & g, [- w. j0 h3 }7 d7 C3 h
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 7 b% B- `8 l) A1 I, m& s$ y
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); & g' Y% {% Y  K% j+ c6 Y: G
} 2 D/ B4 D1 S/ }  s  I: r' v
} % q$ Z" P0 d4 E4 r8 \5 K8 b% K
}
+ W$ g9 Q0 r; p2 W3 k6 t</script>
1 G3 x) M* Q9 L+ o- x# H; [
- d0 G  W) f5 ?<form name="combo_box">
: F0 _; M- J% U( W0 D, U<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">6 O; ]; v6 o0 X+ z$ W/ E. R" y
  <tr height="24">( @( f' [6 h' f. {
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
! U( ?( V+ p9 u' m& \: U5 M    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>1 T% H( a2 V  e, v
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
5 W- X( Q3 r1 J* `8 a7 M    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>8 n5 Z3 P; {! O2 r2 h8 h& `
  </tr>
. P3 w- r7 B1 P$ y0 ^- g  <tr> - v! ^8 {, j7 i8 E7 o! P
    <td>
$ N, W/ l: q7 W+ [; |6 o( D  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
7 B  ^. W8 D& J% ~) o) N  <option value="0">请选择部门 ---></option>5 j1 W4 s, k, d% ^
<%9 y2 W' O; ^6 v
    string sqld="select * from tdept";
6 G! k: W& F& q6 O  Bstmt=conn.createstatement();
0 s# B2 t9 H8 G/ S% f) j. Krs=stmt.executequery(sqld);) S0 g8 F& F* q
while(rs.next())& y* ?2 ^$ M2 z, ?7 D! M- M
{8 F- e. ^$ r" g5 C  T- F* T( `
%>
7 T: I' O$ V9 ?) t2 X  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>9 D7 X( t5 K; \) t+ f9 r4 }1 V
<%
& P, ~6 r* ~" Y4 D& |$ o}
; ^0 c6 O0 n; I. `%> - t( {  J& g: E4 p- V+ \1 t& `
  </select>
' ^1 l  Y% B' h</td>. d; t0 i6 H5 Z. I
    <td>
7 f) i1 {# Y; [7 K  <select multiple id=city style="width:150;height:200" class="bgc">+ c1 y0 i4 \3 k: y0 z% c
  </select>% r: @7 w" _# d# u; w
</td>/ q8 ^( P* E1 P6 f
    <td nowrap align="center" class="bgc">- x1 B2 S. d( z5 l4 a
  <input type="button"  value="<<" class="buttons">8 c9 F" P. y, n5 o$ j- a8 t
  <input type="button"  value=">>" class="buttons">
. q; W# j% O% w6 j</td>( ~- S1 R' n% E8 W
    <td>* q! M+ A$ q: |/ V- F
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
. k: ^& y# [( B4 h! l! i; w2 n9 g  </select>$ f7 C' s$ ]; K7 M3 y3 s8 l) u. w: }
</td>
; ?8 m/ A) x! F' |: e  </tr>
7 r7 |6 S+ M) k    <tr class="bgc"> 3 i2 P4 R& Q/ Y$ z" n2 [9 Z% I
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>3 ]3 c9 y3 }0 m. H- I, C+ R7 L6 E& m
  </tr>
5 w& F" _+ ?% ~1 C- _7 z8 k, U) C</table>
) [1 f1 g" T- U. @$ g</form>
* _. J& W' ^1 D- Q<script language="javascript">+ ], a: Q3 i  F+ s& r
//人名移动
: v; F3 k+ H  h$ c, j3 xfunction move(fbox, tbox) {
5 @8 }6 E' Q7 R) m, e! ?var arrfbox = new array();
% ]0 C. P& p8 D" ?var arrtbox = new array();
' K+ a" w" d* s  o! V) y+ t4 ^7 hvar arrlookup = new array();) [5 O8 m, u) F. T8 Y
var i;
4 k( G, t: J' hfor (i = 0; i < tbox.options.length; i++) {
* }. t7 h2 W6 ]' H! y; aarrlookup[tbox.options.text] = tbox.options.value;
$ B( |  F0 |; `8 {; o6 @arrtbox = tbox.options.text;4 k! @, ]( `7 D6 K% ]+ d
}; w" X9 W$ R4 j; B
var flength = 0;! G, y1 F3 r, u, m! u7 A, O
var tlength = arrtbox.length;$ z- S0 w) I8 h5 y6 I5 u, Z; P- Q( E
for(i = 0; i < fbox.options.length; i++) {
* o  E5 E  c5 }3 ^1 jarrlookup[fbox.options.text] = fbox.options.value;5 `" Z2 b* G3 P* C' l, P
if (fbox.options.selected && fbox.options.value != "") {! k9 W) X0 @2 d3 g
arrtbox[tlength] = fbox.options.text;
* D8 {: t9 f" _2 n0 N0 R+ Ztlength++;+ @1 V' G5 v1 W
}
0 G6 x! D. U% M! c# belse {% |7 S/ [. ~  _9 h: V8 B- Y
arrfbox[flength] = fbox.options.text;
  J  l, y. t$ n' o- gflength++;
  d) Y3 |9 a! L# u, ]   }
1 q1 f) q! ^! V+ Y& I2 R! t}2 j5 H3 ]/ A# K1 I! X+ P; S: E# I
arrfbox.sort();
( ~* X0 v' q. U& X6 Larrtbox.sort();7 q  f. U# t2 }! e0 D1 n) C" x

* n6 r: i. K- |: G. Nfbox.length = 0;
& U# v% i# V# z! R" d# y9 Wtbox.length = 0;
) E& t$ z7 o- T+ v9 y9 @% E6 ovar c;+ w; |! V, D; I3 D& t; B1 n
for(c = 0; c < arrfbox.length; c++) {$ ]6 E5 t8 v; y9 i, p7 Q
var no = new option();2 o" R4 \4 S3 a
no.value = arrlookup[arrfbox[c]];
9 G1 H: L1 m% k$ uno.text = arrfbox[c];) Q' k  j2 C7 P: G
fbox[c] = no;
3 V& I7 @- t( t8 |}
8 X+ x# ^; [7 |$ K# N* t, e. gfor(c = 0; c < arrtbox.length; c++) {
5 J0 v  X; _  [& n. ]: gvar no = new option();
, q5 _( b! g9 X# E# Ono.value = arrlookup[arrtbox[c]];
/ C) c/ s* y+ D% y4 Bno.text = arrtbox[c];! H5 U8 E' n4 Z0 a1 s% s5 G7 ]
tbox[c] = no;
! C# d% K4 A" R2 l) s  h   }
% C6 w5 k) K5 P. N+ P# L) K}
! R; G+ y7 i( D7 V5 w</script>
6 E4 l5 c- z" ?- [/ ^</body>
) \  C0 J6 k3 ?5 Y! D! Y

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