Board logo

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

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

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;". L8 [( _2 |+ h, s% [' g* V8 }6 @
         c pageencoding="gb2312"% h, o0 e, {+ G) R
%>
! G7 P  `4 ?' S* ?4 ]<style>
/ C& _- @3 a. C* f  d, E.f9{ font-size:9pt; }
4 K& N$ L: m3 p6 w+ o# O- }.bgc{ background-color:#aecaf9; color: #0033ff }
) z2 B8 q  m# \! b; S& ]7 y" s.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
* j8 U6 f5 d1 B5 s* i2 Q8 S  border-bottom: solid 1px #4e7dc1;
' t# q  O' f9 i' E. M' u3 u& c  border-left: solid 1px #aecaf9;
9 P# z4 L) h9 u' w; I  border-right: solid 1px #5679bd;, [$ }6 K' `. ~" }; M( W
  padding:1px;- D+ y( A# G: q$ q; c+ J
  margin:0px;}& R) u" F. w  \: B9 n5 Q8 L
</style>1 w2 G0 I% [4 l
<script language="javascript">' u4 p6 I/ n' f* `" N9 ~
<!--
$ `. d+ G* W& I% g% @0 ufunction rv()
" Y' D* D( q' E* {. Z8 [5 o9 z{7 V1 v; N9 ~# j# `% H
  var val="";
0 F6 h& s4 ~% X' m  for(i=0;i<combo_box.list2.length;i++){( L. _0 Q3 B% w6 f# y5 E
   val+=","+combo_box.list2.value;& w+ U, E. E  s  [. b, x; P6 k+ z
  }
$ `$ o" r* A. o: ^  if(val.charat(0)==","){
$ b4 _& J% H1 S6 y( w   val=val.substr(1,val.length);. t% G7 G9 Z0 U% o
  }# e) B& D% q' ^3 z) X( k
  opener.form1.frecname.value=val;0 ?+ d! G% Z/ q- j* n: X) b
  self.close();3 e3 d0 g* z) D
}5 N6 q$ u  c  i3 A- E7 H, F1 {  G
//-->
: f- u0 |1 w# X' d</script>
$ |* V4 ?5 Y- y3 H  K) C# o<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">6 [5 f; d2 x* y* O
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
  t2 e2 A5 w9 w8 N( F# s! N2 Y, y3 J<%
) D# ?9 Q0 |/ S6 i6 R: E; l  cdatasource ds=new cdatasource();  //数据联结bean实例
3 v) e6 A' A, A0 k3 `$ O4 e) E7 J  java.sql.connection conn=ds.getconnection();
2 m4 s' t9 q# m  java.sql.statement stmt=null;! l4 B: w5 s  w* v. p; k, e+ \
  java.sql.resultset rs=null;6 Y: c2 ~9 k' E* ]+ q6 \
  cdatacheck dc=new cdatacheck();
