返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"1 G$ J& f- c; u( s
         c pageencoding="gb2312"
6 N( Z, ^: w% W; e. {/ W%>9 X3 ]1 G; x, x. {
<style>
, y* N& M' _/ _1 k. {- L) G.f9{ font-size:9pt; }3 Q2 a" S. N, I5 n# B. Y: w
.bgc{ background-color:#aecaf9; color: #0033ff }
9 O$ @. ?! C& h- O6 z3 k.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;% j$ T, \6 B* C* f9 Q% K
  border-bottom: solid 1px #4e7dc1;
; u" C8 H1 D9 }8 h9 u% D  border-left: solid 1px #aecaf9;
8 q& {6 S+ \( k& n+ {  border-right: solid 1px #5679bd;" d$ P1 F& v0 y& O' D( y% }
  padding:1px;
0 O! j% x. {# I# K  F- ^8 X  margin:0px;}
- L3 C: w: G/ {' h</style>
7 X+ u7 f9 n' S: B! W/ r% @<script language="javascript">
" u) c# N/ m' E1 K& e: h0 n: w<!--- j  R: ?: R5 t7 n
function rv()$ i6 R7 _3 d' b3 S; }4 V
{
* ]8 u  w9 l# L# \+ s4 a: D  var val="";- l. `- {/ |; L$ d/ Y
  for(i=0;i<combo_box.list2.length;i++){
2 a9 k" K3 f/ F   val+=","+combo_box.list2.value;
# W4 l5 F% r/ n4 H* o0 {  }5 ^& K6 d0 h) \5 j
  if(val.charat(0)==","){6 |( O. d1 A& ?. k
   val=val.substr(1,val.length);
2 `( u. `2 ~/ C3 d  }5 [% z2 p, Z/ R2 A/ u7 K
  opener.form1.frecname.value=val;- P1 V* i, {( r
  self.close();
6 {6 {; ~# {( p9 d: @}' A) t0 I, Y: M5 @
//-->
' X! y5 y9 p( x9 Y3 H: s</script>3 C0 D; u/ _( a7 o' n/ H/ e0 Z) N
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
1 ^0 U5 ^) `8 N) \9 F7 J7 u8 }' r' l9 u<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />' c, y# c7 [& F  r
<%: y3 {5 r3 C9 v9 S. E, C
  cdatasource ds=new cdatasource();  //数据联结bean实例$ k) c) a8 B8 |# X  q. y5 s4 }
  java.sql.connection conn=ds.getconnection();
4 ?( n- z& L  O) [- S  java.sql.statement stmt=null;
5 Y3 C' K, E$ w* E' z  java.sql.resultset rs=null;- n( q# |/ ?3 x- w) v0 N% X0 a
  cdatacheck dc=new cdatacheck();
, |$ T# i7 D( q5 j%>
% q# x" K% R) c7 q; |2 S<%1 k7 ]9 I1 d, Q1 Z( N  y) ~
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";, P% W6 ^5 ~9 U
stmt=conn.createstatement();
. F- D# F" a7 r) Ars=stmt.executequery(sqlu);  V  v1 D% D3 z( W
%>
: k! v! h5 {' V. s8 J& ?, g( X<script language='javascript'>( w& s7 A' C; a8 j& r1 F7 p( d( U
arr = new array();  `/ K  r6 X' D1 g/ g9 X. F
<%  int temp=0;* |  J' F' R7 t* M7 \
while(rs.next())4 s$ u* \! p. K* n
{: p1 z+ D3 w' }1 t0 j5 o
%>5 M: T' m) i) J( l; h
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
8 N# N2 B% n6 M/ c, \# ~<%
1 t7 }: h/ D+ M% |8 D. a4 ptemp = temp + 1;
) h. s9 R0 n$ B+ W8 G, \% z% n8 k" W$ z}
1 {' u$ q, v2 d8 x/ [6 `3 C) W& `%>+ d  p( H' J" s  L  S: H) P/ ?
temp=<%=temp%>;
: m+ d4 ^, C$ H5 Y" Ffunction changelocation(id){
# k( {8 M( ~9 B! |; B4 Mdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 ' N" k5 W! J0 u  K+ j' q- J  B6 Y; r
var i = 0; ) @  g! ~. a' p6 P) p4 G5 T0 ^
document.combo_box.city.options[0]=new option('-------','');
6 h6 V9 R0 Z% Q7 C! hfor(i=0;i<temp;i++){ $ p2 _; y) Y* T$ b& [* w+ j* S" |" L
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] ' l, j' z  z& y! k
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
: o/ u9 Z' b) w/ L# d1 G}
0 y  x5 z7 J9 x}
  Z) o: S3 ~- s) q& d8 f/ m} 9 M9 j! v5 H0 t
</script>
0 [7 P, o/ G4 W, G+ A6 _3 I1 R9 A" `* Z/ L- n* I- H% \9 I2 G
<form name="combo_box">
. J- \0 A) L' F4 K' x1 t- o<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
( A, {* x( X: Z0 x1 j3 Z8 u8 \  <tr height="24">
  {  m+ ~/ ^  j  e    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
0 y  }; Y6 ]1 w  q- X& D3 e; N' T    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
8 F$ V- S0 b- N* W2 g) \+ X2 d    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
+ N' o# |, a3 l: z0 }    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
7 L3 x# i; h1 i, R5 w7 s9 y  </tr>
( v$ L) v. o2 L3 v  <tr>
$ V: d6 l7 F- K3 d, B    <td>$ }& s8 F  @. w, W$ j$ F
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
2 y6 ^; m' m% X  <option value="0">请选择部门 ---></option>/ m& E  ^$ d  a" e" _
<%
! \, ~: q# N+ h: r: Q3 Y; K7 N4 `6 }    string sqld="select * from tdept";
. b- V) E$ @) ]5 @! m2 c9 D9 o4 vstmt=conn.createstatement();
3 {  c$ F7 W9 Zrs=stmt.executequery(sqld);
& X3 P, l0 Z2 l5 [! twhile(rs.next())
8 D/ p( N" N- I$ Z6 |- |{- p& L1 N/ o% E, c' }, Y: e0 b
%>
. a. c  _/ i* N3 `5 J% J. L  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>4 }/ i8 b$ G6 @, j
<%
: [0 E9 u4 V! _}
5 ~* Z2 `) j2 N( J/ `1 q3 {  o%> 6 q+ f% k! {  p# O% Z& d2 X- \, b
  </select>
4 ?+ O3 @8 ^( S</td>
& @7 R8 G6 u7 z    <td>
2 D2 P/ w* I! C, O7 \: R  <select multiple id=city style="width:150;height:200" class="bgc">
/ |. \5 P0 `: O4 H  </select>, C( \) o) `0 P7 \) u- |8 e
</td>
- |( M" b% O) z! O3 M    <td nowrap align="center" class="bgc">
& c4 g$ z) d6 `% @1 u4 w  <input type="button"  value="<<" class="buttons">& {! m+ `0 w, @4 ~& G: P
  <input type="button"  value=">>" class="buttons">
8 G6 C1 c7 q( @! g2 F' [9 l: F% l</td>1 x* ^& a  i. `/ U0 z. ^/ x. S
    <td>
" V) e" I0 T; b! A  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
; i4 `! p1 e8 b6 C) ?& K6 q  </select>  Q' Q1 d- o9 }% a+ ?$ F
</td>% U  m" r* m5 |
  </tr>
/ u" O4 Q1 C8 ~; q    <tr class="bgc">
+ @% H' c% M7 W' B2 Z( x1 y    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>& r' H# _2 Z  V; G! C, a
  </tr>
: Q* n0 z# l% f9 Q' [, H</table>
+ q6 k/ T( @7 \3 e3 }5 e5 e</form>/ G! Z' ?2 `  u( |7 J4 w2 T1 k
<script language="javascript">
6 T; C9 o, A5 V# k//人名移动# p  R! P2 }  n. \' g! n9 u8 F
function move(fbox, tbox) {
' R) Q& e+ d4 ?  s7 Y5 p+ k- kvar arrfbox = new array();7 I5 {4 L# c. k& X' r2 F' w" i$ x
var arrtbox = new array();4 C+ J# I: j2 T' ?3 A0 x; _
var arrlookup = new array();
$ g$ K. }+ X3 g% g9 L3 Avar i;9 O- h* l& G  _7 L; q$ |
for (i = 0; i < tbox.options.length; i++) {  U0 g6 n2 y3 M8 u4 t9 N! M$ h
arrlookup[tbox.options.text] = tbox.options.value;
: j# Q* o+ U) u+ C0 @arrtbox = tbox.options.text;
) P0 i1 S2 f% f' G! ]3 |3 B8 E" m}
: `$ P2 F# s- y0 Q& u; x2 Yvar flength = 0;
1 j2 n' l5 C$ m" ^$ M* x0 ^var tlength = arrtbox.length;- u8 Z" h6 Z2 R0 a" }
for(i = 0; i < fbox.options.length; i++) {
# e0 _1 x# l2 S0 \# u1 Parrlookup[fbox.options.text] = fbox.options.value;- K$ F) X6 w" f9 H0 ]
if (fbox.options.selected && fbox.options.value != "") {
; c: m1 ?' C$ O; r6 J* Sarrtbox[tlength] = fbox.options.text;
$ @  `8 n' r+ l: s2 Etlength++;( C; Z/ I3 T# I1 v
}
0 i$ h, c0 }$ x( u& pelse {
8 u" Q$ w8 a: Q7 s  y' jarrfbox[flength] = fbox.options.text;
0 A/ W( B% |% G" O9 F" Q! j# Gflength++;0 j6 `9 h# M% ]! h* \
   }( T+ I% Y5 r  [- s8 h* A. X
}
9 i8 n/ T* D. j) _* J1 ~3 ]) ^) t8 Varrfbox.sort();/ x# B  U- z3 r8 D, a5 K. C; w
arrtbox.sort();
- C3 ?+ j+ R) a8 c/ M4 O* p$ V$ d6 U6 e9 k2 M
fbox.length = 0;
, o- O" G5 V$ Etbox.length = 0;' |. V( U7 q$ b+ c) M
var c;
  m: H- |5 `. t( T' ^! v# Ffor(c = 0; c < arrfbox.length; c++) {  r/ K( O! b5 I7 s+ \0 I) P1 {
var no = new option();
1 L- |% q0 T; Rno.value = arrlookup[arrfbox[c]];" z7 e! u5 D# P6 L, r
no.text = arrfbox[c];! U4 Z" `" ]: F; F7 K3 q
fbox[c] = no;' f; f5 L+ D+ H0 t! i9 ?; E
}. u3 G' L- ~6 h0 R3 z8 G" L
for(c = 0; c < arrtbox.length; c++) {
6 _* o+ A" x) S, E% a6 I& J: avar no = new option();; D1 P0 Q$ Y' |$ i
no.value = arrlookup[arrtbox[c]];( U2 z& H. ~+ G9 c, b% E
no.text = arrtbox[c];
8 Q  N7 [8 f7 V  Z7 qtbox[c] = no;
& j5 }7 v+ i/ G) {   }. j! ~# t# f/ c, c. m3 L
}
, h0 P2 l2 v; i  c</script>$ U7 H2 ?5 Y! k& W3 K; T1 n
</body>
6 ]5 m* H/ Z# H! M$ k/ ?, f  P

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