返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
' |. Z3 l4 r) }5 M# O         c pageencoding="gb2312"
! ?" V- Z) ~! K2 o' d0 x% e%>
$ u+ @  i& w7 G0 t<style>
2 a1 W# R! h* m  i' J7 s.f9{ font-size:9pt; }1 H( H) I% m+ W" O1 |( A& G! {0 d
.bgc{ background-color:#aecaf9; color: #0033ff }
% u) Y3 F. a. ^7 v.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;" v9 M0 r: `& D( p+ b8 a2 w
  border-bottom: solid 1px #4e7dc1;4 u# i* c1 d8 u, D& v; w, d, m# g
  border-left: solid 1px #aecaf9;
8 V& B" [* x/ G. G! ]5 N% d  border-right: solid 1px #5679bd;  R6 C& ~* y/ ~4 j5 K) L
  padding:1px;+ B+ L0 e% J6 Y; _/ G1 q! ~
  margin:0px;}' s! r1 X- m2 B& V$ Y4 W
</style>
& K# [0 _/ _1 G0 p" _: Q6 a2 r- s. ~<script language="javascript">6 ^6 }8 ?  Y% G; L' \: @5 x+ b" I
<!--
/ M3 Z% K7 y1 f! v+ v: ?4 X$ Ofunction rv()1 \) }" z7 s3 Y8 T
{# s% b- c( Z2 S- w
  var val="";8 K) ?( d0 K3 c8 o! `
  for(i=0;i<combo_box.list2.length;i++){; `; k1 I/ _) `( d7 ?9 B
   val+=","+combo_box.list2.value;
( @+ D1 r" T) P; o6 ~1 {# K  }0 i1 F9 ~7 U# A
  if(val.charat(0)==","){
5 G4 y) X8 @/ D- q- @   val=val.substr(1,val.length);
, i3 f) C, j7 }/ ~% ^  }
- }  b) O/ o* v  opener.form1.frecname.value=val;
0 v2 Q' g  W" c  self.close();8 v3 }* y( @, j  O& c2 {8 J7 U# k
}
) S" j2 |  \+ I- ]5 [) u//-->& U. y% o- M% t7 Y2 ]
</script>: ~* H* f7 O3 y1 a: \
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">9 R4 ^% N& j) H
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
  J1 N1 c4 V0 h% ]<%  k' e* j+ e3 B, Y
  cdatasource ds=new cdatasource();  //数据联结bean实例
; Y' m3 |" h  a4 l1 E( f  java.sql.connection conn=ds.getconnection();
" p; z- V3 Z4 L) U3 s0 B  java.sql.statement stmt=null;
" F" p, ]# W3 c% K) j: k% n  java.sql.resultset rs=null;8 C- i  u: S2 ^
  cdatacheck dc=new cdatacheck();- j4 B* g* e$ E
%>
. V. O( e' a' E2 ~<%# h6 [& m. ~. g5 N/ j
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";
" g2 `! p1 \+ {6 C* B2 g" tstmt=conn.createstatement();/ ~' e% {' X& S. u
rs=stmt.executequery(sqlu);
; M; L& L" a6 [4 E%>
. K' [" o( a: a& R+ p, A<script language='javascript'>
4 |# c# Y+ `: k' p5 p. rarr = new array();
4 r* }. C. l" m. \/ G<%  int temp=0;
- [% H8 `* c3 Mwhile(rs.next())2 p$ X9 K  M+ w3 M+ g3 I3 u
{
; ?7 P. O0 ~' T%>( I* F) e4 m0 r7 S
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
6 ]" }) l$ q/ H+ L3 j/ q<%
0 V/ B5 T9 @  F/ X/ _* a! ?temp = temp + 1;
4 ^: R. C/ s9 h5 M6 J, Q; I}' Z# C) ^+ a/ D7 R# ~" i, A
%>6 M, e0 [/ N" Y2 ~! V4 A. }
temp=<%=temp%>;0 M; k8 b. O# q: A6 m
function changelocation(id){ 3 n% \' O7 M( w
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 : N: X+ Y1 P2 D0 Q* ?8 J  A
var i = 0;
/ C0 v. k+ i' G9 o8 odocument.combo_box.city.options[0]=new option('-------','');
0 N9 {: d) J5 f" @/ Ufor(i=0;i<temp;i++){
9 \. Q- _( M) k/ P0 U& B: mif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
7 r/ w/ n9 @9 \! e; mdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
. p* L3 T$ A+ x& t$ A7 D: V} , Q& w* a/ x' A7 p& c& w* W* w! X
} - s" G2 M& }/ J6 Z
} $ s3 x0 d% A7 i% c' h% |( I
</script>+ D, \2 A, a' m- r5 G' s7 u; {  `# Z
/ q; N3 @. w$ w" j! B. n
<form name="combo_box">
- ~: |7 C& i) r' l  y4 M' Q& Z<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
4 M, g, K! F0 q4 F7 |4 @0 O! i  <tr height="24">! {; f- [3 n- V$ N- ~2 y
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>/ D, U* [; p+ I  h! X) r
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>! o! i  N* [0 B/ ~5 u& e# ]5 U$ k! P
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
' d& _, a8 S. j; T; R, C    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>/ j) d; D. y3 A/ l% C+ S
  </tr>5 s4 C  ]" w1 M8 B
  <tr> - ~8 S+ O6 L; g
    <td>
* g$ V' r* o9 b; O! K  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
) u6 x/ \/ P" `; B  <option value="0">请选择部门 ---></option>
& `3 x$ o- T4 W& I& x" C6 x+ ]<%5 D; ~% h  b9 k0 q! ]
    string sqld="select * from tdept";
4 U. @3 @9 {7 ]stmt=conn.createstatement();1 X2 v. W& f, N4 V
rs=stmt.executequery(sqld);
/ X/ V; Q4 H- h$ S7 d5 Lwhile(rs.next())
  U' f* ?: R  \# o{
% H, z# x3 O4 K. i8 |$ L6 |%>
* R1 ?5 u3 e  N* u6 W  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
" x) e2 P- p5 g  ^<%
& O9 _5 S8 I+ a}
0 E' C  d, k% T2 n0 ^% k1 M( D%> 4 F7 q* h7 C5 \) I
  </select>) w7 x* C+ O! v1 U0 I
</td>) r. b7 B% [0 o6 ^
    <td>
& K; O; k, r4 f) Z  <select multiple id=city style="width:150;height:200" class="bgc">
8 Q5 c9 y4 f0 w  </select>
% S& Z$ j) m  \5 I% f8 j</td>
' t# W% v  T& D, k' N' @    <td nowrap align="center" class="bgc">/ i7 K+ E+ c- O* [: m, {
  <input type="button"  value="<<" class="buttons">; w/ l1 t& @% m$ ~
  <input type="button"  value=">>" class="buttons">
' x& v& q2 K6 o" [0 L: m9 A" m- S</td>
! n) \4 p! l0 n# {* T    <td>
* b) f$ O% s* q! g- Q0 C0 Q) P  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">8 p5 B! F% _8 `) T& o- f" D
  </select>0 u0 N) R  ~' C' {8 s3 ^
</td>
/ z7 D. ~  K% J  {7 i  </tr>
# F* U) {; r; @* s( V8 e5 S    <tr class="bgc"> & r8 _9 p7 @' s
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
) x, K( p& t5 K4 X# o  </tr>) h8 [! o# u% @: T
</table># I/ u+ Z$ O5 [" X, u
</form>
9 U. z9 t2 s. }0 g  K<script language="javascript">
' L  Q2 H- b: ~2 d- W+ m1 N( D7 o//人名移动
+ m9 ~8 M* u3 ^9 {8 lfunction move(fbox, tbox) {
! Y& M3 m3 F1 R; K" Pvar arrfbox = new array();
, |8 O$ ~0 k+ ?' u: Y+ r7 jvar arrtbox = new array();% J* C; k! P9 f4 |
var arrlookup = new array();
' [! l& s" @3 a+ Evar i;2 S% Q4 _& g. L# G0 y: w" w; m
for (i = 0; i < tbox.options.length; i++) {
5 [4 z. K+ r% c" E' y  F, marrlookup[tbox.options.text] = tbox.options.value;
+ i: T& _; x5 c( a6 \2 P4 b" Harrtbox = tbox.options.text;* I6 E) p' W7 F" u; }5 o
}% q- e* V# s0 [: D( J3 c
var flength = 0;; _- H8 d5 }2 |( `8 m, b
var tlength = arrtbox.length;/ ]) J! O/ B" y4 W, l
for(i = 0; i < fbox.options.length; i++) {
$ |% Q3 q) S" ?; ^$ h2 larrlookup[fbox.options.text] = fbox.options.value;! V1 b6 Y) {% M0 H
if (fbox.options.selected && fbox.options.value != "") {& Z* G% ]2 l2 z
arrtbox[tlength] = fbox.options.text;
; B" U  n, z; p4 ntlength++;
/ d! o6 N: @, k}( v% U# f6 s. ~8 ]* o2 N9 L7 j
else {6 g5 H/ t( X6 D6 ]4 J
arrfbox[flength] = fbox.options.text;# H) {; `1 O+ }: i
flength++;
# k/ Q$ j5 W; x" L   }' z4 v; W2 n9 d6 t. [
}
5 J- k! W$ h+ R! e7 j8 Farrfbox.sort();2 v& _/ \' z9 W6 K1 \. @
arrtbox.sort();! B# [" m8 ~& L& w/ i6 f) ?) w

' ~+ m- ~: l' ]# i6 V* W  |: z6 mfbox.length = 0;
1 a# j5 Z5 ^% btbox.length = 0;! M6 A) t1 n: ~5 t5 s
var c;) ]" z2 o3 z' P8 I
for(c = 0; c < arrfbox.length; c++) {& U: u0 S- G* |6 |9 h. A7 [: m7 s
var no = new option();
( z) P; @6 K  [! |7 v- Vno.value = arrlookup[arrfbox[c]];3 Q/ l" w" K8 E& k+ H
no.text = arrfbox[c];
8 m# x5 b5 U1 W/ _  X3 G% A. r7 @fbox[c] = no;* [8 d+ T% }' c. m! u, f; B0 b
}2 Y" X& t; w$ \3 X! r
for(c = 0; c < arrtbox.length; c++) {, u' z0 q" {* R9 S7 X: d
var no = new option();- c" w) f! M7 ^1 k' }7 X! W, q
no.value = arrlookup[arrtbox[c]];
8 q& @# k* u. b6 y' Y5 ino.text = arrtbox[c];8 j4 g- S) r2 v  @. e
tbox[c] = no;
1 f8 v8 P! O: Z* k   }0 @( O6 o7 l2 l3 M! [2 j
}
& m2 w' h! S7 c4 @</script>) d# N. {) c) C. C! p
</body>9 y" g% o3 k! F' M$ l& A* [& d2 O

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