Board logo

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

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

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;": g% K, l6 ~2 ^8 _4 d
         c pageencoding="gb2312"" ]% J& h" U7 P3 }- U' Y# F
%>
) p+ \9 i& c/ ~/ f% F' H<style>
* m; G) o- s0 V6 {# z; q$ C3 E$ F4 r.f9{ font-size:9pt; }. f1 ^; N9 q* u% E+ M
.bgc{ background-color:#aecaf9; color: #0033ff }
# ^& U* G& m- X0 v& w$ p" E) B4 p.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
9 p6 H( n  M( o) j  border-bottom: solid 1px #4e7dc1;4 N4 I) `* u3 z" w
  border-left: solid 1px #aecaf9;
8 A$ J6 }, {; I: q* l# V8 |  border-right: solid 1px #5679bd;. c2 o* C3 c5 p; R* P
  padding:1px;
2 N9 k3 k- W6 H) D6 v! k* a+ e, g  margin:0px;}0 s% v- W# Z% i2 ~
</style># q% V* I' }& e( Y3 C2 q
<script language="javascript">
0 a6 ]" m5 I- h' }* k<!--
) M& L  y  C0 H+ z' n. b0 gfunction rv()
! |& m* N- M% y  n% C; L3 C( o{2 p; r3 p. ~; U6 q& b
  var val="";/ ?( g( ]! r" D. Y1 K. |: ~
  for(i=0;i<combo_box.list2.length;i++){0 [- s: ]8 ]2 M: [6 t' ]7 T
   val+=","+combo_box.list2.value;4 I3 d* G* [7 V8 `, A6 C6 [* z
  }1 B: j7 i6 }; ?4 g8 Y! `0 m
  if(val.charat(0)==","){4 |) s5 w$ B( N9 I8 b
   val=val.substr(1,val.length);7 J4 n& D9 j! k
  }
- ?  x. d& T, z* y1 [2 @( d  opener.form1.frecname.value=val;
5 i9 m0 S* w% n3 r( G1 ^  self.close();2 u" Z3 u1 o  F$ N+ h
}
* k4 o' _  a6 }6 ^' Y//-->5 g* |) o/ x5 @1 L6 s+ v  f
</script>
1 z1 O$ ]0 m2 ?3 O<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">0 @' K' l8 G1 i/ i; l
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
9 ?+ D$ c) B3 o2 {  |" ^<%
# T0 J6 _( F4 z  cdatasource ds=new cdatasource();  //数据联结bean实例# V( z. }' T  Z; u, u0 _
  java.sql.connection conn=ds.getconnection();' f6 `4 q2 \" q# w( x1 v5 @
  java.sql.statement stmt=null;; S1 ?9 r  E* G# w1 k9 v
  java.sql.resultset rs=null;% D/ A  Y2 D& _6 X
  cdatacheck dc=new cdatacheck();
# T8 Q( j4 l2 u% r%>
" n+ y( C0 D+ S" S8 @$ H<%. i5 Z2 q. r- m# ~% Z4 m# F
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";& f1 h: B3 f' O( I) s% |6 O, o
stmt=conn.createstatement();
! e3 W6 f% Q7 }" krs=stmt.executequery(sqlu);
/ |5 `1 f* s6 s4 [/ s, C4 o%>- r8 \: c& m! a
<script language='javascript'>
1 ]' M- z2 C* p6 i: J0 n9 W: Sarr = new array();/ l, _, n) Q' x; s) q
<%  int temp=0;
5 g6 @! p# K" \3 V( Vwhile(rs.next())
0 A) M% k2 `* {9 I6 i  b{
! P7 R, f" ?# f  `- D%>
8 p$ e+ t5 c; }, |arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
- E& v1 s- K# N5 _3 @' n<%
. A9 }- h: ?& R( Q0 ~6 p" jtemp = temp + 1;( @1 m* k  S2 {; O! _% X
}* t( Y7 ^/ [! b9 ]5 L# T  l5 N9 v* D
%>
3 O% e: I% H) I+ j  S/ Ltemp=<%=temp%>;- d" I4 h' M+ C: G- w
function changelocation(id){ & K5 p  S* `7 y4 ^2 l/ M2 r
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 - Y4 h) T5 D+ W6 l7 }
var i = 0;
" ?& u. p+ j  z* }4 t9 |& \. ]" sdocument.combo_box.city.options[0]=new option('-------','');
& H) Y% b$ P0 Z, ^for(i=0;i<temp;i++){
; G+ l4 u. V, n5 B/ T, fif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
5 a  w5 ]# t) R0 @; \  a7 {" Y4 Y: fdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); . o6 h$ ?. ?7 c0 o
} " k7 m/ e# p; m- }& \$ I5 s
}
' L/ |5 p! V1 Q  L0 p}
1 Y0 K, L' X- f0 L% i: I: G( J+ B</script>
' e, v- b: O. R9 o. {9 N; c) J- g
1 o5 g& j5 ~. g/ w" T<form name="combo_box">* `" g  N% v6 t$ p
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">' m! q- ^; P( y: c' g0 v
  <tr height="24">( j& z' u: i; L4 r# Q9 g# N
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>) T# N' U  u* a' D$ X
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td># ^* O% H: c& M3 P7 l2 o% W3 H  `8 t$ b
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
1 {# M3 ^* }, _" s. F8 y1 c, _    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>: D/ K/ b7 E6 p$ r5 n6 t
  </tr>! }0 v/ a4 q! u; z
  <tr> + R& {) W/ p* x( p, o1 b# V
    <td>7 q" o& J6 F+ X5 Y6 q( i* X! U
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
: j' Z1 ^  |  `4 I- E  <option value="0">请选择部门 ---></option>7 |# w7 A& ?) ^! {& f( x1 n
<%; G0 C( `: S. o6 s# D
    string sqld="select * from tdept";' W1 i" H4 A3 F* t+ V. H& x, O
stmt=conn.createstatement();/ H! t7 V5 o  P  u$ ?# x0 J0 e
rs=stmt.executequery(sqld);( \! U0 v! v- D
while(rs.next())
- P% \( c7 h6 m. D* |{
/ d: A8 @9 u+ C9 ^- _/ T, N%>
- I" A9 }5 o# v; n  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
2 V+ E! T$ j4 z, d. Y: O* `% I: X! _<%
8 P2 j7 {& Q* t1 r( i}6 j7 o* Z/ E. M
%> / I* ]8 b( R- o! Q* p0 e5 D2 h
  </select>' u/ G* o4 J' l' p
</td>" s- r+ V/ p8 t3 h
    <td>
1 A; ?+ w: K" t& r  f$ h  <select multiple id=city style="width:150;height:200" class="bgc">- U7 X4 B0 x' y* C7 L' l
  </select>
5 m7 S( p6 ~5 S/ A, ^/ x' o2 w</td>- w' F& V4 I$ Z! `$ @9 D7 a9 _
    <td nowrap align="center" class="bgc">
& @, u' X0 I% Z. m  <input type="button"  value="<<" class="buttons">! O# M$ U0 z' V& C/ l3 P9 T
  <input type="button"  value=">>" class="buttons">
9 Y* o3 |+ T6 N1 M8 D& d</td>
7 E& O& a7 G6 z/ i! @    <td>( d+ v" h& X# P; i; [- f
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
0 i1 W* E% K2 x: x, G+ x  e  </select>+ ?; }; s  I3 J8 b! n
</td>
' X! Q2 o" p+ s& L3 Y3 c  </tr>: q0 f5 n) R' P, Z9 I2 b
    <tr class="bgc"> 3 ]; w$ T# w' `* ~  R7 j
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>* }9 g+ R$ d- R4 @1 F" b
  </tr>! z8 q2 X7 C7 U2 i6 A0 f
</table>6 x/ W1 e2 e/ D7 s. r0 u
</form>2 r7 s7 x) W" A  _! o. E
<script language="javascript">
" P; b, Z5 `% H) `2 b$ N- a//人名移动9 h% u- `1 X, R+ q6 D8 p" m- z
function move(fbox, tbox) {: N6 i2 r% }5 S2 m+ ]* n
var arrfbox = new array();3 t: y7 o, K2 m& {
var arrtbox = new array();; B) N1 [1 v  a
var arrlookup = new array();
# C6 j6 l5 d* o( v( q1 C; [) F0 {var i;/ r0 F9 A% }: V& E
for (i = 0; i < tbox.options.length; i++) {$ e* f- D- f4 ?; G2 l
arrlookup[tbox.options.text] = tbox.options.value;
1 Y  n1 a3 \" _arrtbox = tbox.options.text;
. @( |, b1 \( S% u5 Q& ]}
! f* C: K; h; B3 \var flength = 0;$ }+ @# J' Q0 ?
var tlength = arrtbox.length;4 ^# K: |; B) J$ X7 \" z0 x
for(i = 0; i < fbox.options.length; i++) {  a" [. Q: \% m' C6 }- I9 U/ b
arrlookup[fbox.options.text] = fbox.options.value;) y5 c, U5 ]5 H5 ~* o
if (fbox.options.selected && fbox.options.value != "") {  B3 g2 ]5 q2 a1 x; C
arrtbox[tlength] = fbox.options.text;) Y8 M+ L# M! r3 Z: R5 W
tlength++;
4 `- ~7 i& {$ o+ K3 z}+ f$ t2 c+ k" ?! t6 B9 ~+ H1 v
else {$ k" V& h4 s- G% ~% @2 f
arrfbox[flength] = fbox.options.text;3 T% W' L& o5 l& {
flength++;% }4 v" _( U; N" p) F5 u
   }: X% ?/ ~% \7 L* M* a; U8 u8 B! Z
}
" l9 t- `) H% _1 }1 h" J5 Warrfbox.sort();
) p' z( ?0 K. h3 }/ }3 b( Earrtbox.sort();; t' c! p+ {2 i6 a9 P  G

  W1 X; o# h8 q3 }fbox.length = 0;
0 d4 [, i# r8 H4 C" [! g% J+ q  ~tbox.length = 0;
! [3 k$ ]4 j6 s- E$ K3 vvar c;
2 b% @4 C9 S, {; o  t4 Zfor(c = 0; c < arrfbox.length; c++) {
; M1 q, {' j- svar no = new option();( t4 I9 T) k: U' o+ U6 h
no.value = arrlookup[arrfbox[c]];, G! c3 k# g. J1 e! }. I
no.text = arrfbox[c];5 {( _# ~- Y) O; g
fbox[c] = no;+ D# L0 `4 O% \8 r% ?" E4 D
}" \. V5 J0 G; ~  B/ U
for(c = 0; c < arrtbox.length; c++) {
3 A* n0 M. l3 Y' B# o% M( avar no = new option();
+ i7 i. D, n8 O+ Y4 n7 Fno.value = arrlookup[arrtbox[c]];2 O( z5 F& S( ^6 o# P% ?* G2 ]; X8 e. K
no.text = arrtbox[c];
' a5 n$ u; h! G1 a5 s  vtbox[c] = no;
  @* c9 I8 |# S: W) _. f- U   }
8 U+ g) _# P6 |) w0 A}2 a1 t! n' O; `9 k( J" W! ^2 n+ F
</script>. z$ e2 ?  R6 I( m) A) J
</body>
0 y5 z) P3 {/ f" K





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