; ?4 J# l# x8 P$ @# a% h7 P- a: A%>4 ^7 {7 c% Z8 p& K3 s  x
<%
5 ]# y. n7 M5 O* n0 ?# h( hstring 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- p7 L4 H, L* g5 H, Nstmt=conn.createstatement();! e6 U/ D6 M, ~1 P" Q) h
rs=stmt.executequery(sqlu);
# {! {! m+ u$ A' m4 w9 d* K2 Z%>
  B: B) A8 c/ q* ?& ?<script language='javascript'>- [& c* M. P3 e' V$ X% t* D8 G
arr = new array();
4 D5 r. F/ |, K5 |( o5 ]<%  int temp=0;
5 R' B7 N5 w+ W6 cwhile(rs.next())
9 _/ R' q& O' R' h0 _, S" s0 j{
  O' q0 q- X( f7 B%>
+ \3 n# o, O, Varr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");$ Z" Q8 _8 ?: }* H2 G7 X; `+ C6 J
<%
$ u( e! h$ W4 g( w' G% Ctemp = temp + 1;) g* b: s1 J/ ?  w! ~! s* i
}
/ Z- v! v# ]; F+ o' K%>
; D5 |) W/ G5 @4 P' L) I# D( Wtemp=<%=temp%>;
2 O4 F) E4 B4 G- R& Nfunction changelocation(id){ + g" \5 E/ S2 |& J( [7 a7 t# T6 ]
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 5 D# ^8 h2 Y) r( g0 U+ V
var i = 0; & u# K2 ~) _6 f  C! q1 m
document.combo_box.city.options[0]=new option('-------','');
2 v9 m2 h  ^; W; y2 ]# e2 |2 [for(i=0;i<temp;i++){ 9 p1 ~$ S/ o) P3 a2 B
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
  v, Z+ [' I# r) W; P9 @1 e2 s) Ndocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
2 e, ^& ~% H) D/ J1 N/ E3 N" v; R}
6 n4 c4 Z. C3 b# n2 G$ V3 k/ ]} / B7 }  H. f; `; n
} ' {2 k( s2 A' R4 Q* [2 d) e+ n" z2 z
</script>
3 {( }- z2 u% R4 K2 {7 S
( z  M* H2 ~- Q$ h5 I- @& J2 c! t<form name="combo_box">
: u! X! L) _3 U  }! \+ a# d' M! A" r: m<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">7 l" E* T. ]: ]- S$ M& k
  <tr height="24">" T; u  D: H: g9 l* l4 J
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>/ N3 V% Z+ q. q6 Y
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
+ A2 _3 X6 D' }) ?    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>5 C2 V/ O0 j8 F5 Y8 \& u
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
9 s; A3 @( O% d* W  </tr>6 ]; l1 T2 A: _) d% q
  <tr> # P5 x+ m( h8 f7 ~
    <td>4 {! p+ d" Z- m# e& W+ w
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
3 K& F* g- I0 x& }  <option value="0">请选择部门 ---></option>- {8 z1 Q7 _" @4 q
<%; J+ @" y  d: W& H9 _+ R2 P! h
    string sqld="select * from tdept";# S( b& E2 l' u) i7 `* ]" l2 g
stmt=conn.createstatement();
4 ]; \2 [/ _5 S- {  Qrs=stmt.executequery(sqld);
( p: `8 C, h' Q8 p3 Owhile(rs.next()): J% w- F; ?* H( a9 r
{
+ e. q0 B* G! d1 i%>
: J5 Q( G, I  U- r# _% d  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
* ?/ z- v: @; d# l1 a6 N<%
' d6 s' T; }  t$ s$ o! l) b$ I}
3 J" n/ k3 |" B' A2 w+ e$ v9 L%> ' Z" f. v* B$ j( G
  </select>( ^' ?1 E; d5 B/ }, h" j
</td>" ]3 S" @, v! p
    <td>
3 Z; B2 j  _3 M2 M  <select multiple id=city style="width:150;height:200" class="bgc">
) O& I* g$ V( E' ~8 O; e( q) l- }  </select>
! |) e6 J$ ]. r0 R</td>
: ]0 Y: f4 x+ {    <td nowrap align="center" class="bgc">
8 f7 J+ c- s7 S0 B! ]# T# h  <input type="button"  value="<<" class="buttons">9 u8 e! O0 l0 z1 c. W
  <input type="button"  value=">>" class="buttons">- D- H  f1 j# V$ D+ X
</td>. y# f. G1 f- @$ S
    <td>
4 j7 S$ W2 L$ j  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">5 m6 l2 p5 u2 @0 ~! B1 l
  </select>/ S; A6 y- i$ K) `& F! U+ ?+ j: r
</td>" o* e4 G, M0 i
  </tr>8 B9 j# B6 R; d6 t. U
    <tr class="bgc"> 2 x; @5 Y! x; m' X+ j$ a: Y
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
4 K% @# x9 m2 H+ K# J( A. U7 ?  </tr>
  E: D. K  ?% W5 Z" ~! |) t* C</table>( p( W8 T8 B5 l. V* V
</form>+ f: J9 p/ s: ]) g
<script language="javascript">
. U/ r- J9 n5 w8 t- m6 b//人名移动" A+ W* x7 L- r$ X! D9 Z3 d- e7 m- T
function move(fbox, tbox) {! l. u; z7 Q5 m$ I6 ^1 h, K
var arrfbox = new array();
; P, K# e) D: n, R: ~' pvar arrtbox = new array();
) x# b$ @; }4 f; W" Uvar arrlookup = new array();
9 z/ `# }2 D6 b8 U1 d, rvar i;
  d1 r1 B$ s7 Q& N6 X+ ~/ ~for (i = 0; i < tbox.options.length; i++) {
' P& F2 I: n6 Z; L1 Marrlookup[tbox.options.text] = tbox.options.value;( x8 _. Y: b8 ~! f
arrtbox = tbox.options.text;
" u8 J8 o) S: [}% v! Q! O  y: S3 m% H  k' E- n
var flength = 0;
# b. D% r: G4 M. L# {% J4 ]var tlength = arrtbox.length;
- ?8 [1 m8 }) M3 `! W3 k  Vfor(i = 0; i < fbox.options.length; i++) {9 E* `' q+ u6 E3 C, y
arrlookup[fbox.options.text] = fbox.options.value;* d, p& r2 D; j4 L
if (fbox.options.selected && fbox.options.value != "") {7 Y4 E2 |- Q! E8 |. m; f
arrtbox[tlength] = fbox.options.text;( @, ]9 F1 X7 P( E" t1 \" d: A
tlength++;
, O( b9 k- o! @- }}
! U+ [- u* U7 m# ~# n& r2 N  relse {6 O$ L/ y9 Q7 h, `8 [' T
arrfbox[flength] = fbox.options.text;
# t' c; V% k/ n" {7 wflength++;
/ H3 e; }, ~+ h" V  p   }, f" C6 M2 H! a! I: e0 D( ~
}$ ?0 J& g& }$ |
arrfbox.sort();
, _, T  l/ I  l5 M3 varrtbox.sort();# \2 h0 z  h/ P

3 m( `/ |. A! ]/ B9 i# p7 Y# dfbox.length = 0;+ W; Y1 S! @. }6 }
tbox.length = 0;
; L! @6 ^, W8 m2 Q0 z! ^; W  q- Mvar c;% |7 y& e% ~0 S+ q4 D3 C" U
for(c = 0; c < arrfbox.length; c++) {
6 j' P+ o- [2 n. f: N/ M! Cvar no = new option();8 X. w1 |7 [3 l/ U
no.value = arrlookup[arrfbox[c]];
% W7 A, ~2 g, W' O) G- p+ H  m9 Pno.text = arrfbox[c];4 e$ S% H  M- n4 ~0 Y
fbox[c] = no;! L- ?7 Y* y3 B3 D) d
}
/ w. o: X; i- S7 O+ P, Jfor(c = 0; c < arrtbox.length; c++) {
* s, p& X: D" G5 p) \  U/ U4 Kvar no = new option();
' u1 `) W/ _- Y  S3 L0 Eno.value = arrlookup[arrtbox[c]];% T9 Y% ^: W" h# S
no.text = arrtbox[c];' r  q. w( O! y, ~
tbox[c] = no;8 s2 Z+ G0 J; ~6 b: t% @; i9 k; Y" ?
   }
$ t) W2 w2 q% W" c! \  q}7 }8 A1 ]! {! k+ \% k; e# w0 y
</script>
8 n4 n0 H& [" f4 w4 Y</body>
) v. J& L/ c% E





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