返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"3 n1 D. \1 c  ]! x4 V1 R; l
         c pageencoding="gb2312"( |) u. x' |: ]2 T  h3 H8 N8 ^' a
%>
; S& V# N2 X4 u/ |0 {! z+ C* ~<style>
! m( n7 y0 x$ J3 B9 }.f9{ font-size:9pt; }
) o8 v3 W3 L! Z. U  D.bgc{ background-color:#aecaf9; color: #0033ff }
" h2 t/ H; S* F# w$ d' f.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;8 Q5 @( {. E& q4 q' z; m) v
  border-bottom: solid 1px #4e7dc1;$ P, P. j8 ~( Y& @
  border-left: solid 1px #aecaf9;2 w9 B! b) l! P6 j
  border-right: solid 1px #5679bd;/ }, h* Z. R" @0 ?1 W$ |* k
  padding:1px;
3 }5 l. [8 P% {1 z. t# C9 E  margin:0px;}
7 ^% _/ d7 V0 k1 S4 U</style># {2 L# `7 a: ^% N" ?9 g
<script language="javascript">
3 P% k9 e6 n( q4 G. h: L<!--# t7 k! l% t5 h: B
function rv()
, O& s4 @# e# C) V0 S! U+ J{
3 `+ N. T5 R. H- F  W; m0 c  var val="";
* r! b  O0 R6 p  E) z  for(i=0;i<combo_box.list2.length;i++){
( E: _+ m* M: \- o6 a! U   val+=","+combo_box.list2.value;
+ R7 J0 I( E. y) J/ d  }) Z  A; D6 a% z" y$ i
  if(val.charat(0)==","){
0 {6 Q- O0 U5 ^* ]   val=val.substr(1,val.length);
/ f5 P6 k( g, p4 W( H1 A* c  }
; A/ R5 n- @4 f  opener.form1.frecname.value=val;
1 O5 s  V9 S! F% H( G) ~  self.close();
! ~; _" q  x9 Z& M9 d( F+ ]; E}& ]: M. l" U& S; @
//-->
  e1 U& A$ z4 d</script>1 W- s6 `, f( {
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
7 @  Q1 h( n) H7 G<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />( J9 x/ Y2 J1 d( D
<%+ g+ _1 b9 k% o! r; ]; y
  cdatasource ds=new cdatasource();  //数据联结bean实例
$ X" V0 C# |  V- O9 `  java.sql.connection conn=ds.getconnection();
" g; M2 X! G& E  java.sql.statement stmt=null;
! |1 u8 U  _0 r  java.sql.resultset rs=null;& J$ E2 t! w9 `4 M' ^
  cdatacheck dc=new cdatacheck();
1 X" ]) N; s& ?" H& @%>* }3 z/ x2 A1 `" b) l7 C" y* f8 S
<%
2 i; I6 T+ @9 T0 Q# zstring 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";9 _/ i; |% G0 ]5 Y! I
stmt=conn.createstatement();
4 k, s# x- P6 K1 D1 [rs=stmt.executequery(sqlu);
0 [, O+ L8 M# l4 x3 t%>7 j, Q& K" h1 |( t4 x7 o: w
<script language='javascript'>
. m0 @6 A8 O4 B+ G3 Y- U# d+ farr = new array();
- E1 a& {1 _( y1 J5 C) n+ ?<%  int temp=0;
0 G8 s% Z3 L" N5 v4 R  r4 \while(rs.next())' G8 s7 ~: i( X' H7 J
{
3 H7 {& U" O5 I# K%># K8 f/ V% l; @& A) y$ d# \4 v
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
4 W* q3 e$ w- u3 ^. `<%, o' p, U9 N/ t* k1 V* a1 C8 R
temp = temp + 1;' h1 @5 x' w* h4 \3 i
}
$ O( H3 m! D5 Y- c2 }3 R. z! c2 D# \%>
$ X# P$ U' a* y3 m8 R3 Vtemp=<%=temp%>;
9 X( ]! `- g. n4 v" L0 p* G# J4 H+ Pfunction changelocation(id){ . B, s$ l5 j: L: L) r+ A
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
0 j# S- d0 N4 F) q" Pvar i = 0;
# R( q+ R8 x  ]5 K5 jdocument.combo_box.city.options[0]=new option('-------',''); 3 x2 u3 p( Q* E( U! J
for(i=0;i<temp;i++){ ! B/ n6 L/ z5 U) j+ j0 O
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] . y6 w3 V7 y# R  O, A. v
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 8 M6 m" b/ I! V2 Y+ F, k; H1 ?
} . @2 c' z! e+ t- P+ R
}
0 A9 H/ U6 Q; _+ w" C} 3 E; P& S5 m# U# O6 ~+ Y
</script>
+ @. G+ |- u+ Z; Q: \7 D8 n! `5 J, l, R9 i& ]2 k8 l7 m& `6 V. j
<form name="combo_box">
+ x% T4 t, c# s" ]" H6 f; A' @( O<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
" k5 Z) K' Z% z$ ~" y% F, r( d7 ]/ j3 A# R  <tr height="24">4 p  Y4 }+ }# N! |9 c
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>3 H& p$ S' V! J" v- Q5 @, M
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td># F  b2 w1 }3 A5 l
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
5 r" W9 a# T1 d; `5 O) ^1 p    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
. o. b/ p$ H& ^( @. L  </tr>
& i1 g. A( J, ^8 H4 M1 X# g- N  <tr>
* K: x4 r2 H; o* o$ s# A    <td>0 E% t/ E2 h/ _, Z
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">* e1 j; _2 f8 W* G' N3 n
  <option value="0">请选择部门 ---></option>( ?0 W" `" q: p. v/ o
<%& B: I& `5 D2 E% w6 v6 s$ T
    string sqld="select * from tdept";9 g* S6 J. ~% E# A8 Z! B+ J
stmt=conn.createstatement();
2 Q. ^$ T$ ^# r0 mrs=stmt.executequery(sqld);
) k. c; o/ `7 E: q9 A" G" l0 W7 Awhile(rs.next())4 z$ i  h3 D+ d2 F1 V) s
{9 ^$ W4 l. {! s! c. l
%>
# U! t3 z; N. e7 I  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>4 p* Z) g$ b6 D. \; j
<%
0 F( n( S5 [6 C; W}: M+ N) E: Y8 s. K4 v
%>
& m5 N9 @. k: _5 W0 w8 Y  </select>
! g) g1 d; E; e6 A2 x; B</td>+ N0 Z& X) P6 u% h' O( b
    <td>! ?2 g% k8 N+ Y6 s9 `  G) ]
  <select multiple id=city style="width:150;height:200" class="bgc">/ R& T- \+ J" a' N% E( W9 J# O$ \, M
  </select>% L6 g2 N+ n' X
</td>
! r8 h) }+ N, x( F; ?8 v  N# P; c    <td nowrap align="center" class="bgc">
5 I" b; }- s2 ^& ^& O  <input type="button"  value="<<" class="buttons">7 K  E# E! k2 m; T/ ?, }& Y
  <input type="button"  value=">>" class="buttons">! W3 o  n% f  h2 N8 t$ n/ F
</td>' d! ]& f/ n0 M
    <td>
& W% F9 i! s9 t& J  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
1 v% [+ d% i- |7 s  </select>
* }1 Q. e8 V; n  g3 I# ?7 i</td>
& x0 ]+ u6 B3 V- I6 h  </tr>- Y' j8 `3 F: S) e% J
    <tr class="bgc">
, V7 C$ i- o+ M- r    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>% L$ m, p+ {, I+ M: Q
  </tr>0 b: o  E9 Q  E! M) Z
</table>! B, Z: A6 L$ _  H% s% C" K) P
</form>
( G/ Z& {; j8 K+ h8 D0 J" Y- g% ?; G<script language="javascript">
+ _& M$ e( p* {; U7 o//人名移动
( j$ ?& K% K+ A9 Cfunction move(fbox, tbox) {6 X% R4 S1 w3 h. f) d  `
var arrfbox = new array();& ]& [; u1 j' e5 w! t  T9 s! S
var arrtbox = new array();
- D5 }. a( \7 E8 ]! S0 r2 avar arrlookup = new array();
; ]  H: w, B" ~7 Y6 {# f6 K8 A6 o4 }var i;
" H8 Q/ N4 A( T9 I# A; Tfor (i = 0; i < tbox.options.length; i++) {
, |8 A) G3 o# j; E, d# Larrlookup[tbox.options.text] = tbox.options.value;5 C$ |4 u/ @; U& g+ }: q
arrtbox = tbox.options.text;# }1 T" q/ Z5 c' U  s
}
9 O) \9 z! z$ pvar flength = 0;
5 U2 U4 f- ]9 s& Z# R% V7 Fvar tlength = arrtbox.length;. o; J! [. X; [4 F2 X5 v+ r  v
for(i = 0; i < fbox.options.length; i++) {
+ G) q% e9 i- x. rarrlookup[fbox.options.text] = fbox.options.value;
% X2 Y( @5 X) D) }( `( ~! Mif (fbox.options.selected && fbox.options.value != "") {
  o1 O2 `, w4 `; |6 S" O- Farrtbox[tlength] = fbox.options.text;
/ `  R% M5 U$ Z5 T, L$ K& z- Htlength++;
& ^- Y) e1 J; H. k) C}, H5 a4 F) h/ c+ _/ U  k  T- b
else {( v$ u( v9 W- u9 v- A  M9 h
arrfbox[flength] = fbox.options.text;1 a2 Q! j& V" U. ?
flength++;
, m' D2 ~' ~) `, y   }
1 Q8 f& k; J4 Y& h1 Z# k# Y}6 K7 v9 n& q+ @. d; ?1 A* e
arrfbox.sort();6 g2 v9 S/ Z' j/ V) w
arrtbox.sort();
7 C+ F0 |$ e* v5 _; j
, o1 O$ c( W4 Y) P/ c& ~fbox.length = 0;& b3 M' X" E  p) U
tbox.length = 0;
1 c% P6 u+ L; M  Y+ Nvar c;' P9 |3 ^9 f$ o! e7 G% m8 f. R4 c6 u
for(c = 0; c < arrfbox.length; c++) {
: I4 ^" R/ O$ C  |& m& N$ `var no = new option();/ Z7 E. M) I# d2 b; C
no.value = arrlookup[arrfbox[c]];8 L7 K' ~1 J$ J; N
no.text = arrfbox[c];
% e7 L5 N* v6 G8 y4 Gfbox[c] = no;
2 P. R* V2 ~8 j6 u# U3 i}# h1 ^2 E" A0 ]' k2 P/ D
for(c = 0; c < arrtbox.length; c++) {3 ?$ F8 N; t# V
var no = new option();3 L% V, K$ B3 ~1 }0 h
no.value = arrlookup[arrtbox[c]];
9 m2 F: l' Y. T  V! Ino.text = arrtbox[c];* l. d$ t" {4 y1 R3 d, }' i1 [
tbox[c] = no;) }8 c3 e& c# |+ ]8 u5 j2 d( W
   }# A' T& [6 `- Z8 @$ O0 O8 y! `
}8 v8 b: W) {2 K4 ]3 [5 h
</script>1 ?* y; D4 L- H
</body>
+ c8 P% F8 d8 f$ ]! ?

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