返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"9 U! P' R. Y% ^" ?( Z- o
         c pageencoding="gb2312"
% `! e0 K4 h& V  m/ W' {# T%>7 c4 Z% J5 _4 V. a( F
<style>, H# d4 C& @" U1 F! ^$ S& Z
.f9{ font-size:9pt; }( j7 V& ]: {0 ~) j, D
.bgc{ background-color:#aecaf9; color: #0033ff }
, H# K4 G- w# C8 A6 f* y.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
, I# c" @8 s7 L9 ?  border-bottom: solid 1px #4e7dc1;+ p# W) Y% Q8 x$ F  L
  border-left: solid 1px #aecaf9;' T1 I& J$ L9 Q) A: \
  border-right: solid 1px #5679bd;2 Z5 n* U8 `0 K; O' P- q% c7 ~
  padding:1px;
; D$ n0 l5 `3 ^! Z  margin:0px;}
0 |' i' t- X) S/ R& G) `3 g0 H</style>, @( I: F) M1 }) d6 \. Y
<script language="javascript">
+ }% @9 n  t; j9 q2 M<!--
3 Z  D* s. b/ H4 Ffunction rv()! f" @& L: N, j& N. x' W2 I7 m
{# Z' C+ k$ X% b1 T
  var val="";
# r: z; O( f  A0 y2 z7 W! L7 U  for(i=0;i<combo_box.list2.length;i++){
; m( v4 D$ R9 |- K" i7 ]  D   val+=","+combo_box.list2.value;% p% V; Q2 M) g& _4 D+ b
  }2 y4 R( y; y) Y' p
  if(val.charat(0)==","){
8 L1 ^% J. N5 ]8 ]1 e  I8 I   val=val.substr(1,val.length);
5 K; O2 ~* Q9 K/ K  }# V" r! c8 }' Z% k+ I
  opener.form1.frecname.value=val;  Z& `1 |' v! t2 ^0 X' \# P
  self.close();' r  z0 b5 r0 z4 X
}# P9 K! i! Q, M8 j8 y4 H1 J# |
//-->
( _* c4 \3 h. X/ j0 ]</script>
/ [: Z8 T# {- p9 L<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">& `, X7 A' K; j$ \. _
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
$ [$ A+ ]- w! ~8 z/ a<%
$ _: S1 N3 b- Q& [5 u1 |6 k9 M0 l  cdatasource ds=new cdatasource();  //数据联结bean实例0 C' i( E9 j! B7 t- O9 z
  java.sql.connection conn=ds.getconnection();3 _3 N+ r5 s- G
  java.sql.statement stmt=null;- e# b; _3 ~3 q0 }
  java.sql.resultset rs=null;6 W/ \% N3 ?; V; P8 Q0 r
  cdatacheck dc=new cdatacheck();- r4 n. l; t  D3 j2 T- Y1 s+ {+ U
%>- ^) w6 `/ G  [8 m. y
<%
) v0 B* Y1 f; Y1 P8 U% n( N/ [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 C8 I! m# `- [) M. o- Qstmt=conn.createstatement();
# o# C8 H1 k4 @* I+ T) Lrs=stmt.executequery(sqlu);
. v( U7 X1 B6 d6 j: o%>5 g: |6 K/ w" K  K' s
<script language='javascript'>2 Y# L1 w- s: A% y& n3 S
arr = new array();
, ]' i" M4 j5 R# k5 E<%  int temp=0;
& D8 a6 f  l7 \3 \$ G: z: s! owhile(rs.next())
* E: x4 K+ P  K* C5 S{
) ^4 o' f3 O* N* e! [% E%>8 e* A2 s* m& X, E- v( R( ~
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");, z- c+ Z6 ^" J7 V2 G
<%! L3 t: B, j' S9 o# J! D9 j8 w
temp = temp + 1;
7 j: c: H! U5 |, i; Y3 ?* x}5 Y: Z2 u4 J6 e! M& ]* O* c
%>. e9 X) @* }& {% ?" M
temp=<%=temp%>;
4 I1 v/ x1 {# p' Bfunction changelocation(id){
/ X, K) j3 `8 `  {  W' mdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 5 [) v, S, O3 c
var i = 0; $ l: I8 Z  _+ E8 ~  u  \' b8 f: t: k
document.combo_box.city.options[0]=new option('-------',''); : T( u1 X- E* o( Q% G; i
for(i=0;i<temp;i++){ ( A  }. d! H" b  |: u- L
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
1 [4 W6 m% K4 R& E3 P8 bdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 9 w" N* D5 s' |2 [$ o  ^1 A3 X1 h
}
. @' [: d) I6 f* ]2 E% m9 A( i} * V8 y6 W) [7 p  F/ e
} : K/ r& G* B( t/ K
</script>6 L3 [7 y7 x9 u1 h: ^% j
: M; w& b, h3 V- k
<form name="combo_box"># a4 z/ w; U% N( }6 h
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">* r6 T. Z8 O: X& k7 p. G
  <tr height="24">
& G- g( L( W( v4 G    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
1 D4 ^7 h7 l5 K( o' H    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
* {( u! n5 J- r4 n) r9 z3 s    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
4 m+ m7 e( b3 g* I    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
+ U; @2 D6 o2 }; P! F) G5 b) ]3 |  </tr>
. y: j$ b( P8 B0 f" @3 r- J  <tr>
/ E& v% a  r$ i/ ~/ M    <td>3 d$ l' p5 z, @  V. E9 b$ C
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">" \: T7 m+ d) W* j" v, V8 ]
  <option value="0">请选择部门 ---></option>
8 Y7 l9 C2 M$ f# K6 R% y<%9 H$ V5 ^2 I! Y5 s
    string sqld="select * from tdept";: r4 Z  {2 P) C
stmt=conn.createstatement();
- w/ n+ @. a/ Q7 ?; u% vrs=stmt.executequery(sqld);
4 R! t: p. V0 f8 T/ x* T0 vwhile(rs.next())
3 d7 z5 [  i; d7 a5 w{  O8 P# T# a5 t3 G& Z5 `# C
%>; u6 ]8 M* Q* a/ J6 T  ~# f
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
8 h0 u, a, u  r<%
7 |0 }; w- t. q/ S! R, t' m1 o}
: ^( Q1 W+ c$ z* p# [%>
: ~: t# ]- k! A  </select>/ t1 _9 V6 S' q1 ]0 S
</td>
7 K+ V1 y1 w0 A  R3 [1 ]    <td>& w3 Q' }3 d0 N) Q, h& }. S
  <select multiple id=city style="width:150;height:200" class="bgc">
! j( p  K  ]2 _6 Q) N/ f  </select>
8 ~5 p% a( K  y7 ~( ^</td>/ |1 s' k( d3 u, @# R7 W
    <td nowrap align="center" class="bgc">% v* s4 h' i9 C0 Z
  <input type="button"  value="<<" class="buttons"># i" b; L+ s% ]
  <input type="button"  value=">>" class="buttons">$ Q6 z8 c3 |$ p: T6 z
</td>
' @6 g4 c" [( K, g9 n6 ~* L    <td>
9 j7 r& [9 b% O. V1 U" h  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">9 P; ~6 V( i" H* E, _( K! ^# q
  </select>
% s: b4 V7 h) q; z</td>
) I6 \1 K. C# m) d  </tr>/ T  e/ E9 }: r* {; U7 ^' ~" E
    <tr class="bgc">
& }, |% a6 O, \2 @( w    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
- ?1 v  k" W0 V, @/ ?+ o  </tr>
7 O) T+ H6 k* J</table>
" Y3 N. d+ t1 W5 ?+ \; f& t</form>
% R& a: ]+ b+ p# @<script language="javascript">$ I3 `- Q$ s* x! s# Y
//人名移动
1 {1 V# Y: Z# `, E  rfunction move(fbox, tbox) {
* i( ]6 |; G7 Wvar arrfbox = new array();
9 W' T& F& h; y4 Q& pvar arrtbox = new array();' z4 }: e. X6 W" e# s
var arrlookup = new array();
! z/ v( D4 n1 O/ lvar i;9 a2 J' s5 g7 J' j: [
for (i = 0; i < tbox.options.length; i++) {
. s& _' L/ F, T  [  {8 Y- G* Garrlookup[tbox.options.text] = tbox.options.value;& T  ~  `$ p! t- l6 m' Z6 x
arrtbox = tbox.options.text;
& s- ]+ m# L5 l, s# z5 X}
  m. [9 P( k; N% ?9 l/ L, svar flength = 0;$ T. e" m9 v& d- j8 X
var tlength = arrtbox.length;
+ d- R5 G( X2 n* m; F3 F4 @for(i = 0; i < fbox.options.length; i++) {4 O1 F! ?2 D2 }* c
arrlookup[fbox.options.text] = fbox.options.value;' w1 k8 B, Y- k0 d) z) k
if (fbox.options.selected && fbox.options.value != "") {3 p4 E5 f/ [0 q- d% Z) u* E7 j
arrtbox[tlength] = fbox.options.text;8 O1 x# Q- M' t. u& U# _
tlength++;
, d5 o+ J5 e8 P! v: @; {}
4 ?& }  F- \4 g! V# yelse {
2 @" a6 q6 d8 S0 jarrfbox[flength] = fbox.options.text;
! a: v0 f5 k, Wflength++;
# r4 ]9 F% W4 ]7 ]; x& e   }
2 s5 r! q& J  i3 n2 U# K}+ U  D; S% K) V" \) g' r  Z% h( _
arrfbox.sort();
& B2 ^7 l9 O9 {- a4 garrtbox.sort();
4 V' ?# v. C7 f/ t* Y# r
/ R, D  h$ ^! P3 J) sfbox.length = 0;+ ?# Y8 {* v' t2 m0 `0 w
tbox.length = 0;% `8 D4 a% A1 V
var c;: g+ A( b, D4 b  f2 D. `7 D4 c
for(c = 0; c < arrfbox.length; c++) {
6 e4 E+ a! J8 L+ bvar no = new option();
# u- h/ p$ V7 e7 \4 Yno.value = arrlookup[arrfbox[c]];: U0 `* ^: W& x; S2 `
no.text = arrfbox[c];0 N1 ~; g+ H: W  p5 t; i& x. o
fbox[c] = no;
& `3 L( X1 f' y: z$ j}' }6 @; j- u! N; q
for(c = 0; c < arrtbox.length; c++) {6 @6 S/ o5 ~1 V3 r7 C
var no = new option();9 U1 L% F6 D  g6 [$ C" h
no.value = arrlookup[arrtbox[c]];, |1 c! k# p+ t
no.text = arrtbox[c];; S8 b0 @% W, o* F7 Z% S
tbox[c] = no;
& g+ f/ J5 @+ G   }1 n3 c  |. V6 C7 T. _' w6 ]
}- i- M* {2 L% H- M* S9 ^. S- l! A1 R
</script>
+ n: O' @( F5 i+ j% E</body>9 R9 a' L; I8 ]( m6 A

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