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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
. R: r2 p0 `) z/ z         c pageencoding="gb2312"9 T# T8 q& ~3 ?: u$ Q
%>4 B4 M1 y/ j: @) G, ~$ X: u5 l
<style>
! L$ L7 T  C- m8 \1 V# w.f9{ font-size:9pt; }8 x3 M! Z0 A: {- _3 F
.bgc{ background-color:#aecaf9; color: #0033ff }4 v; C) V2 C" w" [* R
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
# d9 j8 v! J/ t# U  border-bottom: solid 1px #4e7dc1;8 t5 t" ]& x- p6 |
  border-left: solid 1px #aecaf9;
/ M% f( M4 r5 ]2 M  border-right: solid 1px #5679bd;
' y1 ~. }$ `$ p  padding:1px;2 i$ @  l! ^) f: K8 {
  margin:0px;}& N, W4 Q+ M& H3 K8 L
</style>
7 q) S5 K: R1 g- o3 w<script language="javascript">! t$ a/ {! \# c7 ~
<!--$ `0 {% r$ P$ U7 k
function rv()
5 ?" l! s( n- L' X1 z: r{
1 g% r/ O. D- E& q2 b& k- |  var val="";  e) {" p# a1 D; T' j5 c  o
  for(i=0;i<combo_box.list2.length;i++){
4 p& ~4 b% J4 I2 |& \9 O   val+=","+combo_box.list2.value;
; F0 P! p/ Z1 d6 Q1 D) k/ ?7 {: o  }
& p: A) e( Y3 l5 R  if(val.charat(0)==","){
- U- y2 S8 d1 p/ w: E   val=val.substr(1,val.length);
' \& N- F  }3 y& c; x& f! x+ _  }$ I+ C( k! i1 u- A
  opener.form1.frecname.value=val;" G) H9 h9 Z  w0 L+ s5 b
  self.close();6 }9 b, Y6 d& T, o; }2 g6 `
}
# K0 {  s$ w5 ^0 ?3 \- C3 |8 e' Z% T- |//-->
+ t, }* R: T- o0 u</script>- H6 V0 P1 C" y
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">9 Z$ ]" U5 I* [, r( s+ g( ]- U; b
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />% y7 R% E; J; M3 s
<%
9 t3 E0 w* A& E( m! h' R  cdatasource ds=new cdatasource();  //数据联结bean实例/ ^- F4 r3 F; L+ [5 \) E
  java.sql.connection conn=ds.getconnection();
( `) ~* ]! h3 n9 m* F1 q. s  java.sql.statement stmt=null;
/ K: K" o4 K  m* B! P  j  java.sql.resultset rs=null;
3 ]" l, X- f( W8 a$ h  cdatacheck dc=new cdatacheck();
( y3 T! s1 F/ V; v%>
! P& u9 g! W0 M9 Z% d+ y& S9 ?0 h<%
, g9 o; S* T9 U- V$ ~0 l$ z5 M& P# nstring 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";
% d' ?  q% @; W' t# ?/ X' lstmt=conn.createstatement();
8 H. @$ C9 R4 W; J9 {rs=stmt.executequery(sqlu);: G2 F) r' X4 O/ i- B1 m
%>" n5 d, m( i- @- K1 }- p: t
<script language='javascript'>9 I1 a1 U; _) J# n
arr = new array();+ ]2 I1 t0 B' ]2 ~5 J8 P% ~
<%  int temp=0;
' `! u0 }; l. V/ H* ]8 x4 ~while(rs.next())+ R: a; o, `/ C5 M
{& j( W9 M8 r( p- f  |
%>3 s2 I8 ^% V$ Q1 N8 b( l5 A) D. W
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
- z5 C% f0 t9 _, S5 q/ A: k<%% P% {9 j; J8 u. O; N# b( M
temp = temp + 1;
+ d8 y' R! U/ ]9 h+ m}
' W' J/ H- P' x3 e%>
: U+ X! Z+ N, {( ]: B7 u' }) Itemp=<%=temp%>;/ E7 e+ ^- j% w  t2 x/ q" F- _& z
function changelocation(id){
+ \1 ^- H8 ^* V1 B( g. i: \document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
( W& ^+ j  d; _3 L6 i: q; Bvar i = 0; & Y+ M/ T' N) `! R, ]* ?9 Z
document.combo_box.city.options[0]=new option('-------','');
# }% `  E* {4 b9 E& R( o' qfor(i=0;i<temp;i++){
0 J! d4 L$ \  o& Q6 Nif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 6 @- P6 v+ ^. Y. C2 ]/ x6 [
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 9 S; e! N/ E9 h, d! R  }
}
8 X! i* v/ F7 N} 8 P2 h3 s  E4 Z! u( D. Y
} 7 o: A. ?$ |" v  V
</script>- R* q+ l3 b. D8 H

