返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"; o/ _) L9 q$ f) ~+ \. L
         c pageencoding="gb2312"
# b' W% i9 X% f5 o%>$ v$ B3 G* O7 z, q- d; e
<style>
& Z, {5 @$ A) J  h4 K.f9{ font-size:9pt; }
1 y4 I7 W! Y; c. U+ R) |.bgc{ background-color:#aecaf9; color: #0033ff }; e" V8 }& W2 g1 ~$ Q! U! V% ?
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
4 r$ D: w, Q' u8 J  border-bottom: solid 1px #4e7dc1;
7 F0 w& x% `1 l4 D  border-left: solid 1px #aecaf9;4 D+ ]7 h" ^  G/ p5 i1 a' o8 K
  border-right: solid 1px #5679bd;' R; x6 W  n% L$ V
  padding:1px;# P6 \1 L9 A* B8 q' C. ^! X; v: u8 |
  margin:0px;}1 M; J& P& V# K* E) Z+ e
</style>2 e- t2 J( \0 T# J
<script language="javascript">: ^/ m' I/ N0 @6 P
<!--7 S8 k. M  A! t% E' ~0 I
function rv()
- O4 u% w" d/ q7 x  c{
/ w$ k/ M; E, e$ y) Z  var val="";" }, M+ J  U: K3 N) r/ `5 @
  for(i=0;i<combo_box.list2.length;i++){! k* x$ l: p: t/ y2 b% \% b2 f
   val+=","+combo_box.list2.value;
) p* }" E5 G- m; W- h( X/ F- n  _  }  u6 t" a* w" L* t  m, {  Q
  if(val.charat(0)==","){1 W! Z6 j7 k- R+ Q3 r
   val=val.substr(1,val.length);5 k; ~0 X( ]! d6 u0 z& q3 g' @
  }7 ^. {: M: i0 g$ u* [; [, [
  opener.form1.frecname.value=val;
: l7 p2 o- }$ f$ ?' p" c1 k$ R  self.close();- `4 t  K* R! R. N! g% Y
}
) }3 R: d; g- K//-->' g, R$ m  f9 F! V
</script>8 j4 Z- s+ g" C) Q- h& S; u
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
2 b' y! b* b. u2 A<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
& t3 {. U5 J. {<%
) p% w, r' t( O# o( e  cdatasource ds=new cdatasource();  //数据联结bean实例  I- j' j: @/ L6 E3 h3 O
  java.sql.connection conn=ds.getconnection();, N6 a0 [0 o& Z
  java.sql.statement stmt=null;
8 g8 A' _3 ?. H2 y- \  java.sql.resultset rs=null;
, n+ @# ]4 g3 d! i! j3 C( J- S- B1 ]! Z  cdatacheck dc=new cdatacheck();' V/ N) J" e1 m8 w
%>
7 @  z. Z* c+ q5 [  ^- D2 G<%: d/ l" @4 d; u) n/ S
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";
( D0 `1 s- q0 R1 o( J2 H; lstmt=conn.createstatement();
1 u* E4 j/ n- }% Grs=stmt.executequery(sqlu);
3 D% v/ D0 g) T7 M" @$ w- y! i8 L" b%>( L9 @3 R9 a2 W& o$ D
<script language='javascript'>
$ s, ~5 q. n% Q' P, _arr = new array();' M+ w1 Z; V0 s, N4 ]/ o- }  E
<%  int temp=0;; x( |5 D7 u" s& D3 l) I, P' C
while(rs.next())
" P" ]  ?# I/ S( v  J+ j2 e{
1 |; z5 o  H1 ]9 t6 V%>
+ e3 _( e- c/ R. n) z7 W$ Y0 M$ Qarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");! o9 R0 q& x1 `2 K  `
<%, ^, v! |) ~- N- O3 S  Q, m
temp = temp + 1;
- k6 I; f/ a0 o! O- H$ w9 r; h}0 T* H7 r  [( i
%>6 f3 g9 u- v; h0 B; c
temp=<%=temp%>;
0 H/ p/ L4 |5 w9 e! Ifunction changelocation(id){
; k' h6 ?  S$ p' [6 h/ `document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
( I0 ]( J% N/ o( }5 J, xvar i = 0;
& W$ G' h7 c# c2 T6 zdocument.combo_box.city.options[0]=new option('-------','');
& E3 B+ ^% W' A2 wfor(i=0;i<temp;i++){ 9 X6 M) S: {& ?& r/ F
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] ; A' B. W% I" X# x2 B$ s5 e# R! y( o& [
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 8 a! c% t; N  @7 z
}
. E0 A: p) d4 P+ \2 t}
5 l8 C! ]; m2 E} % S' I; `7 v: a# D
</script>
, z% P# U" s. {/ a) J6 v: a+ m2 y% R- b. t: d  H" |2 i
<form name="combo_box">0 H; z0 Y, v  o8 J* E$ O0 N- \: ?4 R
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">4 W5 @% p8 }. Y. E6 ~
  <tr height="24">7 g) e0 ]3 f. l4 r* W; Y
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>- a* k( N9 }  z* X
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>, z, W" d6 ], v1 q
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
- g% `. V1 r; a  e: O7 B* K    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
1 A7 t3 Q( v% D. t  </tr>
& y% _7 f5 `+ a1 [; \+ f  <tr> 4 ]: ?, p' p' y4 x/ g
    <td>2 A3 ^9 K8 n% C+ K
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">- h% `8 f5 F! m# H8 x- |
  <option value="0">请选择部门 ---></option>
