返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
, B" W3 s3 ^: `( t. v3 m: Z         c pageencoding="gb2312"
, v+ ]/ h. s8 `7 i' q7 k+ k%>
/ [& V  v& f* [<style>9 B& Z' u- c5 s$ g4 M
.f9{ font-size:9pt; }* D( V! L# W# _6 L
.bgc{ background-color:#aecaf9; color: #0033ff }
7 k# {! \! [: [# `$ F: T# o.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;' s: B) g! p. _& }( w( z
  border-bottom: solid 1px #4e7dc1;# H, M2 X- E9 ]7 U) @0 X$ M3 B
  border-left: solid 1px #aecaf9;& n2 V2 R2 }9 q# E& y1 j; ^
  border-right: solid 1px #5679bd;
. k/ h# M- n, `# j/ L- h6 E  padding:1px;; W; j  q  {+ |/ ]+ B3 i+ u. |" i
  margin:0px;}% d7 O# N3 t7 _3 Q/ \
</style>2 w  I0 u) f4 P7 B1 V% H# ~
<script language="javascript">( Q/ @( ~" ?! @3 }* V: O
<!--$ W7 P* K7 N$ G6 f* H$ S1 k
function rv()
3 {1 E+ A& F( t2 r! q5 B& N- A{
9 Z& J9 r/ \$ f! ^" O  var val="";
% C4 m& V2 n/ e/ \0 A  for(i=0;i<combo_box.list2.length;i++){
# `- P+ U& W% w4 Z( B   val+=","+combo_box.list2.value;0 w$ K  d$ a& [- \
  }" p' Q1 n' V* Q' t' M9 Q3 t
  if(val.charat(0)==","){
- G5 r' ]; q- H+ c0 l2 r   val=val.substr(1,val.length);
4 @1 I. W0 B7 _) |- x* _7 Y( O  }
8 Z3 T$ |4 l" e7 z& d" T  opener.form1.frecname.value=val;' M3 ^7 F' q0 M. H" M
  self.close();
( \5 s7 u9 {* u0 C* a}
5 V& t9 s7 k" N//-->
- X" ]$ K' b3 B7 \5 P, s% U</script>
7 t$ X  W3 ~' A) d<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
- X$ K1 }' [/ L* g<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
6 ~) V% u8 q& a! J8 I# i0 u  I<%
+ \7 J+ _9 \7 ]/ e' ^% b  cdatasource ds=new cdatasource();  //数据联结bean实例
* _, s) `9 d: e8 K. {2 M+ V8 Q3 P. b  java.sql.connection conn=ds.getconnection();
: v- o+ b" |% f0 {6 ^  java.sql.statement stmt=null;0 N5 q2 y, G8 f$ @/ I$ E, o$ b
  java.sql.resultset rs=null;
3 {- y2 n9 e/ O1 M# X% Y  cdatacheck dc=new cdatacheck();5 _" U1 E5 Q: ^" K! Z* ~
%>1 c2 V" x, c2 }+ D5 H' G
<%
; j; k1 B) c  I/ ~# xstring 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";# H/ m  a9 H8 p  S+ j
stmt=conn.createstatement();+ G# L& r/ i3 G& m: u
rs=stmt.executequery(sqlu);
. U1 ~( `  m5 @! d/ h" @( z%>0 ^4 m% C6 ]# |6 \' d
<script language='javascript'>
, l8 e- N, [/ j* Z8 U4 g- S" ]arr = new array();
3 e8 h7 R' Z5 H9 `: H) k<%  int temp=0;
# K1 l+ j% `$ u0 _. gwhile(rs.next())
/ ?; t8 B( I, V( w6 L{
$ R# G, o7 j- Z0 I%>
" x; m% D$ H+ x4 O( Zarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
$ J( Z- c2 H+ a7 \9 w<%
: D  G, M; a) G8 w3 A7 i2 Ktemp = temp + 1;
& A5 O; C& Q. H, H" V}3 R$ K5 \7 n1 }% x' B
%>( p8 Y% o" s; F( ~
temp=<%=temp%>;1 p7 E0 j' W1 m' y
function changelocation(id){ ( e) ~- M( x" @' O* V6 f
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 3 D2 F7 b- H; i0 e: d
var i = 0; 7 \0 Q! n0 b/ k( V! P( T4 A
document.combo_box.city.options[0]=new option('-------','');
. N# s$ f3 a  A/ @% C8 ]* Nfor(i=0;i<temp;i++){ 5 b1 m, x) t3 [9 J' u' C. r
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
$ w& Q9 [/ ^8 ?4 Pdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
; g' R  U) }/ E  T}
1 T8 c0 \& y! n# w) E& m: O! V}
- j6 T1 H7 f4 g2 Q" i}
2 }$ b0 w! t6 _) r+ S</script>1 a8 }( G6 ?. [8 J
) _- q3 o* }& Q  q; _
<form name="combo_box">) p3 g2 ~. M6 l2 B( O- x* t' o
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">9 C( N2 L( f" {* Y) |
  <tr height="24">
& ~; q1 P5 D9 l' ]/ R: ~. [+ ]    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>  I/ E; |- L- @) m/ d- h
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
. f  V- ]% o: y) o6 p3 K    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>; ^6 U3 i; f2 Z( F( P
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>: s. v0 _. j7 N9 }+ x5 L' f2 C
  </tr>
' c# E8 i/ f( G4 n6 f2 W  <tr>
( T+ S* [2 d. L, \$ t1 g" x7 `    <td>
/ B9 ]. h: e  G1 o% H  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
# `9 C7 B- {6 A) q2 V% K2 c. [  <option value="0">请选择部门 ---></option>/ Q5 o7 l8 V3 q( y& O* M6 e
<%
. b, w) u7 v) \7 s    string sqld="select * from tdept";
/ V0 _8 |  _! L5 lstmt=conn.createstatement();
/ R" ]. x! c- d& F4 \" o& J  grs=stmt.executequery(sqld);
2 P$ p, P1 F. S* ^4 o8 s: Zwhile(rs.next())( Z: ^( z# \" G# i) G
{
* n6 _. ?2 I' g3 `4 S, A%>
; ?: y. l1 U4 c. V  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
. Q+ E* E+ }. b8 u! y<%! W1 b7 S; B% M& `) }# w3 X
}0 Q  A7 ?9 H5 C. s0 w
%>
- S# A2 f! N1 t1 Z( P: b, x: i" H4 I  </select>
( _# [' [% w9 e* k  {- U" p</td>7 j$ _5 Z- f& k
    <td>- w% A% e# ~; T; E; R( z
  <select multiple id=city style="width:150;height:200" class="bgc">
( ?! d) h" J* N  i0 `! {# R  </select>, e# ?" m1 w2 u* g) h  k/ f9 Q
</td>
/ a3 e2 q1 D+ r! P4 T. l    <td nowrap align="center" class="bgc">
, X/ L' ]9 i! S& J  <input type="button"  value="<<" class="buttons">
7 O# s2 _, A4 k5 J: M  S; O8 ^1 k/ a- y  <input type="button"  value=">>" class="buttons">
/ j$ i* F3 _. S( r: r& n, O</td>
6 j& i/ s6 ^* A    <td>/ F7 P. o6 q3 T+ |! b( u! j
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">8 x; T+ C* o8 `) |( Q' ?
  </select>( d: ^: Z% f) y5 X* q" j
</td>
: {" w- b  H0 |( ]  </tr>- W; g( P/ T: e( |8 n0 o9 Q
    <tr class="bgc"> + c! Y( y$ Y' Z4 W7 i5 b
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
1 h4 R6 c8 |4 ^- I% |' G" W  </tr>. [) Y$ G8 i8 ?4 a7 |. {
</table>
2 y0 ]# q8 d  o' D- E& Z</form>
! I$ H# i: l" d5 Q<script language="javascript">  H' w! B4 a/ U; `- {
//人名移动/ H& R* ?3 e( v  E/ X
function move(fbox, tbox) {. Z( u" c2 g9 S& H9 M/ g- R
var arrfbox = new array();
5 e% d+ J# a) S9 Tvar arrtbox = new array();  A: l" h6 \  i2 Y2 [
var arrlookup = new array();  O( B7 W4 o( h, J
var i;
) C  Q( v) r- f' C* d4 Q# Zfor (i = 0; i < tbox.options.length; i++) {
1 F4 J3 j8 U0 M* ^arrlookup[tbox.options.text] = tbox.options.value;
1 h/ t9 I5 T% H3 d4 |' varrtbox = tbox.options.text;- _( `* q1 ?* e% Q9 |1 m
}3 v# }/ _3 y' I9 t! H% |2 ^
var flength = 0;4 \2 Q" G" |% h: ?" U' Z) B+ {$ q
var tlength = arrtbox.length;
- L1 G; ?. \" I8 s4 ^2 L& yfor(i = 0; i < fbox.options.length; i++) {
" D2 u% P9 j+ P) g% N2 M2 q: ]arrlookup[fbox.options.text] = fbox.options.value;
" S4 E5 Q2 f6 N" m% u+ ]  Nif (fbox.options.selected && fbox.options.value != "") {9 B2 }: i- ?0 M7 z$ J" I
arrtbox[tlength] = fbox.options.text;
9 s" o/ d8 \8 e/ K# D- C- \: atlength++;
4 |: u) A2 ~& }* a' L( J0 S4 U4 D0 o}
  D' y  |7 a: x7 D( r7 c) |else {3 J2 S/ C9 Q  \& o! e7 u
arrfbox[flength] = fbox.options.text;- \$ s6 Z& ]+ q0 Z
flength++;, H8 F- h/ w$ n6 H# P& M  b* l
   }
8 U8 f1 s8 Q( R: F' F}& [. l' ~9 V* ^+ e
arrfbox.sort();2 U/ n$ B4 ^6 R
arrtbox.sort();
" ^9 Z* j' Q. W. a) V9 |1 N+ J. I; ^8 i" p- I  l
fbox.length = 0;. \0 H9 V0 c' d: ~6 n
tbox.length = 0;
0 \% s$ O. e6 `! S  vvar c;8 I7 X5 {4 A' ?$ G
for(c = 0; c < arrfbox.length; c++) {
  T# C5 _* h" P+ h$ `' `0 bvar no = new option();0 {% W# A" i9 b# k. b
no.value = arrlookup[arrfbox[c]];+ X4 g# @: V1 s, h/ v; f
no.text = arrfbox[c];* n: m) V) P4 G! k" p9 l! x1 T
fbox[c] = no;
/ J7 S2 h) F. a}4 m; B9 a- r! ~7 c) [, H. q
for(c = 0; c < arrtbox.length; c++) {
! M1 p: |+ ?3 t  lvar no = new option();' B4 m$ u. O% v5 i( e1 t
no.value = arrlookup[arrtbox[c]];5 Q5 x! n4 l# |& @0 f1 x5 P3 O# f
no.text = arrtbox[c];- U1 ]- \! c5 q1 C  g
tbox[c] = no;
8 @" d& c' w, U' V" U   }9 \2 f% \) E! m9 m9 ]" ]
}
# g& R& v  f( g</script>( D% `7 A/ o$ F- O# X+ O
</body>* o% ]& I5 _; x) I% M$ L

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