# Y* U/ ~8 o  z<form name="combo_box">
5 O4 T4 C  L* V<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
* ?/ F; X) e$ s1 _/ K: j  <tr height="24">
, Z  Z& ^$ Z$ m; X6 P7 q6 Z* |    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>4 B' I9 V5 f/ Y
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>6 I$ Y$ X, z3 l& j
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>& q/ c; Y3 ^$ l* r( ]$ t8 r, l9 i
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>! X* F3 w  t- `9 d% X8 v4 q
  </tr>, Y2 V& v0 Q! D  q( k  l; F( P
  <tr>
" Z9 o" ~* J  P: t( C( h: k    <td>
/ ~% Q, f; C4 m# T  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
: e, H  C3 {& z1 P! t* a  <option value="0">请选择部门 ---></option>+ q8 u" O+ r4 N1 L0 K. ?4 o) t
<%: r8 A1 X8 n  U( q2 J
    string sqld="select * from tdept";
% Y, Q( d# W( L; |  o% E' Sstmt=conn.createstatement();% A4 r" h- n( S) ]+ `
rs=stmt.executequery(sqld);
. ?$ J, p0 h# X# `: v8 bwhile(rs.next())8 I7 C7 |/ m* K
{
' `4 s* ^( n& d, O%>
4 I# A1 }7 h# E5 D1 p8 F  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>2 ~. c, D+ y- y+ c+ s& F* f% P6 E- U
<%
1 `/ I5 |5 t8 F; }}
! o( Z0 v" ]- z  o%> , ^$ `5 x$ p, h& D% M9 i1 L
  </select>
( r; `; ^$ ?$ o- W; f/ S1 x* }</td>( C; p5 v% G' P
    <td>
6 K& I6 K" p. H5 E9 b  <select multiple id=city style="width:150;height:200" class="bgc">
1 b+ M( m" Q( N; g, j5 W6 Z  </select>
- A9 i9 S$ X/ o5 T</td>
" s( L3 p$ j# o( }* r" [    <td nowrap align="center" class="bgc">
- C! V+ S3 d! ?' c/ e+ Z  <input type="button"  value="<<" class="buttons">. B3 b8 c5 x1 S* T+ A& {. w
  <input type="button"  value=">>" class="buttons">. Y8 Q$ {% v  K3 i- x% b
</td>
$ O& [7 x; [' u& I9 \    <td>
2 k6 l1 b  m, t7 g  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
0 ?& A7 M5 M: t9 o1 K  </select>
& k2 J' n# J) y* U$ Z</td>
8 K. l; Q0 _! z) N  </tr>" Q! p" i% x/ r' b
    <tr class="bgc">   s, j7 p8 O3 L' w  u
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
0 D& f2 b4 U' n' P2 |2 y0 _  </tr>
4 z3 m, O9 X  M4 Q( o  {4 \</table>
. e! n9 ~: c3 L2 D( |9 D</form>
, j  _) f$ o* v) W/ X<script language="javascript">: q- ]' k- Z" F9 [7 I; F
//人名移动! E% X- H1 F  N: J4 u$ A3 t2 @
function move(fbox, tbox) {& y; D$ V5 k! o) c
var arrfbox = new array();
- x1 ~4 |4 s# I) A/ t7 Gvar arrtbox = new array();
8 U) g4 j! _. g9 P0 @4 `+ d. `var arrlookup = new array();+ U  X9 U4 O5 d/ Q3 F, m% K) B
var i;7 _( t; w* J' o
for (i = 0; i < tbox.options.length; i++) {
1 y  X/ H; b' [2 k8 carrlookup[tbox.options.text] = tbox.options.value;1 T6 m# b  n$ w( E; ], D+ O
arrtbox = tbox.options.text;) C) R0 ~  K* ]* E  I  p, d
}/ b, l5 S+ \* c
var flength = 0;
. s& J: P+ o3 P0 Hvar tlength = arrtbox.length;/ f$ \6 e& [# P, \# a
for(i = 0; i < fbox.options.length; i++) {
0 u0 D, L% D6 ?% W( S$ K% d2 tarrlookup[fbox.options.text] = fbox.options.value;2 }/ W6 n; i4 r+ ?
if (fbox.options.selected && fbox.options.value != "") {0 H; E: P/ R# L. K7 \
arrtbox[tlength] = fbox.options.text;5 z1 L% q* D: X3 _5 u
tlength++;
0 h  `7 h) w" Q8 Y4 p) L}
7 O0 d. d9 k, }2 ]0 @else {
4 W) l2 M& \, M( q  Q* l9 ~4 Karrfbox[flength] = fbox.options.text;
% b6 A8 ^2 i; t$ Dflength++;. B) s6 c, ]+ v8 ?& w& c# x
   }0 C* g0 }! N6 _3 D3 _+ S1 `
}1 S8 A( g- d" A( ?: s
arrfbox.sort();) q; h2 v! i2 u. t/ D5 V0 M! |1 s6 [" c
arrtbox.sort();
# p3 U+ E# z8 y) I$ q
, N5 n+ ^4 X% z) M8 T/ l8 S' \fbox.length = 0;2 O% y  x0 l3 \, Z" K! i6 f. }
tbox.length = 0;/ ~5 x4 ]1 W: k* ^" ~; m
var c;
0 u* h8 p9 T! g( Q( `+ s1 F  ffor(c = 0; c < arrfbox.length; c++) {( X: l; ^! W1 M0 P
var no = new option();( r# q1 H8 e8 S- P" O7 {
no.value = arrlookup[arrfbox[c]];( e6 T% [# C. T& p) Y1 o
no.text = arrfbox[c];4 q7 s* i1 N5 [, {& T
fbox[c] = no;9 M. |$ n  U1 x4 k7 F2 a' V; m
}, C& m4 ?/ |7 k0 h) d  B& h
for(c = 0; c < arrtbox.length; c++) {
  w# a7 h# V: Y6 Y$ s( v  L5 P0 b/ Ivar no = new option();
0 i! H9 ]/ w9 }. U. K, Q4 q  Rno.value = arrlookup[arrtbox[c]];
" [* H( h- X: |1 W, f5 ~" Y. K* Bno.text = arrtbox[c];: `  t/ n' c4 B- a
tbox[c] = no;
$ `0 Z7 {4 o- P! d2 z% `   }
' ^$ B9 P/ o/ x/ h+ n}
) x; O; R. G+ o% a</script>  n0 `5 f4 s4 x* h7 w$ P" a; j( p
</body>
) r9 W3 h- Y/ ~. I& i

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