返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"1 H) T5 {8 R6 j" J) g! y
         c pageencoding="gb2312"
# T, P" O& v- V+ U# ^%>
9 u6 Q/ _3 s5 T<style>" m2 }0 p$ N4 H* {) l
.f9{ font-size:9pt; }4 T- }% p" R* \1 O& {1 Q
.bgc{ background-color:#aecaf9; color: #0033ff }+ A: P. \% t& r" J) ]* S3 n+ s5 N' [' H
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;# \0 A% G' M, O9 J8 `, X; [8 v
  border-bottom: solid 1px #4e7dc1;1 Y% G# `6 \9 H" v& s+ s) u
  border-left: solid 1px #aecaf9;
- y$ @/ w. S  u4 _2 t  border-right: solid 1px #5679bd;
' o0 ], ]7 v& m8 }: a  padding:1px;
9 Y2 l0 r! M& t  margin:0px;}
1 u& _. V- q: N3 I# \</style>
6 `; e% h) v& p3 }4 R. c( C<script language="javascript">( q, H; L1 s) Z
<!--
# J. b$ C" _, F" m: }! `' s; afunction rv()9 x' u& s2 R; U: v% g3 `
{( [+ f; T, S) c
  var val="";
" G$ c7 {# L8 A& a' W2 Q  for(i=0;i<combo_box.list2.length;i++){
, f4 l0 t. {- O   val+=","+combo_box.list2.value;
8 N1 v+ V& \. s+ s1 }, Q6 W  }$ P% x) X' r& b
  if(val.charat(0)==","){5 M# l6 f2 X3 c* C1 W6 x
   val=val.substr(1,val.length);3 u+ E& ]8 X! \4 b# u6 n. U) c
  }8 s5 _* I/ U9 T$ J% ~+ A
  opener.form1.frecname.value=val;  Y6 A8 U/ J1 v
  self.close();
7 H- j2 N) M# S/ |1 W}
2 C# \* G' W) y9 t6 `. d//-->
& r2 D' c: W$ M' a( }</script>
" K$ d' A2 F' {; z+ u2 t5 f2 u<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
! `8 G" j" q3 i- L<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
9 q: V. E& _, v, m8 e. V' }<%- \! S9 H  T! \3 v, r9 e% Q
  cdatasource ds=new cdatasource();  //数据联结bean实例
8 X+ U2 @2 ~2 t: A  java.sql.connection conn=ds.getconnection();
) ?- `3 s+ C4 P" u  java.sql.statement stmt=null;. M- Y, f+ E& h' ~
  java.sql.resultset rs=null;3 E; k+ ]8 v, o1 H3 ~
  cdatacheck dc=new cdatacheck();" u" H- u1 E) a' l( G9 `& v
