返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"$ `" I" x6 z" X3 C9 s
         c pageencoding="gb2312"
2 E7 d" o9 r5 Z- e6 d%>
6 o* {* i$ b6 Y0 E- O1 `- \! k' f<style>( m1 `/ c& l( c! P$ w9 Z, L
.f9{ font-size:9pt; }& c+ L- H7 F, }( I% }# h% L  ?5 y( y- u/ @
.bgc{ background-color:#aecaf9; color: #0033ff }
6 ]0 w' n  ^: n& c) O.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;4 x' d7 ?$ M9 t: B' T6 g
  border-bottom: solid 1px #4e7dc1;
: ?+ n' A# }# K& C  border-left: solid 1px #aecaf9;! u0 ~: g" ?7 P' X# a& a$ `5 U; ^* Z# `
  border-right: solid 1px #5679bd;
% Z: H0 m* t  m/ z! W  padding:1px;/ Y* ?# F# N& Q4 B6 r7 ~$ N, a4 v
  margin:0px;}
7 X* a2 \" m  S! {- W( E# d</style>
' q+ {7 x1 w* n' v9 q% {<script language="javascript">
) i5 m) j7 M$ _0 H5 U1 T<!--' `/ K+ r8 \. Z3 @/ A' ~
function rv(), P$ W- G- z+ b: ~* ?0 ?
{
" h2 ]5 L% e; _9 b$ D9 h' t  var val="";5 M: O, P* [- C( \6 Z# j
  for(i=0;i<combo_box.list2.length;i++){
% ]9 @$ T" ~- a7 j$ x" _- E" K( R   val+=","+combo_box.list2.value;
  U% z1 e4 X5 e# ]4 a6 d  }( Z4 @9 a3 F# ?: X8 u! @3 N7 |2 E- X0 s
  if(val.charat(0)==","){
2 \! M  u, J( N7 F0 T4 }+ y* x   val=val.substr(1,val.length);
! T8 P" X0 x7 N5 U* k- ^' j2 f  }
/ x7 u: ~4 H) l' C& c5 r3 r  opener.form1.frecname.value=val;
8 I- z! m6 P7 {0 W+ N/ U  self.close();) }8 o) ]" g1 F7 ]1 n% C6 v2 _- N
}
1 p& d2 W( K1 R1 W3 Y' @//-->6 g# o, o2 @  ^. M0 {
</script>: e5 j" M* E; Y: x4 A" l! N
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">- U. N5 C* g4 @- N. `/ `' V
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
* p( D) g; Z' d# W# N1 D3 S<%* y5 d8 g$ O8 B
  cdatasource ds=new cdatasource();  //数据联结bean实例+ D* Q/ ]2 E. t
  java.sql.connection conn=ds.getconnection();. t+ r# K! r$ [  c0 k  _2 ?! r
  java.sql.statement stmt=null;
+ Z) P( h6 y5 V  java.sql.resultset rs=null;
& A' c" `; k8 C; t  cdatacheck dc=new cdatacheck();
$ v8 {. m! v, t/ J# K%>5 {0 g# p8 ]7 }& C& B  J5 C  W
<%
5 q# }5 O# o4 B8 c3 Gstring 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";# r3 X+ c6 c7 @1 J! x- @( p+ @
stmt=conn.createstatement();
% _! V% c3 {6 t  Z# c; [rs=stmt.executequery(sqlu);
" t- W" Z' B; Q, Z; l! M8 K%>
) E6 E+ w; I5 Y, Z) e<script language='javascript'>5 z( Z% H! o( ^* e( P# Y1 ]
arr = new array();  G  R% R9 N' ?( U+ C" y% E8 T- E
<%  int temp=0;, Q; k; p4 e6 P
while(rs.next()). |0 ^# W7 s7 C+ j
{6 w: L) g4 s& Q9 `0 W& ]& Q6 v
%>$ ?, O: _' V4 i8 j& _* O
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");2 U/ E! p/ I, j" d
<%% o6 G" O: @, G% B( e' m  p$ Q
temp = temp + 1;
- L- r" o7 ~# S5 t}
- i( o# A( Z8 `/ K6 K%>
! {7 O4 H( `0 ~9 H4 Utemp=<%=temp%>;
3 d! \# [- I! A- p4 Ffunction changelocation(id){ * O3 ]8 a5 j" s
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 ; p& K; ?& H' I
var i = 0; " ]. Y. |$ _( J6 ?% @( y* f. Z
document.combo_box.city.options[0]=new option('-------',''); * E+ P1 p; A9 P' _, u
for(i=0;i<temp;i++){
, h1 p8 [  K8 O  X2 I! z" b9 Fif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 3 {$ j8 v6 E2 p) m9 l. r
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 4 u6 c. \/ F/ H
}
1 Y8 s0 W1 k9 `- h* n}
5 \; B. h& ~" `6 B. J, Z- R) E; U}
2 z* ]$ ?$ y) L4 g- A5 z/ j0 H</script># `+ H& [( L$ l0 B

4 \5 E: k7 ~9 f) o<form name="combo_box">
( r7 P: O) [! K, C; I$ z; C, H( M<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
* n' @& m7 Z3 Z( w. c8 @! t: D- b$ U  <tr height="24">' H( F, v' M6 o: F
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
* Y$ u% ^7 Z3 o8 {' J7 b- ^    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>; T7 c. W7 G4 i; g; D
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>4 Z! s- T( K# g+ u' n* M
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>! X3 N% P$ E3 s+ d
  </tr>3 Y1 `/ E, p( A5 b
  <tr>
0 M0 [7 K9 u0 k2 U    <td>; n$ l0 B# [; @
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">$ B! B% l0 A! J8 A: `' T
  <option value="0">请选择部门 ---></option>3 e' g5 C  @# K3 [9 _8 y
<%; \, f* w: J$ v
    string sqld="select * from tdept";
7 U! M6 m5 Q5 U5 x1 ]& j  Z/ Qstmt=conn.createstatement();
1 l+ S- l/ y' @' i, [2 X, C8 X' r8 Drs=stmt.executequery(sqld);
" h6 [+ i. q; F/ h2 {& X7 ?while(rs.next())
; l6 ~! e% ^0 v1 V0 S% T{
5 v: H$ j# Z; [%>% R8 @. z* `7 \$ S# M
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
+ I3 W- i5 t6 h5 E4 g+ i9 B<%
9 G! ]* _# x5 N}* `. g* ~7 |# E. C9 H7 W; b
%> # U% d4 W  G) l+ M6 T: f
  </select>4 c7 a( [& U" O7 C
</td>
$ k. p: U) }8 K! ^    <td>* Q, b: i  {, e; |; }2 `6 A2 Y2 o
  <select multiple id=city style="width:150;height:200" class="bgc">+ y; j8 p. P$ N( u/ m
  </select>
* O# D' _- Q$ Z2 j- F) Y; a  X3 j</td>
. d# g4 Q" V: z; N    <td nowrap align="center" class="bgc">
3 g4 a' z1 v4 _% s  <input type="button"  value="<<" class="buttons">
  M9 d0 ~- K5 `! b' x1 D  <input type="button"  value=">>" class="buttons">1 W- x) n+ q, w, @" w
</td>/ F+ Q: y4 M" y7 z9 ]: P5 r6 E
    <td>
5 s$ L' e1 E! u5 I  B1 |  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">( n3 z% ]# P, N4 [- }' S4 d( E
  </select>; j: g+ m( {6 D5 e
</td>
2 i4 Y: ?) o  A2 b  </tr>4 B  Z, q4 [2 |
    <tr class="bgc">
$ F' q; {4 [' T7 ~    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
- S' v9 X9 L- Y" O% ?; q  </tr>) W$ G7 z4 G9 J+ G5 W
</table>
$ B( s9 K8 P$ O</form>
, d' o' ?! }; Z% m! ?+ t<script language="javascript">" v4 I+ g! |2 a$ O+ L
//人名移动& S: `0 L  V/ V- M/ _  k
function move(fbox, tbox) {0 I& |' q( }% e- r; k, ]
var arrfbox = new array();6 U* F1 z2 `: Z9 _0 E* r' T
var arrtbox = new array();5 m* {- {7 O" Y! \  X4 L/ \
var arrlookup = new array();; a- N# B& w' a9 z4 j' x
var i;5 M, H3 C7 z* x
for (i = 0; i < tbox.options.length; i++) {
% Q+ n# Z9 }& W  y3 n" warrlookup[tbox.options.text] = tbox.options.value;5 z0 X) F9 @9 u" O
arrtbox = tbox.options.text;
% V# A5 F: f/ g: E}
$ D5 o. {) Y. c4 Qvar flength = 0;
/ _, F! V$ l0 V* l4 X, F6 @$ kvar tlength = arrtbox.length;
2 g1 `% z# i4 ^4 s) h7 u( E# lfor(i = 0; i < fbox.options.length; i++) {3 V1 S8 K  O0 A4 s& F
arrlookup[fbox.options.text] = fbox.options.value;% p% C' x. b  ^! n% B
if (fbox.options.selected && fbox.options.value != "") {
, [' w6 G  c# c) h* `arrtbox[tlength] = fbox.options.text;
( F8 m( y9 P) ?: G, @2 xtlength++;
5 n. F% y1 h5 ?0 E* ?! b* ?/ _}
# h1 @% y( u9 s5 j/ O5 }  W) kelse {
$ h4 i  `, `! {' T: carrfbox[flength] = fbox.options.text;
8 n* L, x, `: P8 d0 `flength++;$ e4 _2 h& H+ X2 e4 f
   }, m& Y/ {- R5 i) f3 q  w4 w; A
}8 o) m6 c# q2 B. q, Y: |$ S/ q
arrfbox.sort();
/ u+ C, S$ E' ~  w& ^0 ^arrtbox.sort();
" }% R2 `) T. [8 `* t6 W8 v& D3 I% e5 h  J: q
fbox.length = 0;- c5 |. K" J$ a* {: F
tbox.length = 0;% f+ S4 Z) V3 o/ b, u5 H
var c;
: j9 ^5 p8 q" S$ Kfor(c = 0; c < arrfbox.length; c++) {1 Z# `" J  G6 Q
var no = new option();8 ?1 }1 R- F1 [# w
no.value = arrlookup[arrfbox[c]];) W9 T4 e" I' v
no.text = arrfbox[c];
0 U% d7 ~: |4 @1 C7 U0 o4 ]fbox[c] = no;
; @+ h9 }- L$ S% M& u5 B3 b1 ^; J7 {}
$ K4 C" D$ C* J5 y! L. Q; efor(c = 0; c < arrtbox.length; c++) {
  _2 l+ U* [. |, [; n9 g+ ?3 a$ {0 ^! zvar no = new option();
! j% n# x" P& C) Q5 ono.value = arrlookup[arrtbox[c]];
5 o5 b7 n/ c, _  L! v/ D) Sno.text = arrtbox[c];) J  W) N( S5 ?4 _  v
tbox[c] = no;  E* t3 f  N* u2 I
   }
, ?+ X4 n, X* K9 H" O$ [$ |}
9 m% ~$ O8 b% a</script>! N* r; C' Q: a. Q2 F
</body>8 n$ e) X- b. H- C, P: W

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