返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
+ L# s5 }+ ?- G3 f9 \& p         c pageencoding="gb2312"
+ d/ j( ?/ _3 C; d4 n3 y. S%>
$ g; J' _5 O) t% L  _, g<style>! j( c  U7 x" _& U
.f9{ font-size:9pt; }0 |3 Y1 z2 d6 i, O% [) o
.bgc{ background-color:#aecaf9; color: #0033ff }
1 ^; i  u1 H; z) ^4 `, ].buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;0 o/ f9 F: g0 W
  border-bottom: solid 1px #4e7dc1;
. `; y4 b) f. g: G) E  border-left: solid 1px #aecaf9;
% k+ C5 Q- u- ^& G6 _6 E) a  border-right: solid 1px #5679bd;
/ V9 V" S: k( Y6 M! s' L  padding:1px;  A; `2 q9 n2 J* a$ J6 |
  margin:0px;}: ~, T) T3 k& }7 X1 w4 f
</style>: |% a) u' {0 \, k  M
<script language="javascript">
, ~6 }/ _& ?/ r+ ?( n' O<!--; p( U. Z/ _. Q0 y# ]6 d" e
function rv()' A4 x3 a- q# n
{
/ s& E6 a- x( _5 ^% C" X( h  var val="";. n! ]- o4 q6 F! m, ]4 W, t
  for(i=0;i<combo_box.list2.length;i++){( D2 F! m0 E# Y5 S% U1 P$ x" q; y
   val+=","+combo_box.list2.value;
; N& G" \) S2 }) _: Y7 h" f) {+ z  }% |0 m; o! |* P9 x5 T6 n
  if(val.charat(0)==","){
+ F" D7 c3 B! j8 [2 E   val=val.substr(1,val.length);7 |/ {1 }) Z3 t% r4 q, U
  }
1 S4 w$ @  {0 E7 i: v. c  opener.form1.frecname.value=val;
& s( \! [4 ]( G, T. e1 y7 |1 w  self.close();& p2 p# M; w' D4 N
}
) s& e! l  m! X2 Y: o//-->( [. I# h) V+ r( U6 q; C
</script>! S% D) D* m( Q* P5 n
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">5 _8 L5 v& V* ]+ c
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />9 o' y' E, t  t- ~. A9 R2 ~4 ~
<%# e4 O, e: {9 r/ X& l4 y; G
  cdatasource ds=new cdatasource();  //数据联结bean实例
& U" O$ k& P- L. M) b  java.sql.connection conn=ds.getconnection();
3 t# h9 u: h; T. G$ k. {  java.sql.statement stmt=null;/ `  A' E* |3 I! b* i) q, A
  java.sql.resultset rs=null;
/ I* \2 ~; A! O/ S% E# v" s& q  cdatacheck dc=new cdatacheck();
& \, Z6 |5 O4 {5 o% L7 ^3 l* Z' \: C% I%>
1 N0 G  R2 ~6 x8 F4 c8 X/ n* [9 i<%
; p& \) b, I; Rstring 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 E0 G. A* T3 X% x+ M
stmt=conn.createstatement();
; q8 G+ s2 |5 v0 O* d6 T2 Urs=stmt.executequery(sqlu);
8 p! F- D/ t0 ?( |%>
) V: p8 z6 y7 W<script language='javascript'>( B0 R  L# ]3 a8 ]9 O* k
arr = new array();1 D+ S% _7 P2 V% F
<%  int temp=0;
1 R( J1 s; T( e5 |: w9 _while(rs.next())  P$ K  ~. s7 h( `9 j6 A  f
{
- E1 h# e* [/ X" M%>3 f) c, L: z% t4 W* W0 {2 H1 Y$ ~
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
5 }, w. o' U. |0 s) ~<%8 V, H# T4 r& n1 V7 V* c2 d, J: X
temp = temp + 1;
) r9 [: u. \. m  d, o}  c, p- V9 ~5 A( u/ A8 K( Y
%>
8 ]0 M) @) \- {temp=<%=temp%>;
) o6 y3 N, X: c/ S3 @- cfunction changelocation(id){
* l# ?! K5 m4 {. T- \; O3 U( l% U- gdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 & @  K, y+ U$ p# U  _
var i = 0; 1 P5 f$ Y% ]2 l0 T, T2 Q8 h. N7 |0 A
document.combo_box.city.options[0]=new option('-------','');
! a# ^; E8 m: H) g+ K) |$ Ufor(i=0;i<temp;i++){
8 o# x) l4 K" s8 Z. w6 V6 b/ t' q1 cif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] % _, _$ s! _2 H* H& r, k/ l# l+ {
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
6 @- p0 g. K% R6 z} + B! p8 f* ^$ U( O9 `0 [4 N# |
} 7 q/ i3 L- z0 C& O; M
}
# D& F( l! S8 ~  I4 G$ w</script>
9 W& u  T- I8 l& f
$ I1 w% M; `' c<form name="combo_box">
% W) d$ Z# U3 u; C<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">( |/ L& A# B/ N
  <tr height="24">
; N- R: {+ i, p- e" i* U2 ]    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>. Q: N* R" @8 D7 o% g
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>) D6 N* i. C2 z% H4 Z! q* U
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>2 b- E7 I' n' [" X7 z# [. E
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>1 ^3 m# X. @8 w% [. Q+ i
  </tr>
" _/ v7 S5 D! B3 ]/ C& i  <tr> ; ]  C5 R! \0 ?) ^
    <td>, W2 ]) Z1 t! ~) F/ t
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">% y) A  L4 O" ~& s4 z# b$ G, i
  <option value="0">请选择部门 ---></option>
, l) J3 T+ r+ Z( q<%
! \/ b9 @% z& @1 B- i/ i    string sqld="select * from tdept";
. D  h  z9 i& A4 U; gstmt=conn.createstatement();) P9 K- k" q' `1 ^
rs=stmt.executequery(sqld);
7 c( E- P0 _6 p( M; kwhile(rs.next())9 o3 `5 V4 u: H) ~( \0 W
{+ w: R: I2 B! {- V2 W
%>/ p1 @% }1 U8 u- Y
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
' [) j7 _- s2 d. S# V' J/ y<%
8 B/ \+ O& U" f; d, x}
; w( E/ s9 k4 e# b4 i( r( Y, Z/ @3 s%> " a8 i8 ]8 e; ]0 ^8 J( `
  </select>( F/ j, f2 {5 T0 k0 y. k! k
</td>
! ]- L3 w2 K9 [2 R    <td>* h: f* O) V- Q* i& Y, Z7 ]$ s" y
  <select multiple id=city style="width:150;height:200" class="bgc">9 b1 e0 U+ @' W/ `, ~/ K+ W
  </select>/ k( o8 s8 _4 |$ y& V' Q4 m
</td>1 O; D: `, K1 l" S
    <td nowrap align="center" class="bgc">; f+ n* G& v) [2 F8 f2 D
  <input type="button"  value="<<" class="buttons">- R/ |2 K" Z+ o0 m  O5 c
  <input type="button"  value=">>" class="buttons">4 Q2 M4 d( M) I1 U
</td>4 g2 W8 Y3 E% W6 ~: w' k) }" z
    <td>& S9 @0 S0 ~" R) J6 e9 M" j+ \( V8 _; g5 C* k
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">; w. |7 N6 j9 v
  </select>
- ]' a. C. g3 x% s; d& |4 }</td>
2 }5 \: w* w+ G* |8 _, |7 k9 r  </tr>' T: J6 i  ]4 z/ L. e. K' }$ C
    <tr class="bgc"> 3 ?' t. E9 D$ m: d5 e4 O8 D& n
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>: \9 x( f, m# M
  </tr>& M8 J. V/ w* X1 ?2 ]( J, N
</table>; u. Q/ \: w0 d2 B( @# h3 K
</form>; B4 @  Y& y6 t
<script language="javascript">
& d0 u0 @4 \% F# J& s  h//人名移动
8 g! u2 N: R4 i8 S3 o  Jfunction move(fbox, tbox) {7 j; k0 S, a( M' |- x4 z  r9 ^
var arrfbox = new array();( [% X8 Z# A5 w
var arrtbox = new array();
: E6 [3 G: e6 ^/ F) \, ^$ p4 ]7 wvar arrlookup = new array();) i6 [1 I5 ]! C- f
var i;$ r# {. n4 g9 S! r
for (i = 0; i < tbox.options.length; i++) {5 E# F4 y; h* j  d
arrlookup[tbox.options.text] = tbox.options.value;
) I; a0 n7 ^# S" ^arrtbox = tbox.options.text;
5 d. C, ~3 n7 D+ f/ }% m2 Z}* h) b' C8 I/ [( C4 ]( d
var flength = 0;
- U, f& I$ U! I7 s/ Wvar tlength = arrtbox.length;  @" ~# b4 a) g9 h7 Y
for(i = 0; i < fbox.options.length; i++) {
- `" M& q% N0 y# P: p* karrlookup[fbox.options.text] = fbox.options.value;
# I; ]1 a) ^# {: Oif (fbox.options.selected && fbox.options.value != "") {, G- H6 b0 |0 e/ l" K% X
arrtbox[tlength] = fbox.options.text;
& {* Z8 J$ K* K7 Q# jtlength++;: F6 `' V- Q1 U7 h6 i/ Q& p
}
/ g; p) d" i; X# a. b3 X( h5 |else {
1 u# r; o  e, l$ Aarrfbox[flength] = fbox.options.text;
$ w, k$ b- B4 Q: j! x+ mflength++;' C8 w. S' Z2 X  t- V
   }
* p, R3 N9 Z( G, ^' p. v6 F; ?}6 [3 k, H  d5 n/ g$ n* ~$ J2 C7 E
arrfbox.sort();6 W6 C9 m* O+ t% m# P
arrtbox.sort();
( G# w: y( t9 H, K5 r0 J8 y7 t/ p" w4 N
fbox.length = 0;
, Z) ~$ B9 ?. O% \' h. e9 R1 ztbox.length = 0;
( I* ?; \3 ~! w+ K1 c& x; [, y# K, vvar c;) [" p/ _  d  i* {; A
for(c = 0; c < arrfbox.length; c++) {
2 f! F! C7 O, jvar no = new option();" ]6 o( V1 M5 ~/ Q' M
no.value = arrlookup[arrfbox[c]];
3 h& Q+ J: y' \8 Tno.text = arrfbox[c];/ }) h2 n0 c6 C0 H1 F( @
fbox[c] = no;
8 c' J- W. I6 t5 y6 J) F  L  e}9 S2 i0 d6 f* W8 Z+ y( K: B. `
for(c = 0; c < arrtbox.length; c++) {9 o' ]: V) [9 d5 y4 J. ?6 N2 s
var no = new option();
0 P, D9 w8 i  M- [1 ~no.value = arrlookup[arrtbox[c]];. ?* H* u$ M: H! e% W( C# F' ~7 r1 A
no.text = arrtbox[c];( ^$ S  A+ T# J& I' p2 z" @
tbox[c] = no;
# G4 K* A* _# |5 Y) ~   }, y$ B0 o1 q, p" n' _
}
+ |% A- }& j/ W</script>
, I- s4 h" w1 K5 B</body>
1 x8 M, H* D  `" I

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