Board logo

标题: jsp+javascript打造级连菜单 [打印本页]

作者: admin    时间: 2007-12-5 17:43     标题: jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"$ ^& N9 q" O+ |% t+ k6 E9 x
         c pageencoding="gb2312"! ?# W" j* f9 K$ S7 j
%>- Y5 Q5 U7 J6 t. D4 W6 @
<style>+ T* n7 v" c6 N& Q+ f! C
.f9{ font-size:9pt; }1 S3 j3 i8 F) c" s2 A0 w) U' ]4 w& P8 ?
.bgc{ background-color:#aecaf9; color: #0033ff }
, O& V' r# F; l1 l' s1 s" g% L.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;7 h: ^( ^; z& I
  border-bottom: solid 1px #4e7dc1;
* `4 j( R+ y/ q4 r* |5 X  border-left: solid 1px #aecaf9;6 ~1 A0 b) X; r/ x
  border-right: solid 1px #5679bd;3 d1 P" \( z) }2 |, B
  padding:1px;. @3 ^& q* }, g# q% ]/ A
  margin:0px;}
& B) f8 o! D2 H. A+ h% ]) Y</style>' N+ v! ~2 l: b6 z2 t4 v- F. Z* `
<script language="javascript">9 U" K2 X* W9 [4 y( V4 |1 U
<!--+ D7 m2 m* E; H9 b3 p, k
function rv()' Z$ [0 Q2 W5 V; C2 a
{
2 Y7 n9 {  [% x3 @  var val="";4 I, E% N0 I3 m# `+ f# d3 C
  for(i=0;i<combo_box.list2.length;i++){8 P  k, N# g# t3 e  z  ~5 J
   val+=","+combo_box.list2.value;8 i9 H# D6 R5 M0 s) g, q5 ^0 E
  }
1 }7 {' `  Q. X  if(val.charat(0)==","){" _; U+ V4 b5 P4 h2 J2 ?5 S3 S
   val=val.substr(1,val.length);  ^' r. J6 r# _( C1 Q6 o
  }2 w2 H, E* K- `# E, U! o- @7 @
  opener.form1.frecname.value=val;9 @: G; D  P1 R1 [3 w
  self.close();
3 R8 S9 d* t$ R3 |! b& _: v& K}# D+ O5 m6 T8 e( `: x
//-->
7 k1 S( l: \4 y' H8 u+ _</script>+ S8 U$ A( l1 v: M! y) I
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">9 n# s9 |4 B2 K7 W
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />" X1 \8 d$ @( j
<%
7 R6 v# ?" ~; ?' m  cdatasource ds=new cdatasource();  //数据联结bean实例
& Q3 C4 g& x, a' j3 L; z- L  java.sql.connection conn=ds.getconnection();6 n: ?& a+ P+ ~  ^: i( V3 x; ?2 B
  java.sql.statement stmt=null;5 A; d) v, g) y+ Z6 ?) F4 x
  java.sql.resultset rs=null;
/ c1 c( ~3 k* x  k- ^  cdatacheck dc=new cdatacheck();9 }/ H9 @5 U8 O: x
%>
2 h% A# j; m3 I<%* {+ d) y  D$ T
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";. @. [7 F3 P1 C- D5 G4 Y
stmt=conn.createstatement();5 {" K3 D5 H& s5 B) m
rs=stmt.executequery(sqlu);
+ D( j5 H( x% [%>
7 E' M8 d7 h# y* |) K1 B# n* ]6 u<script language='javascript'>) R( N, T  J  D  J0 i5 F' o
arr = new array();
" F- i4 U: q! g' m! c: k% _<%  int temp=0;/ u/ t" w( D: M0 [( M/ ?" q( C$ q
while(rs.next())% a2 \- I5 R6 K2 p: {1 W+ D
{
/ q. I6 u, W) V$ Y%>
) u7 G7 `6 c. b" Barr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
( H; Y4 M" u, d* A+ V<%; t- v- v! W" t3 T, Y
temp = temp + 1;- }7 @: d: x' j
}
( [8 ], U% P  A) c%>
' ^' B5 n; M0 ]- S2 h( I2 Utemp=<%=temp%>;; D3 P1 ~0 `& i* y0 c+ O- @
function changelocation(id){
( b  m( E1 _8 U/ odocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 2 M4 Q/ b2 G# y' ]% C  r( _. F
var i = 0; : i" o2 y9 u: [) J0 ^* U
document.combo_box.city.options[0]=new option('-------','');
, }8 f) n. A! F1 w4 w- Hfor(i=0;i<temp;i++){
% \/ I! H& t  {. i: p- e. dif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
" x: E( j1 `8 L' z2 Q/ kdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
7 w/ |9 O0 C0 [$ B3 w# S}
- J  X+ X) y  L, Y: ^2 d4 V}
% p) U; |6 h, H# J} 0 O6 a2 F3 @% V
</script>) |5 ?9 {. ~2 N0 @" Y
2 x: J" f1 _: t1 U6 i
<form name="combo_box">
6 T( _; ]# a8 R' B6 T<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
+ l) ?4 i: `: N& ?1 a- x  <tr height="24">- R. {8 \' C" [8 k* [; {: O; K/ R
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>/ d$ w# N3 o% G) K% D/ P
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>  [$ e" x2 D6 {
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>$ B$ d, X, `7 Q% F
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
; i4 D. g& Z5 \% z3 `: B1 d  </tr>  a: a0 J- D; h  N& m" F+ u
  <tr>
- x& O& S0 E) p7 [    <td>* r; w7 ]* Z2 ?* t/ y6 j
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
, H. J% t" J9 i6 ?7 e  <option value="0">请选择部门 ---></option>7 |9 _/ E3 m- {7 o) g; L
<%/ C& F  x  o9 F' o; X0 p1 L' O$ F' I
    string sqld="select * from tdept";
0 |/ Z" M. U' j. c% cstmt=conn.createstatement();* k8 s3 ?4 a- Q8 M) b. \
rs=stmt.executequery(sqld);2 W$ o- ~/ O0 e7 x
while(rs.next())
1 c, x+ c! c3 W" Y. u0 I) u{, u: w" u/ j8 |; ~+ |
%>9 e* m+ e5 q# E
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>! X2 B( }& E& X% w. F- k
<%
1 `& m/ x& G0 g; J/ T}
- H; v% K3 F2 E5 G+ \; b1 {. A%> % L, A8 ?, k, ^. V8 u
  </select>
+ ?1 g, E9 u9 ~5 ~0 U# b</td>6 b0 {3 p8 a; i2 y+ x: E$ y
    <td>% M9 e! W9 U' z+ L: X
  <select multiple id=city style="width:150;height:200" class="bgc">) ^  a+ e6 y4 w
  </select>
6 K- ~3 K6 ^# o$ e- }) m( W' O5 w</td>  T5 T. J( Q; j- u! I+ Z
    <td nowrap align="center" class="bgc">- F  }# C1 s# B, b% J, X% c
  <input type="button"  value="<<" class="buttons">1 l, C2 L. s6 R
  <input type="button"  value=">>" class="buttons">; z  w' @1 q- ?2 H: j$ s
</td>
2 R( C# F' u- u5 U) t. k2 O    <td>" X# G. }# w6 v4 t
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
6 r( x' P( W6 d  </select>
# J! u. i4 D5 V6 j2 V+ @, i</td>- i5 t7 U- ?, \# M+ W: Q  l% D* O
  </tr>
$ @$ C$ x5 h6 }2 Q0 O' A- ~    <tr class="bgc"> ; Q( @$ S/ M! j% b1 q2 K* Z' R! g
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>5 g! C1 H4 o5 H% C. A. D
  </tr>
8 R, ]- b" n6 q& i1 ]3 n0 o/ ?</table>
; a' c8 r* g$ X8 x</form>
. L( r/ Y& Z; O$ d# Q<script language="javascript">
6 J& l8 J* N9 ]6 f) {" v  P  O5 N& {) X//人名移动
+ d: j" W6 y* c. `" Wfunction move(fbox, tbox) {, R. m' F0 A  C% p( I# X: i: ~0 Z& [
var arrfbox = new array();
! N# h  C$ j3 t- _% R1 Jvar arrtbox = new array();
) I5 B% {1 p$ \- S8 R6 i4 t$ R( mvar arrlookup = new array();
- w3 Y( S+ D, }var i;& n: r) k, m" h% Y
for (i = 0; i < tbox.options.length; i++) {
8 \+ |$ P3 V5 {% uarrlookup[tbox.options.text] = tbox.options.value;8 }. _( K. ]# C
arrtbox = tbox.options.text;2 r$ `4 L2 K/ u& w1 q
}
# M) N. S! ~( j) |: v- D5 D7 P1 tvar flength = 0;
5 }  A: y- R7 _5 y4 k* qvar tlength = arrtbox.length;" V  a9 k6 B% k8 e
for(i = 0; i < fbox.options.length; i++) {
6 G" k$ h! H8 Yarrlookup[fbox.options.text] = fbox.options.value;
. d, F; {, M2 h% H2 U- _1 [7 [if (fbox.options.selected && fbox.options.value != "") {
3 A. R# i+ Z3 marrtbox[tlength] = fbox.options.text;
2 [# E2 A9 b3 i4 Itlength++;: A/ h) y, j& k) d
}
/ d" G2 o" W4 w, `3 i9 E1 Lelse {/ e& m3 k2 A$ d+ A( ]
arrfbox[flength] = fbox.options.text;  D7 A2 z" P7 r$ ^
flength++;2 T8 D% m7 O! W, r: z# o7 F
   }1 Y) Y! A3 m/ ]' J  b$ t/ @( p$ Z
}
4 o: H& Y" T# f8 Uarrfbox.sort();
( D6 N3 d$ z! {* W6 c9 rarrtbox.sort();
9 S4 t4 ]2 M; C1 Z4 @
/ P' E, N5 O+ _6 Kfbox.length = 0;  D* b" t- e" U) a- Z
tbox.length = 0;
/ M. N7 \& \- n4 K( Zvar c;
4 z- r3 U) ?1 W( S& Q7 K8 e2 Ofor(c = 0; c < arrfbox.length; c++) {& z# n, V; G6 [3 Z9 \
var no = new option();
9 H6 U  J1 `' _: \# C: K7 D( v  s- vno.value = arrlookup[arrfbox[c]];# r8 j7 `) A( g
no.text = arrfbox[c];
" q1 v, ~5 h& Yfbox[c] = no;0 T# x% i. a/ f3 U( R
}# o& X! ~7 d; E- m2 C6 T/ w/ Z
for(c = 0; c < arrtbox.length; c++) {% d5 e! z' g. \  g0 r: E+ \
var no = new option();
7 r% q- J/ H  ^/ uno.value = arrlookup[arrtbox[c]];. [6 c: v; p' G' G9 a
no.text = arrtbox[c];
+ k3 C" S1 o5 B  S1 btbox[c] = no;! M& {# C0 m5 [1 E& d  K" T
   }
. y1 {$ Q+ Z7 l3 _}# a7 q( f2 X+ S
</script>' P6 ]) g9 F6 X4 b
</body>
; y" J$ ~$ H( W  y- R





欢迎光临 捌玖网络工作室 (http://89w.org/) Powered by Discuz! 7.2