返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
, B' s  C7 A* y# ~2 f6 G* V         c pageencoding="gb2312"
1 `* N* K7 P8 U3 i%>
; ^' n3 D; f( m! v- L5 [" O<style>, v) h, l, e) M8 T! R0 t
.f9{ font-size:9pt; }
+ w- V8 ]7 A& \" }) o, Q+ j.bgc{ background-color:#aecaf9; color: #0033ff }
5 @* g% V+ c, t% p% s2 R.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
* {0 I" k1 p& T! a3 O3 \  border-bottom: solid 1px #4e7dc1;7 e- |. B" E: B& h# ^' k& T  H
  border-left: solid 1px #aecaf9;9 `% h5 L$ v3 V! K" l
  border-right: solid 1px #5679bd;) h. {# t6 |# G: w0 L  |6 r4 N. D
  padding:1px;
2 R! r9 P3 D8 _0 ~/ Q) u1 j( [  margin:0px;}
) r" ?; Q' O$ N$ ]  `</style>
/ S  P+ \  ]8 x<script language="javascript">5 h. {1 M$ H/ K4 e0 J0 x9 w6 c4 y
<!--. V0 k* q5 a4 N  s- z
function rv()3 f: q+ _+ q# B0 P# {. H
{
  A! s: J: f4 N  G  var val="";
4 L  `' u" i" w* O  `2 p8 }  for(i=0;i<combo_box.list2.length;i++){
$ N7 R, M0 v4 m   val+=","+combo_box.list2.value;
$ n2 S# l+ w8 z. N8 _  }
0 U1 ?+ _6 f5 _6 t$ {  if(val.charat(0)==","){
. ?$ E8 G2 [9 @: j8 y5 d2 ^0 l   val=val.substr(1,val.length);
2 z, J5 ?( t; C' K2 A. ]  }: I5 @- C& B' s! Y5 ?
  opener.form1.frecname.value=val;
& k. x3 Y- W- S  h  self.close();
' n! h" o7 {7 L( H# k& _}
3 B8 W1 q* Y. X/ t( }//-->
$ }: A/ D. f& ~</script>& W: l' M% C, K/ i" Q3 h; ]
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
+ b+ ~; P. ]4 V; E4 @( p! ]<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />' a, N2 q+ J' x8 d0 r
<%" p, g4 t7 T- l- ^/ \  m! a8 \
  cdatasource ds=new cdatasource();  //数据联结bean实例
5 I' m' H& s- n- I( p  java.sql.connection conn=ds.getconnection();1 M3 o/ d" t8 J6 a  {: `& p" P6 m
  java.sql.statement stmt=null;
5 N+ h2 G, l* Q5 Q4 }7 h1 h  java.sql.resultset rs=null;4 T3 y) E% V# J$ ?  s
  cdatacheck dc=new cdatacheck();
5 Y6 ]2 q+ |+ L: V%>
( I7 _! K0 ~8 C+ k: V+ Y' S( ]<%
* ^4 f$ Y+ F2 `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";
; ^  J3 h/ W( X4 x; a8 ^. kstmt=conn.createstatement();  z5 P3 i% d& A) ^" z
rs=stmt.executequery(sqlu);
9 Y3 b0 [. F) V' W%>
! y6 g$ h0 o2 ~: V$ g<script language='javascript'>
1 o% _4 a4 h* u8 l8 L3 p" rarr = new array();
5 \8 l6 \" m# S1 ?' J9 K. E<%  int temp=0;
) e3 c2 s" u: A. e) Iwhile(rs.next())( q8 Y  l$ p/ v7 ]
{
( V# B  b5 ^! j0 A7 }%>: R3 P4 z  X( G3 {: X
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");0 N% A' I/ u; ~; B  F+ `7 P9 V' I& e
<%
' L1 n/ T* l3 W0 C1 Y. Qtemp = temp + 1;
7 W# x* k2 Q* \4 B}
0 D  J' ^9 w  p+ f0 }%>
7 y7 \% j3 b$ p# g9 J0 g* Ctemp=<%=temp%>;; B: i4 a$ f" |. C8 W7 X
function changelocation(id){ 4 X' l4 L9 v3 L
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
! k) I+ E% D% v+ x5 Avar i = 0;
1 h: A% B0 F1 ?2 bdocument.combo_box.city.options[0]=new option('-------','');
6 _' b) W' C3 p/ ]4 yfor(i=0;i<temp;i++){
1 X: P$ i& w$ C* e% `, j0 Fif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
' p) n- P5 l1 Z, b" _! H8 G1 Cdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
3 d- t6 N" [$ q7 i4 U6 N5 A} 7 ]2 i. f! P9 I7 P( s2 Y
} 8 ^; B* Z3 H' V- i6 o) o
} ' z3 B& p; o6 D, t+ `& S5 P$ P& \4 z
</script>
7 _1 t' [, Y9 o/ p0 o5 }' B) z# |9 f6 Z  ^4 D
<form name="combo_box">0 b; \' x9 S# y; Z2 `$ z: l6 e
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
5 I( a$ I+ l  M7 G  <tr height="24">
; _: F. c# M7 f1 g; H, r    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
8 R( c& q2 e- Z6 l! [    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>5 W8 M" }# a( }
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
4 B. D+ n; c% C7 P    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
( _  N# R: }( `  </tr>
: ]1 `/ C# x: r2 P  <tr>
, G7 _2 k* F# |8 T    <td>
0 I- f( s# O0 o5 c7 [  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">) Z6 y' E: W$ f1 i# i% [8 `
  <option value="0">请选择部门 ---></option>% ]) q$ `- I2 |; ], y0 H
<%
' U' i$ u) ]" W- O    string sqld="select * from tdept";' |8 E) q6 w3 P  I2 ]& x' A
stmt=conn.createstatement();
% c  D. g# ]6 `% [9 ]rs=stmt.executequery(sqld);) _/ V( v; G! x0 c
while(rs.next()), h3 m" K1 ^/ B; p
{
5 w3 w2 D0 F2 p: Q- g8 W2 @1 \%>
( K" k; z3 m( W1 \+ F4 d  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>$ i4 y/ D" I( y  T9 r
<%
# \3 [: K' p1 s; Z8 ?" k: o; i}! Q. x3 |' z  P5 E" w
%> 5 N, D( @+ c. `: Z
  </select>5 j  @7 |. [- I4 G# o6 @5 [$ z& `
</td>4 a7 X3 C  X0 a9 I
    <td>+ O' Q( R7 W+ r" E( s4 @
  <select multiple id=city style="width:150;height:200" class="bgc">0 z7 J4 o& K' n! v! t
  </select>
6 X+ E, }( d& |1 p9 j- l7 }% q0 |/ B</td>/ L4 V) b- \( m) ^9 l, a
    <td nowrap align="center" class="bgc">8 C6 j& j, t* D% Q6 N
  <input type="button"  value="<<" class="buttons">. n) z2 X8 ?. v  x; ?/ [5 i
  <input type="button"  value=">>" class="buttons">( M3 O  m" g1 p
</td>; i' H. b1 X# O6 s, H0 c
    <td>
+ q: B8 l0 h9 W4 F  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
4 J2 R' A0 N2 }& [  </select>4 y' I7 U8 w0 o
</td>; G$ ]( l* Y. k$ }4 t9 R
  </tr>/ F: {4 T9 `2 g8 A" T
    <tr class="bgc"> % }$ K9 V" A  g( {
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td># F! i2 p) H# `2 y
  </tr>
$ x1 x1 O& A, z9 f- O( d</table>
: o3 v. `& a' D0 `, ~</form>7 l  u) W; U0 M+ g3 C
<script language="javascript">* U/ m) q8 h" ]- Z% n  |
//人名移动" R9 m& ~7 A4 |- n4 ~
function move(fbox, tbox) {
% g& Y" ~8 ~0 `6 Hvar arrfbox = new array();  z- I4 F! N8 K# |& ]9 O! O
var arrtbox = new array();
7 p# i0 l  l% s% c+ [var arrlookup = new array();
1 ]) E2 f" R$ m, V( dvar i;. |9 V, U2 F3 e: a
for (i = 0; i < tbox.options.length; i++) {9 V2 X& b7 Z) A" c& D; x5 H
arrlookup[tbox.options.text] = tbox.options.value;% V# ~5 w' o, [5 N; `) X3 F
arrtbox = tbox.options.text;
# ?: ?/ ^5 z! Q5 O6 }}' U* ~& {; v0 b) [- i) }  ~& I
var flength = 0;
2 }! A+ w" j2 @* f2 w1 S- _var tlength = arrtbox.length;
! ?( d- s5 L: S: x8 ~6 g' y6 \4 t+ kfor(i = 0; i < fbox.options.length; i++) {6 q+ H. g# o8 n+ _8 Q2 q) e
arrlookup[fbox.options.text] = fbox.options.value;
  c/ L6 J% X$ dif (fbox.options.selected && fbox.options.value != "") {7 M# |; A# j9 Y& O2 B* ^5 [
arrtbox[tlength] = fbox.options.text;
8 t* q+ {% p! e$ G. i1 Ztlength++;
* A6 \, @) n' h4 L! q; C}
: z6 z# ~" x8 {* K/ h# Belse {
& [' f& {) \3 C) K' carrfbox[flength] = fbox.options.text;9 a% x0 {; J: ]* U5 y
flength++;8 e( K: j/ m$ o: X2 @4 y' f
   }+ h4 k% [: e, l* i# Y! I2 B' ~) y
}- C+ {0 D8 S* ]0 r9 y/ k
arrfbox.sort();) d, m. e3 s3 q
arrtbox.sort();
* P3 z- O7 P; E7 k5 ?8 Z7 K2 D* [* ~1 b
fbox.length = 0;$ @( u: Z, j7 i/ S& l
tbox.length = 0;
6 q/ v/ t+ s' _  g& Ivar c;
# S2 |7 O1 y+ N# W5 C; Gfor(c = 0; c < arrfbox.length; c++) {7 X2 [' }! t# e  T
var no = new option();
  @6 ^& t/ f3 M; v' T, V) Dno.value = arrlookup[arrfbox[c]];
$ x/ v" \3 I" C3 o  g3 bno.text = arrfbox[c];
& p& o2 g4 ]& [' j6 F2 N0 Wfbox[c] = no;$ T" {. Y: o+ U0 i
}
9 _6 {, K1 J7 L) ]' }# Efor(c = 0; c < arrtbox.length; c++) {
3 S- z, J( V5 z/ s! A- Mvar no = new option();
! m3 t3 `& n. v, V* p7 O8 [  Cno.value = arrlookup[arrtbox[c]];" W' U) x8 w% q6 C7 `- F' V# k
no.text = arrtbox[c];
" R% W4 M* x: [; Vtbox[c] = no;
0 `& j) H% W$ o, ^/ S& N; Z   }
, w0 d' j' [8 N}
9 X+ B- }/ N- X4 R  I/ Q" N0 O! C</script>
. {' Y1 ?: s9 x8 c" ^& n+ ]# x& L</body>' M0 i7 n$ ^  e& w7 e

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