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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"- A' o" G/ z) j/ o  q
         c pageencoding="gb2312"
/ ^/ Q5 L5 h1 [1 r2 I%>
: x1 V. @9 M9 ?4 r4 b! K( y- Z<style>- Z( _1 U) h5 u* d- j
.f9{ font-size:9pt; }5 n; n# ]8 t4 k5 J+ `
.bgc{ background-color:#aecaf9; color: #0033ff }
$ `9 k3 s  k+ V9 t' t/ J.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
& w$ T# Z7 ~8 D( d% ]  border-bottom: solid 1px #4e7dc1;
1 U% y2 n$ p* f+ u$ J% h! s  border-left: solid 1px #aecaf9;8 w8 x: p2 t; T' [, i- ~9 J
  border-right: solid 1px #5679bd;
( v! K% @: |8 F' E% u  padding:1px;) }! l# w2 U5 B3 L) l
  margin:0px;}
, l) v0 |; M/ ?& u7 N, q  y1 U</style>; |8 }3 _8 q" g
<script language="javascript">
* z  G' ]3 }% k; J7 s3 i5 Z<!--
# s5 V3 y' G/ f; G* p/ kfunction rv()
9 h8 ~% b  i- P) U5 K6 P! P{
  G4 ~2 z% P8 ?. E& X& D0 W$ v  var val="";
: y9 j& W5 U5 P  for(i=0;i<combo_box.list2.length;i++){
+ a; {, b4 i: _: P$ Q   val+=","+combo_box.list2.value;0 P) l" b, x2 k) Q) m: J
  }0 Y6 t; Y1 |+ k$ F$ C; d, Q' c1 I
  if(val.charat(0)==","){0 E4 o7 l6 L7 t) U7 _
   val=val.substr(1,val.length);
6 `" x4 N  n5 x- Q+ }! ~  }8 k- q) l& R; G5 V$ m2 i2 V
  opener.form1.frecname.value=val;- j4 h' I! \8 o/ L! S& ?% }/ m( z& I
  self.close();
7 [" B, H5 t- d. x! d' k}2 u5 M( s! ~- y) j1 y
//-->
9 n' |$ c" s8 e</script>. |( z- v9 [; M/ u" k0 l6 T! l  p; Q
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">* D( m) [" \3 H% R: [
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
- ~* o6 i3 ^; o! F- o2 {- E* c<%& l1 t% n" t9 s, X8 F- A( {3 F' n1 j
  cdatasource ds=new cdatasource();  //数据联结bean实例) z+ C) ]& z" Y& e$ Y$ C0 H
  java.sql.connection conn=ds.getconnection();1 k3 m, ?, k- \' o5 P: M
  java.sql.statement stmt=null;
) t; T1 z* A( z" f4 r1 V; @. ~' P5 _  java.sql.resultset rs=null;
! M% r7 h, i# i  cdatacheck dc=new cdatacheck();1 q5 H; ^' C" @
%>
7 i+ G1 X3 s  Y* M. ?7 ^<%8 s2 L/ B; t2 {. G4 p( i9 h
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";9 o6 ]9 T- o2 x, o* Q
stmt=conn.createstatement();+ N2 m  C7 s* ~, q  h9 ?3 p
rs=stmt.executequery(sqlu);
7 ^; x. i* C$ M$ Q7 [5 m+ P' \%>
+ \" d: K3 [& v- x# ?<script language='javascript'>. |3 l4 o: Q2 A" m" i* g. A
arr = new array();5 k! J, `3 @5 A2 D* Q& Q" s
<%  int temp=0;
% k. _; X7 _8 J: mwhile(rs.next()), t) u; X5 }$ y6 ]- ^7 ]9 O+ y
{
& d7 D, C$ N- e, ?" ^" _" w9 F%>4 T0 A6 ]9 d! ]4 |. g
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
! A# O6 r; H' I, V$ q<%
' i8 h4 G& U+ l. `temp = temp + 1;" @6 b5 M: K" d0 r- n6 L
}" \( v. [( U8 |
%>7 V% ?* |, b$ c, F/ M
temp=<%=temp%>;
- f6 H9 n7 ]3 U+ }) b$ Y! ]7 lfunction changelocation(id){ * U) M6 ^5 I/ x8 g
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 , Q' U) P3 K& E2 C" F/ Y! R
var i = 0; 0 \3 d+ d# I( X# a* m6 _  M! D; H
document.combo_box.city.options[0]=new option('-------','');
; R& n, H5 q( d/ z" Mfor(i=0;i<temp;i++){
  p: x# [/ p9 @' ^. aif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] ; z+ @- R9 G* P5 J
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); : ~- ^9 W- \* M! N
} , J' B/ _  h6 e. Y
} # E( C  @4 T% f' D& m3 Q
}
$ Y1 S0 I( W) t7 W</script>, @1 P+ P' Y( t

3 Z' L" d  N" u& I# _: H<form name="combo_box">  O" H2 B; O  a. B! m, _
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">, m+ y9 A  V/ ^3 S( O: M+ U3 L
  <tr height="24">8 R; B" L* H1 ]; k; A* r
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>( C% h- S4 n9 P4 [* v
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>  A$ H' N' p; f$ b/ M# k
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>0 ~' b3 r: Y) Q; ~) o
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
  T6 T% E3 G: o5 D3 {. E0 w  </tr>9 U, J# @$ b; x; m. H
  <tr>
/ N# ^1 `) a3 m. B' L7 j9 Y    <td>; _% t4 |5 M2 Z+ y$ a/ h5 u
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">8 K  ?# l2 q( e& d3 D  G+ H9 R4 s$ A
  <option value="0">请选择部门 ---></option>
& m3 u4 [) M5 M: p! M<%  g4 {% N7 p) `3 n: X
    string sqld="select * from tdept";, P# ~2 p1 h$ l) b/ }6 {
stmt=conn.createstatement();: C. w; z4 ?# c9 x2 E: c" k7 P
rs=stmt.executequery(sqld);0 {/ z9 G, }4 W% l
while(rs.next())
9 {( h, [! Q; y* Z! `{* j( K0 r+ ]- F0 ^. N" v
%>
) U3 d1 F$ C1 i" q* O  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>9 L& h1 r) T+ Q1 t
<%& w# e3 k3 w/ G9 [  h
}
$ h6 V7 R! t7 j4 `/ d; f" M%> ) P6 [& z2 n9 ]  e! G; \& \
  </select>
4 p8 o. W* {) u# R9 v: A</td>
- z* _! ~: ?/ m) |: d9 Q7 Y! u. j- I    <td>
3 k. q8 x$ ^1 g/ a  t  <select multiple id=city style="width:150;height:200" class="bgc">
+ f. f+ r1 M' d  </select>
* R9 T* q! g- ^. o1 \</td>
. S/ [; R' y0 L( A# A    <td nowrap align="center" class="bgc">  z: [% C5 G6 e
  <input type="button"  value="<<" class="buttons">
+ T0 T2 w8 ^0 s: X" z  <input type="button"  value=">>" class="buttons">$ x$ x) J' ?" s/ b
</td>8 E2 n- T+ r8 m$ o
    <td>
8 }. k0 \- N% t& n/ g  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">6 i; x  T2 [8 t0 W
  </select>
  C2 N9 Q: i7 C( k: e3 O</td>& b# Z* |! d  A) J
  </tr>
+ E+ \* n% b4 K1 H    <tr class="bgc">
4 z; v9 j3 T# x0 r. a# x    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>) R! j; ?# {" v
  </tr>
/ G+ N: W" B: e, O  d</table>& r3 Q6 K/ P6 O7 k8 u& e
</form>: Q  i7 y" n% M9 D
<script language="javascript">) Z7 {) ?& Q; S% z3 T  v
//人名移动, p/ q& C" @) Q  T9 _
function move(fbox, tbox) {
( F$ n7 b% n9 q2 yvar arrfbox = new array();: E8 o1 o7 Z' p0 y
var arrtbox = new array();
$ z- b$ q! ], A9 ~# @var arrlookup = new array();
- f& L/ J4 w, t: u) w: qvar i;
" S* r; W6 I3 hfor (i = 0; i < tbox.options.length; i++) {
, i' x- N8 X* J5 @3 ]  Harrlookup[tbox.options.text] = tbox.options.value;9 o3 Z5 w( f9 o
arrtbox = tbox.options.text;
3 |- A, o. v9 D}# c9 h; ^9 M( |2 N. A. c5 w7 E" v
var flength = 0;
. p( F2 N9 i/ s3 }+ V% fvar tlength = arrtbox.length;
6 z) |$ L7 p6 j1 e, B0 Z1 V& q$ |for(i = 0; i < fbox.options.length; i++) {/ B) r# }) g* l8 g
arrlookup[fbox.options.text] = fbox.options.value;1 y& I! `8 j  `
if (fbox.options.selected && fbox.options.value != "") {
1 g- h: n$ \% ^5 }arrtbox[tlength] = fbox.options.text;- m: ~8 f. |  f- Q4 f
tlength++;
5 `" x4 z7 }) n+ e' H}
* A. S9 C( ]; K5 K  P  ]& aelse {/ U2 Y( G6 _) d7 @6 C  E
arrfbox[flength] = fbox.options.text;! _7 P6 W* S# V: ~% ]  k8 P* i
flength++;
% d8 U) H( b; f; P6 }7 Q   }
9 E& \8 v  {- z+ ?+ R/ R' ]/ ~}- c, C0 k' v" h6 v7 k
arrfbox.sort();
. K! _( ~2 @, ~' j3 {arrtbox.sort();6 M- M/ @. r% q  r3 [

# _/ P! R/ }1 W, \, Q  ?6 F6 x/ Dfbox.length = 0;
8 w0 `) Y; g" ltbox.length = 0;
* x- C0 `' ~( F" J' I  l; lvar c;
; z: O, B* S3 {! k  q8 Zfor(c = 0; c < arrfbox.length; c++) {
: d) ]; f  w) J3 hvar no = new option();
9 j7 W2 C# F4 y" I4 w7 D; R) hno.value = arrlookup[arrfbox[c]];
6 q0 ~& m& u. V! p5 v, n: ?no.text = arrfbox[c];
# s. C: u/ K+ `# Sfbox[c] = no;( X, o: L2 a5 a0 _
}1 P7 s. E/ ~& F; @
for(c = 0; c < arrtbox.length; c++) {& z) a2 F9 {5 E& D7 ?8 C, H
var no = new option();
/ z/ z- |3 Z  \/ I3 Xno.value = arrlookup[arrtbox[c]];4 i% }- J# W7 v* U8 s7 f6 Z( [3 o
no.text = arrtbox[c];9 F* d1 F/ L7 ]% c5 L* a3 J
tbox[c] = no;
& }( u, z5 D$ M. r! O! x9 J. s   }
, N5 S* {. J" r9 I}, ]7 `  C8 l8 g. u
</script>
. ]7 U6 [# ~4 M9 b6 l</body>
  X, R- b* n4 ?/ g5 |' o/ e

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