Board logo

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

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

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;". |8 H% I/ p) @3 N4 j
         c pageencoding="gb2312"1 A% x, o+ v5 B
%>, W/ A3 _. @5 O% r
<style>
. b4 \2 c; ^+ h.f9{ font-size:9pt; }
, T. U- b8 M6 y. F.bgc{ background-color:#aecaf9; color: #0033ff }, ^; _. Y+ k( g1 o$ H2 Y
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;) w/ k- h+ F  M
  border-bottom: solid 1px #4e7dc1;
/ f" [2 J7 Y. k9 Q  border-left: solid 1px #aecaf9;
0 h- t9 Q2 o  L9 L/ j/ A1 v  @- d% [  border-right: solid 1px #5679bd;0 u  Q5 L- ]$ z& E( ~- n: R
  padding:1px;
& N9 R3 r6 ^) }! I$ ~  margin:0px;}
4 b5 P" w; |4 _: S  |5 A</style>
9 T4 w: o9 Z- S<script language="javascript">
3 \- C7 @; \6 k  R. g  V5 M<!--
, G8 G! x& r1 e# m* H* V8 qfunction rv()
5 x! Y6 B2 A3 j$ u, q4 e{
) A, }* ^0 B0 ?) ?# ~+ z& W  var val="";; z3 M: {5 x8 l4 X; k0 }8 w
  for(i=0;i<combo_box.list2.length;i++){* n% w3 Y* f0 S* A; K0 z# a4 E& s
   val+=","+combo_box.list2.value;1 Z! O; D. S  j
  }
