返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
, L: q8 v) x( Q; s& _3 N% {         c pageencoding="gb2312"" ]" q) F3 p8 r: Q: n* d
%>
" N* @$ ], I4 S% n/ a. v9 T+ R<style>
% P4 v5 e6 L9 b2 c/ S0 n- }% }' q.f9{ font-size:9pt; }
; M9 I0 r; W0 t2 D* s.bgc{ background-color:#aecaf9; color: #0033ff }
3 [9 R  [# o' |/ e9 }.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;8 y$ p  k3 k6 h$ i, ?7 e1 H, ]
  border-bottom: solid 1px #4e7dc1;
( H7 W2 p# c0 _9 q; C% K  border-left: solid 1px #aecaf9;( ^9 c& [' B1 U+ O" B
  border-right: solid 1px #5679bd;" u  D3 E, Y& m5 \5 Y; K
  padding:1px;, w! a- q/ ^, Z1 P' n! @& B
  margin:0px;}6 F* P/ I- g. J0 X
</style>! J7 O4 J3 N- W& Y: s( I: ]% B% v  s' z
<script language="javascript">
7 @2 P9 I! A/ r) s4 A. |<!--( i$ d( F" |) i8 {
function rv()
" r1 C: @5 I$ p6 r) F0 _4 }6 ?{
( t- M" `- M- _. f  var val="";
0 w6 L( E1 Y! P% T) D* s2 r  for(i=0;i<combo_box.list2.length;i++){6 E9 h2 w1 C! y0 O" V- F
   val+=","+combo_box.list2.value;
2 {$ P0 P( H# j6 f% r  N4 H8 J  }
; j! }+ z& C5 t+ c& J  if(val.charat(0)==","){- f0 U' ]/ a- z! G, O- x; G
   val=val.substr(1,val.length);
: \. t) U$ s5 \/ C& ]  }
) `4 p" l: r- c4 p! R3 T  opener.form1.frecname.value=val;+ x, h+ i7 z7 }
  self.close();- v6 I2 N" ^8 K
}. t# _" p5 ^; W: N
//-->+ l% b+ G9 j! x
</script># V1 k4 N3 g: K  |$ b" ~
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">; z+ V/ t  N/ E# s, K
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
: B7 d. V5 {+ W0 W" V<%
& N9 O! O3 G! k. N  cdatasource ds=new cdatasource();  //数据联结bean实例( i6 [- D; d1 d$ [1 k' b9 j
  java.sql.connection conn=ds.getconnection();
8 S8 ^9 l* S( f, }, U/ F  java.sql.statement stmt=null;! V. |: J5 c8 P0 Q# I3 Y/ w
  java.sql.resultset rs=null;( z: `: J5 z  T8 w
  cdatacheck dc=new cdatacheck();
4 _  q% ~( \" C+ b" N  E6 X%>+ L7 `- a+ m- \. R0 Q* \9 \
<%7 }; B3 l8 Y6 U6 c% C. Z3 O2 W
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";2 v6 {/ H$ V: v. g
stmt=conn.createstatement();6 b4 V* X0 `, P. @( O3 _/ f0 @2 J
rs=stmt.executequery(sqlu);' k4 m1 i" u- q* [" L( v2 n, P6 V
%>+ G- r8 M% `+ |8 o  @
<script language='javascript'>
. j4 T/ r  h. Parr = new array();+ l3 x. I$ O/ U2 H% [/ j( E
<%  int temp=0;
+ A8 @: x9 A& V  [% n/ Ewhile(rs.next())0 l! E) H3 V6 W' S
{
6 M! n4 |1 K' M) Z$ k' e%>
) |- _, b8 N# b9 P% Sarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");1 n  K5 F3 h& V9 e3 h+ x9 n
<%
- I1 {7 d0 ~$ J9 v/ m6 stemp = temp + 1;
  C4 d$ V8 f! G5 p' d/ b}  ~$ i: U" S# S% p( o
%>4 e; ]5 B8 C" u5 B+ Y7 Y
temp=<%=temp%>;
/ r2 V3 ~, d& O2 L3 Ufunction changelocation(id){
2 P6 W+ ?  J( Ldocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
: h3 I. A0 q7 U6 q% Vvar i = 0;
! O- E. u3 k* Gdocument.combo_box.city.options[0]=new option('-------',''); 3 |; Y$ J+ [# u+ d7 r: b7 _
for(i=0;i<temp;i++){ 0 x5 y) D* B: w  `( |+ H& I) U
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
" U8 c& [* S, t' y8 }- [document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 2 J* `) d  Z4 M: ~1 Z- S
}
$ }+ ^$ k' r+ M} ) S  T+ `' r/ E* d& W
} " c6 d! B. k( @% z, v6 c9 d0 l
</script>
( o7 b3 A3 j! f4 k! d- {- T& ?: q) o; P" k% [
<form name="combo_box">, Z$ L; w! l4 {
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">& k1 K& P( }* W" R8 ~) V* z
  <tr height="24">
' H/ @: g0 G1 {2 ^    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
2 Y+ _  W6 L" K; c3 y) Q' J    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
" I1 B, ]0 H( |3 L6 {    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
" Q) L4 [* ~# [1 v    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
- |4 l  o9 W& ?* r  </tr>
: W- ?1 C2 }. [- ~1 {  <tr> # p( i5 g$ O* Z$ n( X; j0 G
    <td>" O6 W% a# k; b% `
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">9 ~( D: E# O) n% @' ]
  <option value="0">请选择部门 ---></option>$ u& ?4 S$ Q. B* e: Y
<%+ V1 s. P  c* _7 z5 l
    string sqld="select * from tdept";
! d6 w  z; Z2 Z# cstmt=conn.createstatement();
7 @2 Y' p2 T& o4 b7 D7 Z$ ~rs=stmt.executequery(sqld);
8 x$ _6 E- ~& x% A4 m3 [while(rs.next())! o7 i' B  ]# X2 C  m
{5 e0 G9 t$ d7 M' S. ^* ?
%>
7 t2 v" _+ F$ g4 G5 n$ V  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>& t3 v0 m8 O' M: s
<%  F4 L- i- H' K' _* V
}
  P+ [8 f4 I7 B. X0 c) j! ~%> 8 |, f, H& L- h. Z1 _( e6 |, j7 j$ N
  </select>
$ r6 L3 ~" I0 A! L  d  A</td>
; Y. i* R  H1 z/ _1 }    <td>
& V& ]* }3 A8 ~: u) p4 r8 {+ W  <select multiple id=city style="width:150;height:200" class="bgc">
+ U5 _" T3 r0 b- k; f# j  </select># @6 X+ k* n  y; ]  H: y5 d
</td>
# U/ A# Z8 G9 B& [0 W    <td nowrap align="center" class="bgc">& R! o! P- V' D6 d
  <input type="button"  value="<<" class="buttons">) A7 B" Z. H2 N9 L% }5 Z% y" w
  <input type="button"  value=">>" class="buttons">
  v( ~% x! O" B3 R0 ]</td>, K7 y4 J" `, F+ R' F+ W7 M: v
    <td>
' o/ v5 g: p9 k2 L8 B, q  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
  h0 v5 ]. a! ^* \  </select>/ L3 ?. K2 S: a6 T, t, U
</td>0 n3 X# k$ U+ f3 J& W
  </tr>+ I4 w" {; v) x8 B+ H
    <tr class="bgc">
: V" S' n5 Y/ h/ N    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>& D5 R6 `7 O2 F7 @7 g
  </tr>
; V# w' c6 A$ z2 }; Q: \</table>* o! N" P" q# z- W- M
</form>
0 g# j, z. T; P4 K  q<script language="javascript">5 b% X& q* g8 I
//人名移动, P; G: j3 l: o8 ^+ B) `6 P
function move(fbox, tbox) {
# A" r1 R% Q) O. w5 `. V, A3 ~var arrfbox = new array();
5 _9 x. e  N, ^$ B. c" ^% dvar arrtbox = new array();
5 }5 F) m# X9 X+ c! wvar arrlookup = new array();
9 j- m( h" z0 Y) tvar i;
2 e* m. E, u/ ^/ Pfor (i = 0; i < tbox.options.length; i++) {
) M& ~# c: ]: v- F8 v4 _' a. n9 sarrlookup[tbox.options.text] = tbox.options.value;$ [- V( m6 p4 O) ^/ _$ D: L$ ]. H
arrtbox = tbox.options.text;
3 I8 w5 J- e; ]( F}
. @! Y' \* n) tvar flength = 0;7 D6 a0 p1 Q% i( g3 B
var tlength = arrtbox.length;
! C8 p9 X8 R7 `" c) v. a% e1 y9 Hfor(i = 0; i < fbox.options.length; i++) {
; J) ?  R8 M8 W6 K# d4 oarrlookup[fbox.options.text] = fbox.options.value;
2 d5 q% H' ]3 E# O; M5 [% v- l& ]0 \; Yif (fbox.options.selected && fbox.options.value != "") {
! d9 R$ h4 \4 O7 D( uarrtbox[tlength] = fbox.options.text;
# r5 K$ k1 J; @/ y3 b# M1 J6 Stlength++;
" X1 }* h  Y+ C7 [" K8 L, V}
, f. i' W% t. e, O; H+ Helse {
# N  h$ U0 t# z, L  M" I0 Y1 farrfbox[flength] = fbox.options.text;* Q( [" Y6 V% c- s$ z% y; b
flength++;6 ]0 n3 P/ E; E
   }9 A/ p* N3 I, b
}
7 A/ V% W6 b# C2 u* Q. ^( M/ tarrfbox.sort();6 L" t' R' ], L6 J; Z: O- o$ n
arrtbox.sort();: Z5 d+ m  }2 Y0 ?. G0 d

/ H2 S; K; X( {% |3 h3 efbox.length = 0;
* V+ \5 }- W6 atbox.length = 0;% j3 b  ~* q2 r; `
var c;
- ^; W' t. k! K, R. `& efor(c = 0; c < arrfbox.length; c++) {( i- Y- p; E: l1 o4 @
var no = new option();$ A" A7 m' f+ N7 N7 k2 I, `
no.value = arrlookup[arrfbox[c]];- n6 m. \; T6 J( B9 R: ~3 a: S
no.text = arrfbox[c];2 w) b; P/ i6 J& j( d: w& I
fbox[c] = no;
! O& G$ |3 n+ ?+ n& T" J}
8 @) ^6 }" X  _7 h: Yfor(c = 0; c < arrtbox.length; c++) {
; K. t- x# @: P( _  mvar no = new option();
% u5 d8 \" o: o' W2 ~7 Ano.value = arrlookup[arrtbox[c]];1 ?+ i) |9 f/ C$ E
no.text = arrtbox[c];  @& |6 n2 v. f0 H# U! B0 N
tbox[c] = no;1 }9 A, _1 @' r+ a
   }
2 [  R* O3 }' _! e  U* s. d}
4 Q: w2 S' M6 ^! d: F1 n; E+ h7 f</script>
7 \' Q4 O  Y! g9 P) W+ S</body>
/ _9 w0 i' R4 F; I% W: W

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