返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"3 {- F+ e. X3 v9 V% _, c% I8 w) @
         c pageencoding="gb2312"3 a! E5 E3 Y4 e- F. `
%>% X6 a0 X, c: L# u' N
<style>' Z1 Z" c! P- X7 p( b2 H" y3 Z) x
.f9{ font-size:9pt; }3 d: x7 w9 B; L/ ~7 J' f  x' p
.bgc{ background-color:#aecaf9; color: #0033ff }
& D' b$ A% o$ `+ [( U: O.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
% P9 f5 c" v, i  border-bottom: solid 1px #4e7dc1;
6 g. F/ I* y# {/ M1 n6 H  border-left: solid 1px #aecaf9;9 U* i0 m" j0 c# F+ E
  border-right: solid 1px #5679bd;2 W3 Y/ N# j3 i% W$ n0 w$ I
  padding:1px;$ e; O. {! v4 X$ Y" O
  margin:0px;}1 y. o% [0 Y! O/ M5 |. G
</style>
/ _5 |8 b, t* K  ?4 u<script language="javascript">7 O- I' C, B" Y& H' F4 m
<!--9 S! e' r0 ^3 y& b( f
function rv()# M- U9 z& j  g! ~
{+ Q! A1 i4 ?' T; \; Q5 ?- ?
  var val="";! Z4 @( n+ o+ {2 k
  for(i=0;i<combo_box.list2.length;i++){
$ ~; @+ A) C5 L; B( k( |   val+=","+combo_box.list2.value;# M4 H& k; F, s; {6 r- L( X
  }" s  `( J0 u4 z
  if(val.charat(0)==","){
% }1 i) k0 p$ F: f: s8 o4 v* o- e   val=val.substr(1,val.length);1 y- V8 q% [( _
  }: F- S1 {, x# p  J/ b+ p* G
  opener.form1.frecname.value=val;) K0 j- v! u) r: {- u
  self.close();
( X9 A4 C7 Z6 a}
, R* }5 P7 P  M  q" j' z//-->
7 i' V# b5 m: Z0 s2 f</script>
# c1 j/ y: u6 f* G& B, q. a* P$ P3 R<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">: D& C" a: Y9 ~/ u8 I
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />1 f* {: `) c9 G0 A- s- s
<%* F* N7 ~0 e% l5 b
  cdatasource ds=new cdatasource();  //数据联结bean实例
" k7 J( Y) E, g2 Q+ w% u: c  java.sql.connection conn=ds.getconnection();  f% A+ M9 ^$ f2 Y0 L/ M, {% M
  java.sql.statement stmt=null;
( R) m- m: P  B( T  java.sql.resultset rs=null;
) {( L1 t9 l  E( r+ N' U! R( L  cdatacheck dc=new cdatacheck();7 [) q2 R; R) |. ?
%>1 ?* w, ]$ ~1 h; z# z  q1 W7 B
<%0 V; [- h& \) K" {9 {
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";7 d% T2 w, ~. n- r- @
stmt=conn.createstatement();
7 H- D4 M! k" l. c' c- ^. Hrs=stmt.executequery(sqlu);
  F$ f5 D4 N7 S' P%>5 `8 V- \/ }( C( O
<script language='javascript'>
6 N+ I+ x8 H2 M; {% ]2 Xarr = new array();
5 @2 d6 W8 }$ E! T, Y<%  int temp=0;) ]2 q+ L9 _: B6 B/ i: F+ E$ ~" h
while(rs.next())7 ]9 b+ r& n! K
{
) |/ `+ u8 j7 q' W% P0 ]" e. e%>
# j; O2 d" L& u- R; Tarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
/ q0 [- m* K1 ?( Q* }% Z2 \<%% L& _7 t  q( L) W  B5 y% G( _: X
temp = temp + 1;6 x, j  l: F( ~- X
}( N+ P" O2 g( \2 P& g
%>7 x, q& u7 f3 A9 G/ Z
temp=<%=temp%>;% \' J6 ~0 p7 l& A% L  ?! }
function changelocation(id){ $ P* M7 S6 Q0 g/ h/ ^0 V
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
8 g8 m8 L( b0 Y8 D* h+ hvar i = 0; # K# R# z; F- _' _- O
document.combo_box.city.options[0]=new option('-------',''); : C9 j8 a6 `1 f& g0 b  ~
for(i=0;i<temp;i++){ 7 ?) S; s7 c" g! Y5 g" O0 H; e
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
) Q7 W7 i9 h; h7 Z2 @document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); ; d: Q1 w, b# L  D) M0 h' `; B
} 1 x4 ^& T9 \/ f( |4 i
} 8 x3 L( v/ x) [; p  z/ [
}
# Q3 U, T* \7 k! Y  p5 a( D</script>* i4 i: z* ^  L0 l4 J, s8 S
& U: B# X' E: r$ P( @! H% c
<form name="combo_box">  w$ X9 G2 }* m
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
# b6 `, x) C6 ~  <tr height="24">
& K) J  D# O) }% _% B    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
! \; |( E  B& ]! o/ H4 L$ J    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
: u$ G9 w" j* K1 _' e5 k5 M    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td># p- i. y5 q' }) \6 s
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>& d8 Q8 N; G! X9 v
  </tr>
