返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"2 D9 c0 j* h$ v! F9 P
         c pageencoding="gb2312"
5 \+ J5 m3 e# r5 S4 I%>
* `- c: R3 m% ~2 `4 c7 p1 u* N<style>+ n" E' i4 t* F0 [8 o; s2 i
.f9{ font-size:9pt; }
2 q6 W% R" }7 G4 X& k% Z.bgc{ background-color:#aecaf9; color: #0033ff }2 C! _) C4 V$ J8 f, o
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
# V" V# a& b6 O5 N2 Z4 ^  border-bottom: solid 1px #4e7dc1;8 a- c: t  L5 B, t
  border-left: solid 1px #aecaf9;! Y  b0 l6 ]& w, S
  border-right: solid 1px #5679bd;( n: U1 A) S2 M/ V$ v) {- x6 B4 T
  padding:1px;
3 ?7 t$ j; c8 l5 Z% @/ W7 p  margin:0px;}
3 q; ]7 F* U) ^! P* i' W</style>
1 U7 v0 k) M& ?<script language="javascript">
5 Y/ j* r! h. A" {<!--
8 C- v. R# D# ~" }& sfunction rv()  m, o1 r7 v) }# q/ A
{$ f: c& v- v# L2 `; d/ s) n/ H& O
  var val="";
+ |5 s+ w) _/ S  J: z) @$ k  for(i=0;i<combo_box.list2.length;i++){: I  ~7 M( O, a# k+ N, P* F
   val+=","+combo_box.list2.value;
3 v. ^- U) u% P2 L3 |- J  }; Z9 `% U' ~  D
  if(val.charat(0)==","){
- r0 ^* M1 Q6 q& t   val=val.substr(1,val.length);8 e7 ~2 D, Y# B1 L/ Q( P4 |
  }
4 S- D6 S+ _) D% _$ ~" Q; v' m& m1 ?  opener.form1.frecname.value=val;
4 P8 g: g; W# S/ B3 p* m! [. M  self.close();
# x$ _; _; u: d( X; m}
8 C4 f* T/ N- V- h% B  n//-->' `+ t- e0 s0 B  n6 r8 G9 W5 o& \4 }
</script>
2 n( |/ @7 d( f1 g9 y$ w<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">& \% ~& |+ K! X& j
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />. l! B! M* Y+ s( z# a( r; I( I
<%' L6 s, ~5 M/ {* n: U2 Z% o
  cdatasource ds=new cdatasource();  //数据联结bean实例
0 _* d) Z. N. b" k6 F" \8 ?- }( C  java.sql.connection conn=ds.getconnection();
' j9 n- w& y" t0 W! f  java.sql.statement stmt=null;( W+ N  J9 Q" r% M; w/ Z5 d3 C( i! t
  java.sql.resultset rs=null;; X. W: B. P$ C( a! w2 j
  cdatacheck dc=new cdatacheck();1 P: V( R+ o- {( P1 D) z; W
%>, L- b6 _( B! t7 t0 Z4 S" @
<%7 Y! E3 C; {) P$ c' ~
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";% V+ O: ^' J, Q+ S  D7 Z4 C% H% g
stmt=conn.createstatement();
0 ~( P3 b" v% h! G. d! c7 frs=stmt.executequery(sqlu);9 i6 ~1 h3 ]* ?: \& I
%>
( [) M1 V6 G% y3 L. ?" k! z<script language='javascript'>1 ]' g* O) l( V6 t! n& g7 h
arr = new array();
2 `: }* _& c- p<%  int temp=0;+ t  Q$ ~/ O* s2 Z
while(rs.next())
+ b5 C/ }/ W# U. i) z7 q{0 f) b0 X2 ?5 n% ~
%>
  c$ h* U0 U* z7 X6 xarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
9 \: j. j9 ?& U+ E# o<%5 c$ ^: O4 v1 i3 I% c6 I
temp = temp + 1;
5 h& R. u; D: R3 r0 {$ S- z}
8 J- R- |2 v4 `6 a: S! m% }%>
, b" F- r+ E4 i! Q" \/ Vtemp=<%=temp%>;
: T$ X1 V. o/ b/ L  I# q: c2 Yfunction changelocation(id){ # J: Q/ k7 s+ e, y
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 2 i- p  i5 N$ k- m
var i = 0;
* I3 x! Z5 o* ~* W# pdocument.combo_box.city.options[0]=new option('-------',''); + i( M' E. g5 ~+ a/ G4 o0 {
for(i=0;i<temp;i++){
1 N* r3 o6 ?. E) ^1 {5 Jif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
3 h2 n% T0 ]: b+ f. |document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 5 ~6 G3 [% u6 m* |, Z4 Z) n$ N
} : _! P9 F: Z/ A# N+ D8 k! n
} / q  _! C% l  b7 S' ?- q
} # I4 \: a; Z; `7 X0 P
</script>6 \+ |7 j: n. F2 M) [* G1 b6 k3 `
+ Q$ ^/ a% {0 Z
<form name="combo_box">4 O) L% U% h, _& [3 g6 z6 v6 F. I; k( y
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
5 [2 }( z9 l, h2 f4 ?  <tr height="24">: c/ R, z5 Z& _9 h/ m" A/ E
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
. N; X) Z$ ?- g' ?5 t    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
6 L. _/ J4 y' F2 ]0 |1 [& M. [    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>1 o- r3 e7 R7 b- ?: ]
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>. H0 s! y0 P4 Q! [  p! {" g
  </tr>
' I! v8 b5 q7 c0 }" k! b% q; w3 Z  <tr> & T! a0 ], r8 O
    <td>
) q0 _9 @, ^- {7 W" R4 {  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">" j* A% H- [! W% Z& h
  <option value="0">请选择部门 ---></option>3 u7 z, n- A( P
<%
) j, }1 [; y; p6 P    string sqld="select * from tdept";+ L) A9 c5 k) x) }3 B: i/ x! l* ^2 U
stmt=conn.createstatement();
9 e% M3 z3 N1 i- @( W8 |rs=stmt.executequery(sqld);
) M. r- ]' w! Z* U# P0 bwhile(rs.next()). E6 o- `) a& ~9 D8 v& Z5 r) {7 R
{
$ M" g) p) x: d9 G( k%>' A1 j  V" a, e! z) B$ i
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
' m8 A3 R$ I; D& G4 G<%
5 ~" T$ H& Z, x$ H! m. M}# l. J" t+ H% p3 b7 N" y
%>
/ a! K2 d' {6 A5 p5 J! e- L* H( m  </select>
8 {( j% ?8 `% H- L</td>
/ x  g; i, H& {8 k    <td>1 V* a3 K9 b, ^& E
  <select multiple id=city style="width:150;height:200" class="bgc">
- ^/ j$ v! N% y% H5 u  </select>
# }8 T' I* E9 z* M2 y4 U</td>! u" X- i4 @- @* r3 g$ c: h
    <td nowrap align="center" class="bgc">0 q$ w2 H+ X$ @4 U% S0 @
  <input type="button"  value="<<" class="buttons">0 {/ D. z8 J7 b2 s  C; h, M
  <input type="button"  value=">>" class="buttons">* c+ S: S  u# B- s* ?9 B: a
</td>
7 [8 W4 |0 P" t8 y; x    <td>, B$ Z8 z& ~9 p5 P/ e0 E" j
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">' u3 U0 e% Z2 W: p" w
  </select>
( C* u$ t( {4 t. b- Z</td>
: ?; X9 z& B  Z% l  </tr>
9 ^* W" _* S# [    <tr class="bgc">
4 N. Z3 I* ?* b* P& ]7 E    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
. \5 w0 v9 J4 {8 c. N  </tr>
" j4 E' d- D+ l1 l4 d</table>) J1 @7 @! N/ |$ o( l. I
</form>
) k1 c9 q8 ~* b" X  N3 t<script language="javascript">
& ]5 X( f6 F1 O) [/ N; B2 r6 j//人名移动3 V& ]; v# l, R8 i7 S
function move(fbox, tbox) {& B) O% a3 ^% h8 i7 B8 u
var arrfbox = new array();" y1 v2 ]; u7 ~9 f
var arrtbox = new array();
  ?& j  Y0 ?1 ~: @  J! q) Jvar arrlookup = new array();8 J8 f& W0 |) ]* e; n3 M$ L# M- G
var i;" T% u; y3 s7 H# A5 {
for (i = 0; i < tbox.options.length; i++) {+ H/ d& i* w1 T$ ~" ]' D" U
arrlookup[tbox.options.text] = tbox.options.value;
* ~" _' p2 G5 x. }& `; s0 H0 Harrtbox = tbox.options.text;
% T# y$ |' d5 B' H2 V  h}. C7 ^& w6 W6 L; F* z9 E
var flength = 0;
' `( \& o: u; P) i5 u2 jvar tlength = arrtbox.length;
. E" L5 K5 b. U5 Y" L- E  E6 nfor(i = 0; i < fbox.options.length; i++) {) N5 B% p2 |8 Z: `2 ^+ V$ ^1 O
arrlookup[fbox.options.text] = fbox.options.value;
- K; B8 x- [1 u: \* a" }$ gif (fbox.options.selected && fbox.options.value != "") {  q! f! h1 U3 ]. V' y1 i: |
arrtbox[tlength] = fbox.options.text;
( m6 Q& a2 R; a- j! itlength++;
0 S2 F7 ^. i7 L( {8 U) e$ J. s}& G" F( V+ m: ?/ n5 U9 N
else {% o1 @9 K4 m/ d4 p) R6 q3 {, t
arrfbox[flength] = fbox.options.text;
  }3 B- u# ]$ p4 X! Gflength++;
* O9 q5 S* D# E! S9 l$ w   }3 @% m1 C! K3 D8 R* b# r$ f2 s
}
% y' c( a( \% @: v3 h: t3 Barrfbox.sort();7 w$ n% L/ `* B4 e
arrtbox.sort();
- A( I1 v% L7 W2 P# z
0 u0 c; v+ h- \fbox.length = 0;; ^  m: B: R1 a( h% V$ U
tbox.length = 0;: t3 `: ?$ X9 R1 j
var c;6 I0 ?$ D; E* B7 |- i
for(c = 0; c < arrfbox.length; c++) {
; c5 n3 ?3 Y% mvar no = new option();
' P/ S& V5 F+ M) U  Gno.value = arrlookup[arrfbox[c]];
8 l( B( z2 K( ~  d* f/ H9 y) Hno.text = arrfbox[c];
2 O! w7 i- j: l# L; G6 l2 kfbox[c] = no;
  W/ H) j4 U9 I6 h% v( ~}
2 a6 Q7 C$ s( U0 Ffor(c = 0; c < arrtbox.length; c++) {* i4 u7 A$ k  Y4 X! X0 O1 O
var no = new option();
! `2 l* ^% i7 bno.value = arrlookup[arrtbox[c]];
6 W8 j- C3 D: _8 Z2 h7 J4 K, _4 e7 Rno.text = arrtbox[c];
7 c6 W: m$ N/ W" T. R6 y8 ]tbox[c] = no;
/ i- Z" `) v1 |+ q% Q   }, C% V7 E# r& w6 v( s
}
0 G# c8 o& m, R, n1 V1 l: A</script>
$ J% D5 ~% C7 t+ C# F- L) `: l</body># X' O0 i! T, S

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