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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
4 I' P0 W3 h9 r) d8 `! m1 _) c         c pageencoding="gb2312") J' ?+ h: ~& P& |
%>
* [' w* x/ L' ]5 q/ U<style>5 r* N2 v0 c) I$ M7 W2 Z  Q8 n, l
.f9{ font-size:9pt; }
- l2 R0 x7 R8 W5 ]* y5 s# _" ~0 g! |.bgc{ background-color:#aecaf9; color: #0033ff }1 G/ \1 v4 Y: i& i* y
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
+ M) k$ `( ~7 P+ c% I$ n  border-bottom: solid 1px #4e7dc1;( W$ B/ p9 I" }
  border-left: solid 1px #aecaf9;
5 p0 f( `5 [8 F, N  border-right: solid 1px #5679bd;5 T6 C$ b  w  U7 z& R
  padding:1px;) p+ @- O, t3 \1 S! K9 V
  margin:0px;}
) Q& \1 v/ ^  i</style>( C7 _3 Z9 t+ d& s# _& A; X
<script language="javascript">; S+ v7 U0 }, Y  w
<!--' q5 R) @" B! B9 Z9 O7 \" `. m! y
function rv()0 D) n2 n) K2 M" I% u' t3 g
{% d' f1 u3 K& \+ Z& s4 c1 w
  var val="";
9 i* E. j! }! C( P3 M) c- z  for(i=0;i<combo_box.list2.length;i++){
+ ^6 t: E  M. y   val+=","+combo_box.list2.value;
6 p7 w! Q7 O1 j0 z# f6 `  }
  f! `+ Y4 a8 d/ x  if(val.charat(0)==","){
6 O; g9 _. b/ x/ j; e1 U( K   val=val.substr(1,val.length);
# D( W- i! W; r3 C+ W. F  }% g) t4 s; A& z9 q5 u- J; w9 C0 A; K! j
  opener.form1.frecname.value=val;
; H1 K1 L" A6 Y  self.close();1 P1 ~7 `/ h9 j4 V, l' G" h
}
' f, `* }6 H; O/ _+ u0 [//-->. S  Z/ D2 o9 o6 x  |4 k- I
</script>3 p% w  d# `5 `0 y  t4 R! r
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">7 N& e/ v- y2 C5 o$ P
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />  z- B! s$ _+ Q& `
<%
- x- _+ j5 U9 Z  Y0 c2 G  cdatasource ds=new cdatasource();  //数据联结bean实例. g/ t( E0 ]5 x# L
  java.sql.connection conn=ds.getconnection();/ J5 U8 T) l! V2 ~7 K3 U; P
  java.sql.statement stmt=null;4 b& k5 X4 l0 A7 F" A
  java.sql.resultset rs=null;6 T3 T1 Y2 Q% {$ \, A1 H6 ^$ x
  cdatacheck dc=new cdatacheck();
0 }6 ^" H4 U& E: X# T6 E8 H%>- @3 ^# E* b$ b  m( {
<%& ^+ `: D- t8 r! e9 \0 r, [$ D
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";
) z9 ?/ _% U6 s) b7 a: qstmt=conn.createstatement();% m2 U) P0 G4 b
rs=stmt.executequery(sqlu);) U$ B  t7 r8 s7 O8 L& g# Y- n
%>
9 h7 D3 Z7 H$ v) Y* v<script language='javascript'>0 z% d7 V" v1 ?  p+ {. c+ Y
arr = new array();7 ?  f$ U6 ~' S. b* C- n
<%  int temp=0;" f3 {8 ?7 s0 r
while(rs.next())8 L) Y# y9 H+ ^( U! G
{, k0 I# G' u  h
%>% [. o+ O" I: i" {7 W
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
1 ~  b6 r; F5 z9 J  p- Y<%
1 _: [0 [) a! R# g3 N* @0 A$ utemp = temp + 1;
% a; d9 N- n$ {2 Q( v7 i9 ^}9 W2 b2 z' S+ E- n9 x' _
%>9 Y' l7 _, a) l, f& L, s1 o: V
temp=<%=temp%>;" l9 e# z$ _5 J; C. @% n+ o! L
function changelocation(id){
* T1 ]- R2 P( J- N4 Adocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 ! }+ ]! f% h# y) Q
var i = 0;
3 A6 d( ~+ _$ ydocument.combo_box.city.options[0]=new option('-------',''); ( f) b& A0 n8 ?
for(i=0;i<temp;i++){
- i  @4 `9 f, K% i. Z3 P9 oif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
  S& E9 d4 a! Y1 X3 c# |document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); , m$ B8 R: G5 I- x5 D4 N. L: H. J# c
}
6 d, n# c- y, u9 h} 7 x, ~  s. s6 e! @
}
& n, j1 k1 E6 T& t</script>
( {$ ]( ]6 A  B# [- N' L
) ^* e% H/ Q5 H& p& H0 _& W<form name="combo_box">
* x$ t& C( p: r  z* y<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
, o2 ]3 r9 `( ~" @: c7 G7 h  <tr height="24">& h! \) U# X6 u
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>* g. t) R. l8 {/ d$ g& q
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
2 s, D" \0 k$ L0 a1 P    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>6 i  v+ i0 T0 r
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>/ @5 t% U% n8 v4 _. b
  </tr>
  ~6 j3 [. u8 o: `( b  v( t. `  <tr> ( \" Z1 v  |) m& E0 ~& k
    <td>
$ E: c1 R3 |  F  w4 v  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">7 H3 P* {5 k  Z8 P$ e( m) g1 X
  <option value="0">请选择部门 ---></option>
" G$ W, ~) e- |8 V, {<%
9 p4 l6 P* ^6 o7 t, L6 W    string sqld="select * from tdept";
4 a' C/ D& Q5 |stmt=conn.createstatement();. R+ _- J/ W) f
rs=stmt.executequery(sqld);
9 T, v# ]; S" R9 q. j9 Jwhile(rs.next())
% @' G; F. R9 a8 P: E4 u# t{8 P+ m& p7 v4 U8 U
%>
6 e0 U3 I4 C6 ^3 t  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>/ i- a5 A% ^$ g9 O) y2 w& L
<%
7 C& }- B- z$ ^+ m}  @) Q, D3 L( R3 a7 @
%> 9 h' E& Y1 k. o1 m( S4 y7 N* C
  </select>
3 g( A7 ]' d6 \$ a9 e  K( x</td>, p" i# ?& ^: P
    <td>
$ x3 t$ h& u" R1 ?2 M3 Y& s+ H  <select multiple id=city style="width:150;height:200" class="bgc">
( h( m; A( n: U( l6 f  </select>
  A3 h) {$ x2 C6 \+ [</td>
' z" V9 {( n* z# _; K! D    <td nowrap align="center" class="bgc">) A5 F- ^$ a# r& y* S
  <input type="button"  value="<<" class="buttons">
$ d( G6 V: }% |$ Y& M/ d  <input type="button"  value=">>" class="buttons">- c* K, n) p8 H
</td>
% T- l2 w9 B) V% S/ |    <td>: @' ]7 f' r! L: F$ ?
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
- }  @+ ~) P: U) ^! e  i5 R2 I2 d  </select>+ n" G( S0 c4 x2 `( P
</td>. r( v: s' T: s% Z1 F
  </tr>1 Y# m4 X; t1 Z5 @8 M
    <tr class="bgc"> ' k6 v! v$ \1 A2 `8 ^: O% S
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>* m7 k- L  n% U" M7 J1 U" M
  </tr>' @" k1 f4 P; V' z1 \2 [6 f
</table>$ v9 L8 g, f9 j( [3 _1 m
</form>
5 P  ?* ^; m- w" R3 ^# o8 }4 U<script language="javascript">: _+ u$ u" D( P6 J- N
//人名移动& G6 a" N9 o( @" }& U# {6 h
function move(fbox, tbox) {
5 _! z% f+ P: ?4 U) W, Hvar arrfbox = new array();; z6 O! \" `, l0 G' f, C
var arrtbox = new array();8 X' N; P  p, P/ k" {
var arrlookup = new array();
, q! T( H1 _% l7 hvar i;" l( D# t1 y9 e, x) s
for (i = 0; i < tbox.options.length; i++) {* Z- H8 l$ u+ Y+ n# n
arrlookup[tbox.options.text] = tbox.options.value;
. {2 K2 H: i! I9 g4 C5 V+ n( {/ xarrtbox = tbox.options.text;0 \/ O" f0 R( C+ m4 ~# |. O
}
) m0 N+ ~- J- `& Jvar flength = 0;% r: q0 h  s0 ?
var tlength = arrtbox.length;
. u% L5 d2 H, f( R: m2 Lfor(i = 0; i < fbox.options.length; i++) {" E1 E- ]) G! U* w; n; q8 Q
arrlookup[fbox.options.text] = fbox.options.value;
  q: o# N9 L$ W/ B/ i2 W- N8 s# A4 yif (fbox.options.selected && fbox.options.value != "") {- \/ t- `& k# c! F; L$ j* J
arrtbox[tlength] = fbox.options.text;
- P6 e$ r0 T6 ytlength++;4 R* G* `0 C+ R1 ]8 A( q. Q
}
- U6 U4 {9 `  h" U7 z* Z1 {else {
0 `" p4 X1 _: _8 k  y6 warrfbox[flength] = fbox.options.text;
3 _+ Y3 ~. ~7 C7 Cflength++;
+ c4 L% K3 s$ J9 h( ~; Y8 d( R2 L   }
8 L* S& m7 Y1 e2 h1 i}
, m# X  y! P5 {( r* zarrfbox.sort();! k* j0 l5 y) ~; U: [
arrtbox.sort();
9 D" @0 ~, C7 l/ G0 p
  R  Q! f& w- s7 I9 O$ yfbox.length = 0;& |- ~  A/ A& b2 {' Y, ^
tbox.length = 0;
0 `+ m( o$ E# b) c6 S' p4 f3 nvar c;
$ `1 S9 c; G' tfor(c = 0; c < arrfbox.length; c++) {
. o9 E- K! U, r! Y7 _  Y7 cvar no = new option();4 H) b2 Y! t9 |' ]( O
no.value = arrlookup[arrfbox[c]];
/ w; ]1 g* w/ t* tno.text = arrfbox[c];) m3 V; m+ b" Q  h/ H. A4 O
fbox[c] = no;
+ o! [2 O- d" x. S) I4 _! Y+ ], K! f}
1 K5 n" o, i1 r8 b) n  e% X7 _for(c = 0; c < arrtbox.length; c++) {0 {! j0 H2 c8 _0 M/ t$ J* U# J
var no = new option();; C; U! B+ x; x, P2 U9 x
no.value = arrlookup[arrtbox[c]];8 i# @3 W1 ]2 n  r6 C4 `+ b9 v
no.text = arrtbox[c];' n8 Z4 ^" y# A  Q
tbox[c] = no;
0 l4 {8 v' o" f: U" q3 H, o8 `. l   }
( N- i: c2 u( B1 I2 {; q}
( |8 H  M0 ?4 o+ I& F3 r% t! }# V. `1 k. c</script>3 k+ }3 H7 a  |, y
</body>
7 e7 J3 `* c) x/ o3 k( T

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