- I' Q% Y1 s# ~; W+ [3 H  <tr>
: N: \; ]2 H1 ]+ v    <td>; Y% l/ S: V" n2 @
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
/ n( R2 A. h2 r' I  <option value="0">请选择部门 ---></option>( J, m& ~9 `$ R4 Y; x
<%
- c! U0 D$ o7 Y) @8 i0 w! R: d    string sqld="select * from tdept";% k2 f# q) {/ P, |4 D
stmt=conn.createstatement();
, I7 X4 ]7 a8 Frs=stmt.executequery(sqld);8 k3 t& N: e3 u& G2 ]
while(rs.next())8 N3 j# l) X( t: j* k  B  |
{
& N: q$ i# ?$ Z* d2 _: b%>
+ @+ d: f- G$ G- B& \  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
3 W4 k9 B: Q  f; B1 J<%" N+ h6 u# W, K7 I; ~  u7 V* X5 c: T
}. V# t) u+ @# N
%>
9 C: M7 @; r8 _0 z& v+ v1 c  </select>  i4 a% A  R( ^, T7 A
</td>
/ ]! f0 n$ k' m( C/ u, e8 l    <td>9 y/ F" y% F% Q7 w) P
  <select multiple id=city style="width:150;height:200" class="bgc">/ y" n1 o0 |; g* z
  </select>1 J6 U3 V& v" p% C' R
</td>
# m8 ~8 P3 u2 e+ Y8 l% r    <td nowrap align="center" class="bgc">! |! G& w' ~+ a) @2 ~
  <input type="button"  value="<<" class="buttons"># ~, ]( Z$ H' s9 X( E. T' p+ V% f
  <input type="button"  value=">>" class="buttons">
2 D1 \6 H- n2 j0 x2 S</td>) I0 L- D3 b; B5 [( j
    <td>3 ]  J5 q" G! P' N4 {3 o4 }
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">4 d1 I) b% z! ]
  </select>9 \+ F' N$ E4 X$ w+ ~
</td>
  t% E- d, [1 n$ S) v; Z0 n, c  </tr>
" o4 n/ p' p- k: o    <tr class="bgc"> 6 E+ B& L3 h/ c
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
8 F. r) l4 e9 I" P5 d  </tr>6 S+ @/ v6 d' s% @
</table>
; J0 K! {1 Y1 n8 ~</form>
+ k( a- _1 n3 y% h' Q<script language="javascript">0 P7 P- @' y( W4 \7 D9 y- g/ l$ k
//人名移动
) c2 a" V1 y" H1 w6 Pfunction move(fbox, tbox) {# }- a4 X; N( Q( U" g) J: N
var arrfbox = new array();
% B2 k& Y$ e9 ?" L# Jvar arrtbox = new array();
  W' p9 L5 @- @+ }; K# ]; gvar arrlookup = new array();
+ c' v6 t% }+ D/ {% `var i;5 y/ _7 L0 W6 x, O+ \: q+ U- ^
for (i = 0; i < tbox.options.length; i++) {
% n  G7 p: K3 t; _6 a4 D$ w8 L1 P1 marrlookup[tbox.options.text] = tbox.options.value;
$ i1 r, G1 M, A6 {; xarrtbox = tbox.options.text;
% y$ w0 A' P8 l! ]$ Q}
, K1 L9 d! e* F6 W" [6 i+ ~8 Nvar flength = 0;
1 D6 z& X, ~( R0 Yvar tlength = arrtbox.length;
" l1 [) C7 |: Z% U! ufor(i = 0; i < fbox.options.length; i++) {: n6 |& W8 w' e2 Z0 U+ h
arrlookup[fbox.options.text] = fbox.options.value;
7 I" M: a6 b$ S) t( E8 t6 w  S! z) Eif (fbox.options.selected && fbox.options.value != "") {* D0 x( a9 E. ~. e/ D: T4 X
arrtbox[tlength] = fbox.options.text;
3 _0 g) `* x- D$ \( s3 t( ltlength++;; R& E8 X* T% p) }( d  Q/ k
}& q( \7 }! {$ `
else {5 k0 q2 t+ r0 b( R
arrfbox[flength] = fbox.options.text;
! H3 l; u" P5 W8 aflength++;& S  _2 y& }* C( X' s# N& H" I. A; s$ l
   }
0 s3 [- V  `2 e* a4 Y8 C4 Y}
2 }- O/ K/ x/ P; \; n: }1 c+ narrfbox.sort();
* u6 {8 ?' M4 Q( p; E! a8 Larrtbox.sort();* I6 o+ x1 B# _# {, L! \2 o* ^
! h8 ]) ?9 J, q' l8 w
fbox.length = 0;: t' J3 k# ~2 H, R9 f
tbox.length = 0;
8 h( p2 R5 M- p7 M# J7 ovar c;
' \* P. o0 t1 K2 g6 T+ h+ Y' J, @6 Efor(c = 0; c < arrfbox.length; c++) {
# y1 P4 t$ |2 j& Ivar no = new option();
! I1 Q9 N# H  B  s0 g4 k5 hno.value = arrlookup[arrfbox[c]];9 H  k9 L7 k- G- a9 ~" Y' P+ O8 T
no.text = arrfbox[c];$ n2 p# O% ^& e* J- G1 `. J$ ^
fbox[c] = no;0 k7 G0 q; D7 x
}" y$ v9 o9 m2 {0 r6 B6 d
for(c = 0; c < arrtbox.length; c++) {. N( t: |' P- |& v
var no = new option();
% u0 b! Z; H$ I8 V. _+ }7 \no.value = arrlookup[arrtbox[c]];
4 |5 R) A# \& G' l" G4 t9 Ino.text = arrtbox[c];$ f3 t; z! `- {, e
tbox[c] = no;6 W+ U4 q: y! r" i, C. W
   }: j7 f/ i: u4 n/ j  P' U
}
6 _7 v9 @0 x6 k</script>
) \' O& q: R2 y  Y6 B! D</body>
4 G0 H) }* q. i7 }

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