' R* H$ a& o8 t% ?5 J: y<%
* ~: Q! W6 C4 X: X    string sqld="select * from tdept";+ N5 A  P0 P* ~5 ?5 J! \
stmt=conn.createstatement();
4 q& S  t0 M. \rs=stmt.executequery(sqld);
7 k1 F/ [9 ^* ]( ^' j7 P8 J9 ewhile(rs.next())5 p0 I6 \7 d9 N7 p+ |/ w4 O
{. b2 h: w2 \) w6 u7 u; t7 W. @
%>
* o& n" S; s% e' J7 J  W  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>6 E$ W# T( S, E2 Y$ H6 _. f
<%
+ J9 b2 x3 h3 j9 L7 j}3 w$ H. T8 v; E% ?! [/ n
%> 6 t& j8 y  W9 `) s3 H% g# x- M
  </select>
, M: C! U7 s2 z- ~. h& t- t</td>
: r; U' z' R; e1 p, b    <td>
% M: w" Y& G- h  <select multiple id=city style="width:150;height:200" class="bgc">! o/ R6 E" m. P% [7 h1 K: v
  </select>
# k$ z/ N4 W$ ]! C; ~% S" A+ [</td>
7 P9 [& Y9 ?8 U    <td nowrap align="center" class="bgc">  Z7 E) ]8 f: z. ]* S# j$ Z
  <input type="button"  value="<<" class="buttons">/ x. S2 d) M7 Q
  <input type="button"  value=">>" class="buttons">
7 W  [/ R+ a+ _! \9 S+ L; W, B</td>  }* \# W' F6 J- y
    <td>+ Z$ Z# C8 \2 U1 _0 w
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
( D- E& ?" I: k! k/ u  </select>
9 E2 m. b3 R; ]$ r& S* Y</td>
  U" b5 H7 u# v# B, |- m! P2 F  </tr>
3 t8 o8 K2 T1 c% R; l4 O    <tr class="bgc">
) j( Q2 r' ]% U    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>5 D! S; K  e+ @( r& X4 Y
  </tr>
! w3 x  q. ^+ f2 l( ^</table>
- I% ~" [% O9 D% p2 n</form>
% I1 I" P$ u  k& ~" o  D. H<script language="javascript">4 J8 W" \- l# t& [/ a) B2 r2 z+ v
//人名移动
! y( F$ N9 O( `% V' _function move(fbox, tbox) {" [' s) ^' q6 B( M: M2 W* ~1 o
var arrfbox = new array();( B5 S  [8 d, B; V; ]
var arrtbox = new array();
' ]% R0 O) F3 _$ kvar arrlookup = new array();' ?1 H8 W8 ]# n+ G3 |4 R
var i;- n" Y8 T9 }3 l5 _- ~- ]
for (i = 0; i < tbox.options.length; i++) {" J/ s& o$ y* u4 p7 v
arrlookup[tbox.options.text] = tbox.options.value;2 n" @( G6 C  G, |* \% `/ v
arrtbox = tbox.options.text;
% P+ ?& t* ~% a+ D# j& |}+ M  D3 y2 c8 r& Z4 m# Y
var flength = 0;" v* Q1 {; o  f
var tlength = arrtbox.length;
, t3 F. C" ]" ]! r$ B4 |% h# ?for(i = 0; i < fbox.options.length; i++) {% s& g6 U2 D/ X! P& ^& i* |
arrlookup[fbox.options.text] = fbox.options.value;2 D; `8 u( C0 \
if (fbox.options.selected && fbox.options.value != "") {
; S% P. s& u2 c3 C4 iarrtbox[tlength] = fbox.options.text;
0 I- D/ r4 m' t5 Htlength++;
+ Y( t! J( h) x' H1 W% F}
2 _  k9 n+ T1 Melse {
# J3 H& E  P5 @, ]  Karrfbox[flength] = fbox.options.text;5 O9 T. a3 T8 F  b& l6 L# x
flength++;
2 g5 z: `% j! i. _   }
) J/ y8 m$ A* u4 |; k" u}# J  l2 ?* N/ G9 u
arrfbox.sort();8 y4 H& d5 y4 n  B
arrtbox.sort();8 p, Y2 [3 ~. ?: j
& G- @$ L9 k9 u5 I) y3 G
fbox.length = 0;! |4 D8 q3 q- A5 }/ D, ~4 Q
tbox.length = 0;
; @5 R: K$ H+ A5 b8 @6 Ivar c;
# d+ h  W2 M: v  k5 Xfor(c = 0; c < arrfbox.length; c++) {
+ Q5 U/ n' Q4 B" P, r1 G! yvar no = new option();
( ]9 W* m8 S8 @$ ]3 Bno.value = arrlookup[arrfbox[c]];2 G$ |' q: m# T6 ]* f
no.text = arrfbox[c];3 M0 K8 q' }1 n& x" t
fbox[c] = no;2 Q9 }9 N9 t( Z  ^% {3 r; x! Z9 [
}
6 }6 I( |8 n7 ^& O3 jfor(c = 0; c < arrtbox.length; c++) {
, @* u! [* o8 {1 @5 q; o( Jvar no = new option();
/ v7 K3 i& ]# \9 j  nno.value = arrlookup[arrtbox[c]];
/ H* ~7 {, Z# _' j3 rno.text = arrtbox[c];# K/ x- y% B2 _1 N1 X6 i' H
tbox[c] = no;  K& L8 }. S. ^* `
   }. s5 G$ X( C" i$ Q) `0 }8 d0 U8 t
}- f8 W3 h( y4 o5 X
</script>
" T9 N5 J$ f7 O' R</body>
. M, w2 L5 `1 Q9 P- q3 U

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