" F# C6 i# j$ y! N  if(val.charat(0)==","){
+ X; Z5 {3 M2 A   val=val.substr(1,val.length);0 `2 N" L* {6 T% V
  }+ M7 ]) k( v$ N4 E, W6 g
  opener.form1.frecname.value=val;* |  V  M% e/ H" L
  self.close();
; ]3 n5 c0 t, R- O/ O) k: [}
5 |" f/ {; U% q! C1 d+ N. ]//-->1 e  f' x1 G) a8 C5 Q5 f% j
</script>
- J1 J* \) m" N9 G<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">( y6 `. p& p( R( s. W0 `
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
. H0 x: j) x0 Q, Z: r4 u<%5 T2 C$ j" M6 o1 j
  cdatasource ds=new cdatasource();  //数据联结bean实例# O* ^1 F7 x, [5 H7 f. ^
  java.sql.connection conn=ds.getconnection();; M8 G6 j5 c8 O
  java.sql.statement stmt=null;
' q" H/ N  d' ?4 A% G  java.sql.resultset rs=null;
  ^% s; P! U% }6 d7 y  cdatacheck dc=new cdatacheck();9 b( U! i3 D7 I+ `
%>
3 X3 s+ c( U; y7 ~1 t<%
. w% X5 z6 @, H9 vstring 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 f' O3 e% H& U2 ~stmt=conn.createstatement();! R( V; X+ h; e+ I/ h) J' P2 q
rs=stmt.executequery(sqlu);
* S: u' \* r' l% g%>0 |2 ]* g" }* D* }3 R( S& M
<script language='javascript'>
$ Y4 F( r9 w2 jarr = new array();
% p5 H" r! _3 x6 P* i<%  int temp=0;
7 a: p9 x3 r2 f9 [# g- @while(rs.next())
1 q8 w  q0 d( G: ~8 h{  ~2 M, w$ ?4 d9 `" z
%>
, b. p/ t1 J0 karr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");4 b/ j* r! ?0 S  P. A1 x3 V4 G, z% v9 L
<%& k$ |( M8 h  b# ]+ w
temp = temp + 1;( {7 S3 P( ]/ [
}
& m! b! k& v, ?; e( E2 l%>" I9 W$ |* v, M% o  u+ }2 A
temp=<%=temp%>;' G- S& \1 F- }$ a; u4 t: s
function changelocation(id){
; ?, p3 m1 u7 n/ Q7 j) Ldocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 . ?1 x( a6 x% y
var i = 0; 7 e0 o8 k, I3 [
document.combo_box.city.options[0]=new option('-------','');
0 |( k& x4 I! i4 p5 M4 }for(i=0;i<temp;i++){ ; ?$ C5 _1 f: c3 e* d; u
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 0 ]5 ?* {5 C0 t4 @# u7 F+ D. ]  u
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
7 v, P( i. B6 k+ m6 ~% [}
9 d) o" h8 E& s+ z( `  y}
% _: w% Y& t, w! {} * e* p" R" C) Y0 v7 q! ]
</script>1 G$ X: H, L- [3 h, w6 u
0 D) _& W  H7 I  Q* p
<form name="combo_box">
) Q5 q" ~8 @! ?0 d" M<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
& }$ Y1 S7 j+ [" K  <tr height="24">
/ e( g" J' C9 q: s7 W7 y    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
2 S+ i6 e: r. P- K1 G    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
% l2 |: M* F* @, ?: m6 ?    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
  Y( h$ b  q6 z, d# l    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>2 m. @* D5 Z1 z
  </tr>
" G: v- d7 v+ v; P  <tr> ; o( T# A1 G% n# R
    <td>
8 b# h) D- ]6 Q, f5 }- c& W0 d  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">6 A8 m2 s* l& ^
  <option value="0">请选择部门 ---></option>* P' D( M  G( n0 w
<%+ V$ ~0 k" a! d$ ^$ [- n5 l" q/ s
    string sqld="select * from tdept";
* _/ [- z. q5 Z6 H4 V  f9 ^5 H0 Ystmt=conn.createstatement();
- Y3 t8 O9 l: ^. {rs=stmt.executequery(sqld);
# X+ A* @" }( b  q: n: P9 M% Hwhile(rs.next())7 ^& V- P, A& U7 a
{
; m' X9 n# [3 E; b/ ^3 i%>
' r; s# X( V, ~% A8 Z4 t% W5 @; `3 x  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
# ~# {) w7 c2 A<%
' G0 M! v+ Z$ [# v/ T5 ~. n; {}6 k# u! {; z! J5 b6 Z1 t
%>
1 g' M4 |4 M- G* F! z. c2 q7 C( x  </select>0 s# i3 ^0 S% w- @# t$ @+ w
</td>& I8 k! M: P+ \, c2 o( J6 \" C6 d
    <td>$ [5 F! t3 X: F% D
  <select multiple id=city style="width:150;height:200" class="bgc">2 A. _' ~& W; l1 c+ w3 E. e
  </select>
+ z9 b3 S/ P2 E+ P) S8 ?, |# y! x; @</td>
  ^/ D- P& Y3 b' W! D    <td nowrap align="center" class="bgc">2 ]8 |; B" q0 b' ~; g
  <input type="button"  value="<<" class="buttons">8 g+ @5 F, y& \  A4 A  v
  <input type="button"  value=">>" class="buttons">
' a. l" N" b1 S</td>5 y' M) h0 ^1 G% ]! Z
    <td>' `7 M0 a/ R* y3 O
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
! S9 K# M# t2 Y) _7 U& d* ^  </select># a2 A$ Y' X5 Y  X, w
</td>
3 Z$ e$ u& f& b9 M  </tr>
" i: t7 P. @6 M( v, R# J    <tr class="bgc"> % A& G, U9 w: _, T/ l
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
# |: i' F$ }5 a0 E' ?  </tr>
$ U# c( Z4 b( [6 v</table>
2 G4 g- S' U! c1 b0 Y" X</form>% A2 \; e3 P6 o
<script language="javascript">
- R) n' f( ]. o2 a- P4 [$ s//人名移动
) e2 q. Z& b" p- h8 ifunction move(fbox, tbox) {" K. n: H. v, N6 L) e8 n0 \
var arrfbox = new array();
. [# {( m* T% M. E- z- a4 tvar arrtbox = new array();
* I# g& x& r; s! pvar arrlookup = new array();
+ f2 ]1 N, O- ]5 _2 yvar i;! ]6 }  b# i2 s
for (i = 0; i < tbox.options.length; i++) {& w/ c/ Q% h1 O7 |" H; h3 D
arrlookup[tbox.options.text] = tbox.options.value;6 C4 |7 c" J6 ?* Q, t
arrtbox = tbox.options.text;% }2 q& w2 k2 I( [/ u
}' W4 N& p: S1 D' l! Z4 Y4 Y% A
var flength = 0;
# @" j# X- a- W% b, D3 Ovar tlength = arrtbox.length;) Z& k+ e% S- ^0 L, T4 ?5 b8 r/ F
for(i = 0; i < fbox.options.length; i++) {, L+ A1 J0 r/ H
arrlookup[fbox.options.text] = fbox.options.value;: N( m( V+ Y5 P  J' ?5 X
if (fbox.options.selected && fbox.options.value != "") {
1 `) Z% G* d: D" I  Q& jarrtbox[tlength] = fbox.options.text;
1 f2 e! z$ z4 V: ]tlength++;. j+ p) @& }, u; Z) j+ E
}
: m3 n1 }) v8 Selse {, F7 Q0 e8 b: @, E3 Y
arrfbox[flength] = fbox.options.text;* X& a; d6 I+ ]0 d0 V/ `" v- D8 O8 K
flength++;6 f/ a7 a% u0 d, {
   }# K7 @- s) V5 i" `7 j
}
8 L. n! q- S' I, C$ k5 ?arrfbox.sort();
7 \0 S. o* M6 r3 D' H6 k' barrtbox.sort();
, ^8 D& [7 w; j! q* X# |+ @, e
* x7 q" a1 R, P3 O3 ufbox.length = 0;
" k' j; K1 l5 G- e5 B1 Atbox.length = 0;; O; z4 F- v0 e, X
var c;
& d) U$ U/ E- s4 Nfor(c = 0; c < arrfbox.length; c++) {
# z# b# L' p& p. O" gvar no = new option();, u7 ]0 e7 r, ]8 u7 `) Q
no.value = arrlookup[arrfbox[c]];
: P' G) }% s; d( u% R& n5 Bno.text = arrfbox[c];
# l) e  [$ n3 R% Bfbox[c] = no;
/ Z6 q. \" I" d  A% k) [! S2 `}
7 y, R% I5 \2 L9 o# jfor(c = 0; c < arrtbox.length; c++) {$ G5 ?- M" V  E  t8 T( C
var no = new option();5 R! H- m$ ?! g0 Y6 s3 F, l
no.value = arrlookup[arrtbox[c]];
* ?3 b( ?- m0 W0 L, j$ Xno.text = arrtbox[c];" t: O6 e. Z& a$ ^; N  A" I- r
tbox[c] = no;
/ ~6 S" D+ M' e) G7 U   }
& j) S8 d' l1 |/ M; e8 A}
: r6 I- \+ z* F4 ?</script>" o) w" G, |1 p8 N8 R( a& E8 X
</body>
" I6 Z; M4 R, s- p5 Z* ^





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