%>
( r; k% Q9 L6 `- ?. @<%8 s5 U% L" |1 s% {; i' g0 z" l9 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";
6 m, v' Y: @2 z5 F3 E7 lstmt=conn.createstatement();
, O. ^$ r) ?6 d5 U/ u$ A; |rs=stmt.executequery(sqlu);2 h6 R: |7 `4 {  ~0 m
%>
, s- G4 W, E$ K1 ?<script language='javascript'>
" y7 g, C0 Q! c/ B3 D& r; [3 k+ Darr = new array();
+ V% o' t! x8 f3 w; ?<%  int temp=0;
4 h7 G+ F0 r' m, r( Y7 T9 Mwhile(rs.next())5 o. s& A: p  Y4 C( d+ ]( u
{
$ \. G3 I3 ~& O- w! ~& x%>
' {% k- X7 H% c! |% j% b, g( ?arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
' R0 c; q7 y# C. T" r; J& h<%
, r  k( G- L2 @/ P( g. v3 B+ ztemp = temp + 1;( t3 p9 F( ^. |8 Z. @$ ~) s/ t
}
1 u  v3 I& _3 T. f4 p%>/ l1 ^. K9 ]# M- s
temp=<%=temp%>;6 ]1 h$ ]$ W( l! K5 W/ v# l
function changelocation(id){
' c' [+ Q. \1 H, a: C0 d9 |document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
/ R  m& d: d( }var i = 0;
( J6 ^4 F; A% u7 x7 ?) Hdocument.combo_box.city.options[0]=new option('-------',''); 0 F- l6 Z( I1 h( V; `
for(i=0;i<temp;i++){
6 X& F" `& R+ n, y8 U, r9 jif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] & A) o% D2 Z  G, A! ~
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); - B4 g; o& z+ i* Y& h1 A
} ! |" e3 c- a) p" P4 E
}
$ ]2 ?4 Z2 a- @' ^3 D1 K4 ~( p! w. P2 k} & N$ V) l4 b6 Z
</script>, x% u. E7 O: I% g$ s9 O$ p/ G! _# Y4 N

0 p1 X- g2 L6 t% c4 A4 P! C  w<form name="combo_box">
& J2 G8 T% a; x  v, J0 U; u<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">, R1 b: ]9 W! d- T% ]6 E$ u
  <tr height="24">
5 @5 C! n6 }7 B: Z  t: F! A    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
. z1 C4 f) f1 W5 [0 y. G( Q7 C    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
' ?8 O! K0 T. Z1 H- c8 [    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>0 K) G9 c: t% u  k) e! c. Q" \, n
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>: [; b5 @1 V" t# ~" T: h
  </tr>! o* F0 H* p6 }% J8 A
  <tr>
) N1 U2 W2 H& |9 J$ }, z1 T    <td>
& \7 Y! d) B9 D! t! {  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
+ Y* J1 J% q% B0 B  <option value="0">请选择部门 ---></option>+ f8 _- g& k& n5 b  r$ f" s1 J9 W
<%
6 u  F$ `: I- p6 I    string sqld="select * from tdept";
* Z2 x7 ]$ ?/ K# W; x8 x' L# Jstmt=conn.createstatement();
1 \- }7 \: [% v0 [rs=stmt.executequery(sqld);6 O% u6 h" ?7 s0 d  s2 B5 D, G* V
while(rs.next())
5 p( K; J6 d/ M( @: M{
, f4 Y4 R& Y4 V8 U4 y4 ?%>$ i) a. m# E. J. k) P  |0 C: O" i
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
9 U* f  q. d4 h% o' ^& Z<%
, {5 g* p& H0 ?' k}, t, H' v- t# `
%>
; a( s0 o" y, d0 O' _& M9 l  </select>9 ]  Q$ d( ^, b6 I( ^
</td>8 F6 v  M$ X: y0 P4 ?9 v5 q: s: Y
    <td>
1 n" t/ k8 U# b  <select multiple id=city style="width:150;height:200" class="bgc">
8 [; y5 K% G2 b& F) _& \  </select>* O" S. s. w( t
</td>7 N1 o. u$ X) M* `
    <td nowrap align="center" class="bgc">
. c) N( x+ b( y  <input type="button"  value="<<" class="buttons">5 U' B5 S( x2 a+ K, m
  <input type="button"  value=">>" class="buttons">; O; P- \) ~' r5 D& P; v- e
</td>
8 d5 m6 ~- b* [% ?    <td>0 F4 x+ {) z! q$ W4 [" O
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
1 T! E( M4 Q, d8 b' e0 r3 }  </select>
- i9 ?# x0 C4 c) ~. L, W5 s</td>
% [6 t& G. @7 m! d4 S  </tr>' ]# d5 {% w& Z5 B& C
    <tr class="bgc">
8 O/ y- _- L& d( r    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
+ y. b6 c  {, A1 X  </tr>
- _/ W2 o. \0 d% x8 l$ @3 G</table>
" h, d% O+ a3 u; N+ J' A4 N; D  F</form>
( O& |" r& t% m& P9 L" M<script language="javascript">( a" h4 H: c- [7 s/ j, V
//人名移动2 m0 d5 {- E, g0 L$ M) Y9 o
function move(fbox, tbox) {6 A* s  e2 s' S6 |
var arrfbox = new array();
- v( Z9 K, n9 y$ V' hvar arrtbox = new array();! b3 F, N8 v; Q! Y3 j/ Z* h8 M
var arrlookup = new array();1 J& H0 h: F9 g3 p: [6 Z) Y0 f
var i;2 @8 C% b3 I+ B4 [. O
for (i = 0; i < tbox.options.length; i++) {
! M+ r- l, D' N' y" y4 G$ sarrlookup[tbox.options.text] = tbox.options.value;
  t6 c' v' a1 iarrtbox = tbox.options.text;
' b/ @* }* U+ h6 Q! a0 C}  Q+ t" F& ], A) c5 ~: [
var flength = 0;) x8 _; V+ Z1 U/ @+ f
var tlength = arrtbox.length;- F& h& l7 ~- Y4 N8 B
for(i = 0; i < fbox.options.length; i++) {
. v  L' ~/ H: J$ n; j3 E) barrlookup[fbox.options.text] = fbox.options.value;3 Y" F/ r* I+ ^7 I+ H$ _2 [  {
if (fbox.options.selected && fbox.options.value != "") {# @3 D3 E& q6 |/ M" E
arrtbox[tlength] = fbox.options.text;3 k" s* e5 C5 s, M: w" i2 y
tlength++;, `1 s" t! `7 F
}
3 S9 r/ ]/ g0 M) z! o1 F; ]) M+ xelse {
* v' i5 L; _* M! x; ^arrfbox[flength] = fbox.options.text;# k' v* G! {* ]" Z
flength++;
' |! `, S' z7 [( w  B  k; q+ G) z   }1 z/ Y' W; ?9 ?6 ?8 h( `# B. W
}6 x4 a7 f+ x1 \* F. E2 m4 z
arrfbox.sort();
8 H3 v1 Q1 Y8 D! W; i- k2 d3 l4 ]arrtbox.sort();
& |8 t3 E7 h1 ]* `7 I! v; F  b: E2 ]" d# U
fbox.length = 0;4 H# u; u& g2 Y
tbox.length = 0;
% \! z! Z& R  V8 T. A7 E/ Y, s7 o1 L, Yvar c;) t) e1 j! }' z5 `: R
for(c = 0; c < arrfbox.length; c++) {
# @) T7 R+ F$ y/ w( ?5 H& |! uvar no = new option();
' q7 s; ~9 c6 P  g7 r  P6 Lno.value = arrlookup[arrfbox[c]];+ e. R7 F3 l. }$ I
no.text = arrfbox[c];* M  F/ r( ]% r* b) }
fbox[c] = no;
2 I' z( v4 a0 V4 W: P}! r- K& D% O2 n* D
for(c = 0; c < arrtbox.length; c++) {) B3 r* D" I8 ~8 _. `' u
var no = new option();; R% D" s% F7 o. h# d
no.value = arrlookup[arrtbox[c]];
9 n( {8 T' F& W* wno.text = arrtbox[c];; M" V& C$ N) w: w% x5 f  p) J2 l
tbox[c] = no;7 o2 {  |- N9 S! O
   }
4 X/ Q( ^* Q6 ]% Y" b}
7 ~' \4 N2 k0 [* d4 p/ H3 W) S</script>
/ W0 r; _. c/ x4 k$ R- }" D</body>
3 K( S; V/ @; \5 ~: W. w2 ?! F

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