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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
9 E. K9 t' X6 D2 S         c pageencoding="gb2312"
# @- \  H; f! p%>
) w* C2 f; j1 p' n<style>
: E* R: Y0 O# T! T* L9 L# D) n$ c.f9{ font-size:9pt; }
  J) s/ R8 |  H/ e$ s0 Y9 R3 }! B, i.bgc{ background-color:#aecaf9; color: #0033ff }
3 W7 T% U: |4 f" |! r( y.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;9 i! o- ]; d/ M) T
  border-bottom: solid 1px #4e7dc1;0 o9 }/ P% F9 B3 K. B! R5 c
  border-left: solid 1px #aecaf9;+ I" E# m' W% F+ ~  B* m8 k2 j
  border-right: solid 1px #5679bd;
' G  X, g4 g0 M/ H9 y! i  padding:1px;; r( `6 s3 b) ]3 j7 k  r! G/ f
  margin:0px;}
9 {. Y' F6 g3 q& j</style>; w$ w6 {" A; S/ ~8 H3 T
<script language="javascript">
( _* E4 Z  D5 U& U0 Z: k<!--
# ^6 J) j# _- _function rv()
' D; T0 U2 G9 b3 t; n{* j0 y5 l* U. I! C/ B  u/ c5 z: M
  var val="";9 H( k5 x1 A' z
  for(i=0;i<combo_box.list2.length;i++){
! b* ~. [. J" h' {+ c: _% I% ^   val+=","+combo_box.list2.value;
9 h2 ]6 d& e. m$ p" G* `( |6 i1 G  }5 J5 H4 W5 k; I/ X+ z' y
  if(val.charat(0)==","){  _: u; Y' q3 [
   val=val.substr(1,val.length);$ w, W) H0 w( \0 `* u
  }* Y  B% ^* n( w3 C* F, I% ~
  opener.form1.frecname.value=val;+ Z$ M7 V0 e9 B2 q8 g) V# C: f# p3 i$ O
  self.close();8 Y) Y9 }: D3 B1 f
}
6 \' `6 X& _1 n( u  e, ]; p//-->$ @7 b* M& Y( K, k
</script>
4 a  j: o0 e1 k4 P/ n& m/ S3 z( v2 l<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
3 k* O, j. u: i' b# _6 O  [<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
5 L4 B2 ]7 ~( J9 \5 M" n<%5 J2 J% z1 K9 I' a! y( g+ D, g" F
  cdatasource ds=new cdatasource();  //数据联结bean实例- Y, v. P8 z: W' I+ ^& ~' b* ]
  java.sql.connection conn=ds.getconnection();" D1 s8 q* B: D3 {* y. I( B5 x+ {
  java.sql.statement stmt=null;
% Q" Y, t7 J+ V  java.sql.resultset rs=null;9 E7 i: r7 o+ C, T' N+ ^" R; E; x2 E
  cdatacheck dc=new cdatacheck();
$ o1 L% ^. a# i: l%>4 t  S1 b  o3 }/ F
<%" m$ E; ?" [/ n: s8 t
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";) F/ E+ D* r' X$ i
stmt=conn.createstatement();
  D1 U6 Q( W$ S; s5 F8 [& Crs=stmt.executequery(sqlu);
2 [+ k/ z- s( b/ y8 L%>
# `: ^/ n9 b. j- M<script language='javascript'>$ p/ N7 P+ ~6 K3 R- |' h) d
arr = new array();# F/ F. s+ s' R1 p' Q. H) R
<%  int temp=0;
. G9 G3 r1 E9 K# W1 j7 Gwhile(rs.next())+ y3 U! o0 t* r; W- L; P
{4 Y* z5 ?+ c1 m
%>' w; T; M0 b8 [% F% {
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");+ H" S1 E; z# w& E( L
<%$ Y/ w  [9 O" I$ i$ X& C: K3 h
temp = temp + 1;, Q$ S4 y, H5 ]3 n! q# I
}2 H' F$ K, {2 j9 \' z
%>
8 ~9 E6 M% i0 S0 O) i: D" jtemp=<%=temp%>;
& {. u' r3 ~3 n; p- cfunction changelocation(id){
' V5 x- K( k* `" [document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 1 j* T# x) t% o: g; F/ X# m  S
var i = 0;
, i; I' P* s+ m4 p7 D, Xdocument.combo_box.city.options[0]=new option('-------',''); ) j2 Z* }: f; m+ j
for(i=0;i<temp;i++){ 5 G' W' l; V) d1 t0 I
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
3 ^( L+ l* |- q! F& U  ^; s% jdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
+ c$ }, Q; `3 V& D) R}
# h4 }; z' o6 s1 |  q6 c& B% o; j) ]}
# `: K8 b. c$ r1 q. ]} , n" @" ^* Y( H+ F6 \" s/ T# `
</script>" z3 i* K4 C' C

; F, {' ]  M" R6 d* I& |% o<form name="combo_box">! ?9 C+ }/ K- Q! x" k7 m
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
4 S, P0 N4 k0 o6 |, h! y" N  <tr height="24">& T" l, b5 @$ ^9 V- B. L
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>2 }1 s0 @! k4 s. C& N/ j
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
" w) F7 E+ d, D1 d8 x    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
3 f/ ^7 C$ D2 Q% G6 f' U$ ~    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
: V  Y  T, O! `' E3 M) q  </tr>
; P; Q7 a& |- T) l- q) M, m* m5 k  <tr>
( w6 ~6 @6 v9 D    <td>
; `: Y. I" z- B# F. M/ N' O  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">$ v$ V4 c6 r' J4 |3 ?; i
  <option value="0">请选择部门 ---></option>' ^2 K- C: ]7 k% v% |+ r
<%8 s. M* E5 G" {  J- k8 ?& Y
    string sqld="select * from tdept";4 `$ u, \7 h  B5 r) L, o! x7 I3 ]" |
stmt=conn.createstatement();
' |8 I. t) x$ ~' a+ K; n, T" i1 b3 Crs=stmt.executequery(sqld);/ M7 B* |7 J! M2 `: `: V
while(rs.next())  x0 Y5 S2 `" P
{5 K+ ~& Y- R  w) q6 H* I/ s
%>. l0 x/ o1 a; D  J& p* [( T4 o
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
) I# |! `0 u6 B8 I0 U  r- d<%
7 b6 @% c7 b% Q5 r% D2 H: m, e}
7 p6 K' k4 h/ W%> 4 S0 n; b- R: J
  </select>1 j5 H& l" s  X
</td>- d( U/ A9 }9 Q0 u9 Z) s1 Q% e
    <td>6 f) _4 w2 D1 N/ J+ ~. v+ U
  <select multiple id=city style="width:150;height:200" class="bgc">
0 J& E2 E9 C$ ~3 X2 j  </select>; ]& x# O. h$ R% m
</td>
& l" \( S! H: T  k( z/ x    <td nowrap align="center" class="bgc">
' R/ r& J, G  U5 I  <input type="button"  value="<<" class="buttons">% K8 X9 W3 t# y: W; p3 f2 D
  <input type="button"  value=">>" class="buttons">. I" g& e/ `4 y2 t# a/ Q7 C' h( P
</td>+ L' p5 O: |, R: C% w6 c; Y9 J
    <td>; q$ X! h( k+ H1 `4 m# s1 \9 W
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
# K. g0 Z2 j. Q' a+ o  </select>
( D! P% j9 A1 `</td>' ^% F0 u) z+ z3 w3 x
  </tr>
  v6 j1 J. {5 @4 Y% n0 Q7 X/ `    <tr class="bgc">
1 k+ n% p, W' v( F. o) @    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
" X1 Y  k0 W' E* h0 m  </tr>2 ?+ L; n, z1 u% N# f5 d
</table>
) V, Y1 U5 a1 S2 ]; V# G: \, r, P8 H! F</form>7 r" ]8 `1 I; W  ^, C
<script language="javascript">& F9 E! v0 p2 m
//人名移动9 y: ?* k: [% T
function move(fbox, tbox) {
. Z4 d" ]6 k5 `9 f- yvar arrfbox = new array();
: m( D) N* m1 e: Fvar arrtbox = new array();
( N3 T. N: S, g0 ]var arrlookup = new array();
5 F" N- v/ e, w/ d; Pvar i;
. ], G; b, y, r1 h  E$ @, Xfor (i = 0; i < tbox.options.length; i++) {
/ J' x, ?3 y* V2 l! harrlookup[tbox.options.text] = tbox.options.value;. A& X8 g$ J0 D: _0 t" i3 r, q6 c
arrtbox = tbox.options.text;) O$ v% I2 u( X2 u% r9 ]3 T
}+ C% r+ y$ M, W- `+ P
var flength = 0;' C. K3 y8 H" b# u* @' I* O
var tlength = arrtbox.length;
3 x8 K& x9 |$ E$ B( Z2 V0 w" Ofor(i = 0; i < fbox.options.length; i++) {& Y2 o  J% j0 O
arrlookup[fbox.options.text] = fbox.options.value;; t$ t$ v( r2 ^1 v) ^
if (fbox.options.selected && fbox.options.value != "") {; V7 G: Y# Z' Y& e% g- e0 P
arrtbox[tlength] = fbox.options.text;  H  C6 k: q/ h
tlength++;
$ H( y3 q5 e2 a6 k# {}
4 V( z; j7 G4 Jelse {
6 ^1 Z: C% Z; b4 \+ O9 h, }! garrfbox[flength] = fbox.options.text;7 D: q5 x5 D) o0 n1 O# V
flength++;' k; b, l, ]0 P4 v
   }9 H' Y8 g3 O% ]
}% J+ U5 u7 l& K( g3 R
arrfbox.sort();5 F" L4 g3 n5 H/ }; H6 k
arrtbox.sort();% p8 J: W. S& _7 m, T
: e# D% [" ~" D+ v  W
fbox.length = 0;
- @& h- [: B3 H' k, ], ?& f: O9 Ctbox.length = 0;1 o* C1 N7 Z8 I. |0 ]6 ^' s1 c
var c;
% F& S& m9 q5 c: pfor(c = 0; c < arrfbox.length; c++) {# ~( x1 u8 F5 l# p4 \9 C' Z
var no = new option();
( N. @# m( r1 ino.value = arrlookup[arrfbox[c]];
  |0 N" H6 s) j+ F% Uno.text = arrfbox[c];2 L( t. c: ]/ N$ ]8 M* M! I8 |: I5 ]
fbox[c] = no;  e  f4 ]0 h) k+ N9 p3 J- n
}( x2 m  O  ^3 m2 ?0 D& ?
for(c = 0; c < arrtbox.length; c++) {
; S# X. d- }; cvar no = new option();
- x" i; A7 \, p1 U& a: j. o& Z' hno.value = arrlookup[arrtbox[c]];3 j1 x8 D! j% _2 s- J
no.text = arrtbox[c];
) t$ Z" C5 X* G/ @& q5 Ntbox[c] = no;
- y% N& K- ]* C9 U' X   }
" c6 p' u9 D! B" ^* v# W}  _7 a1 c6 V- g. R' R
</script>
7 N5 @0 s2 n* u7 ], F</body>
7 V! G2 i' D. f- ~2 o( ]* W8 V

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