Board logo

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

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

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
* M& g- g' f% ]  T1 T' i         c pageencoding="gb2312"
+ z6 g$ x/ A- @# N%>
2 F# I) w6 ~# U. w% w2 A8 ^<style>
; @' ~" ?! r1 f4 J' r1 }.f9{ font-size:9pt; }& T6 z% ?9 L4 z2 a
.bgc{ background-color:#aecaf9; color: #0033ff }: `! {8 d2 [  `
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;% G# T" g; V% g5 {/ K* S* M8 R
  border-bottom: solid 1px #4e7dc1;
- A# r7 X& W$ W" E5 N0 h# q  border-left: solid 1px #aecaf9;! p/ v' ]! {* j3 \# k" v$ y# |$ Q3 Z
  border-right: solid 1px #5679bd;8 f/ _- v. Q3 n" A
  padding:1px;- z1 E$ p  h# {: O; m0 `7 n. p
  margin:0px;}
" B* d1 i- x0 M( e; U8 T</style>, ]) w8 k: R; @
<script language="javascript">$ b; v6 ]( l; b# ^' a
<!--
. Q( J# X- Q7 W- R7 Lfunction rv()
6 ?& z9 a2 a" V2 C{
6 p" A1 M3 z- l. w  var val="";! }5 v/ a0 {$ {' U
  for(i=0;i<combo_box.list2.length;i++){3 j5 j+ x# j4 e  ]8 X* ]; N/ L
   val+=","+combo_box.list2.value;. L) |/ m! {9 e* v
  }
( M% u: S  n. U  if(val.charat(0)==","){$ ~/ g: l7 Q  r3 D$ x
   val=val.substr(1,val.length);1 w9 `: n1 q$ x) I
  }
  h# C; ~# l2 }. U  opener.form1.frecname.value=val;  D$ G; N" ?' H( Y
  self.close();
3 w4 C5 e. S( m; I9 @}
+ j+ N! s9 Q8 k& _" _1 A7 s9 m$ v//-->8 `" Z: J* _! O( R! O6 [
</script>: J* A9 c+ k2 t9 D5 q
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">8 C  q+ m, p" i5 x. M8 b% t9 f( [
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
4 G0 b0 P! ?1 F<%9 X$ O6 }2 t; D6 K+ k; I/ d
  cdatasource ds=new cdatasource();  //数据联结bean实例+ b7 h8 G. B$ h$ c' S
  java.sql.connection conn=ds.getconnection();6 X( L% c  u* }& E, X' o  B) S- W
  java.sql.statement stmt=null;
9 W! U9 D4 }0 R  ^  java.sql.resultset rs=null;; Y6 i+ h: g  d1 T& D* @. O
  cdatacheck dc=new cdatacheck();7 _0 V) x' n+ U* t- ?
%>& l: j7 r/ \$ T7 w
<%
: \7 O. |2 F* D, u: G* J8 cstring 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";; r" P. v8 U- l2 h' _8 D: W. z$ b
stmt=conn.createstatement();
( C7 M" q/ D! h# G& l5 crs=stmt.executequery(sqlu);
+ ~) L& J5 M3 r% A5 l# O0 {%>! a4 w/ N  k% d) C; |3 m7 o
<script language='javascript'>
7 }8 C0 U8 w* Z* u  H5 V9 Marr = new array();5 s* W' S0 a# {( n, U! A
<%  int temp=0;; T  t$ F1 j2 H+ b6 ^; G. Y* ]7 `* P
while(rs.next())- a" t& _* L* [# X1 _  F
{8 F) z7 B; Y+ R0 P7 v. m& h. M
%>) k: v# |3 H# i" f3 c4 j
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
9 ^  H+ \: T1 p* n<%
' x" ^) v1 K1 ?" f3 ~" U  G; n" wtemp = temp + 1;" l& j8 }+ J7 l, R1 h& h, w
}' j" J2 |, D, p8 A. x9 O
%>
. N  ~4 G# H8 {3 \& `- S8 `5 htemp=<%=temp%>;7 H8 E& L7 N1 c9 f0 p* \
function changelocation(id){
5 A5 T. ?% D  k0 ldocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 + E" g9 R. ]5 |$ F# Z3 m+ j
var i = 0;
' N4 |/ ]; y. Fdocument.combo_box.city.options[0]=new option('-------',''); . O* d; Q; \! {8 x
for(i=0;i<temp;i++){ ' Y7 q+ J3 y: u0 }# y" [+ q
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
) |4 V# L" P* y% sdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
  }" e8 T7 {# A( ^} , k# `+ E5 g+ f$ W  l9 B: ~
} 1 T! y/ o" `# P- `- u* _
} / ?9 N7 u4 i$ M6 h* u2 U& k
</script>
4 R8 i2 ^# d$ o2 Z, R* S' N: \- B$ v8 A
<form name="combo_box">, u- r0 G5 H1 S4 [+ V6 @
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
7 g, B& _2 n, b% q$ Q3 R  <tr height="24">
9 c" m% b8 k6 k5 m    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
, d+ t$ j$ N' k* t" P! P    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>% `6 N% h3 x7 B; o+ D
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
0 N5 A* {( Z7 ?    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
: `0 d! ]& f8 ~' H1 a  </tr>( w* N7 K4 [* D( f* l0 {4 X
  <tr>
9 a0 F6 V/ @8 ?+ C* Q- V1 i8 a! b$ F$ f    <td>! e" k( T* ~# A/ C# p+ }. u; x. x) L
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">+ Z% G; W" Q2 k  c
  <option value="0">请选择部门 ---></option>
" c9 x7 m7 X1 ?  C& ~$ @2 m2 V<%, H; Z. F+ k4 Y8 m
    string sqld="select * from tdept";
5 f' m( O7 W  E" V9 m& V' p# m5 Kstmt=conn.createstatement();
( g' t* r7 H/ T% l- Urs=stmt.executequery(sqld);' s7 H" o  g6 z& M6 x) y
while(rs.next())2 ^, Y" s: O  e' u
{$ v$ w( c  _& x1 m3 j
%>$ R4 U  X  ~, V  K" C
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>) h% [8 e* [" E, a$ N- K  V( |$ H
<%- p1 c+ B" n4 A  U. J+ w( J
}- N( ~% t( P7 u$ O! [' G
%> 6 r% `9 e( O8 j* q
  </select>3 D: B" e9 v# `7 Z0 u8 J
</td>
. T# N8 A& Z2 G, c    <td>- Y  s1 X4 V  }3 ^/ E7 A% s- N- [# `( v: {
  <select multiple id=city style="width:150;height:200" class="bgc">/ }/ K0 O# n6 i9 H
  </select>
$ ]' Y5 r% F' B/ [$ {</td>
+ {8 b- {& d% {! z" h4 c% w    <td nowrap align="center" class="bgc">
" K2 o7 h; E# o0 Y6 m. `' |  b  <input type="button"  value="<<" class="buttons">
% M( H/ I6 C  ~7 e" |) y1 U  <input type="button"  value=">>" class="buttons">7 N: n, x. }: o; H( u4 c1 }6 s
</td>
+ ?" W9 [9 W$ d8 e8 b+ z$ k# g    <td>
; E0 A! g. J* U6 v+ d9 g7 r3 {  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">" g5 x2 o1 j! V" P! i3 \% O
  </select>! ^' k3 v1 k* k4 W: E' h0 p4 E
</td>
$ Z# i" i, _: B5 K. U# v  </tr>
+ U9 L7 w- U. a  h" W# X    <tr class="bgc"> # Q8 O+ c# T: A! k
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
/ p4 }3 d* ~% W  </tr>
6 P7 v8 C! N$ [3 a) ?/ d</table>9 s" |" M6 m. H4 l- \$ L6 h* b& n
</form>/ R. F7 ]0 H! L' t. g- G$ N+ z
<script language="javascript">
# E# b/ X; q$ C, ~) I& E//人名移动2 _. u- j3 Q: C
function move(fbox, tbox) {
; }- q7 k4 q# x8 e$ e+ `var arrfbox = new array();5 y( U2 p1 u7 S: I+ H
var arrtbox = new array();  Y' `; U9 A. L( [3 @
var arrlookup = new array();: m4 s1 w0 h, ^
var i;
- ~$ d7 Q9 e/ x# }0 rfor (i = 0; i < tbox.options.length; i++) {
0 q( }! n/ C4 y* b5 U' Marrlookup[tbox.options.text] = tbox.options.value;
+ u+ ^% i; @. Karrtbox = tbox.options.text;+ r4 |$ X9 }4 \" Y3 U
}9 s, Y. c# J" g: }6 G- h
var flength = 0;9 A* J5 a2 m# y* W+ ^
var tlength = arrtbox.length;; E3 T# m& ?3 n/ @
for(i = 0; i < fbox.options.length; i++) {
% B' E1 e$ Y4 {$ }; S8 X( rarrlookup[fbox.options.text] = fbox.options.value;
, A- J& G0 h/ D3 Q9 H3 Hif (fbox.options.selected && fbox.options.value != "") {
/ `6 h5 b: d% yarrtbox[tlength] = fbox.options.text;/ X. |8 Z, e: I1 a+ q1 `
tlength++;( o* j: N$ X9 U3 j& j
}
. x/ k2 z: P" L1 {else {0 x$ b( m; }5 o. t
arrfbox[flength] = fbox.options.text;
6 ^4 h) ]. J2 d+ t+ wflength++;
( G7 y+ D  p" y   }2 e; o, P7 b- d
}4 }4 Q, j* v$ g3 y9 P8 X
arrfbox.sort();6 w* h: U3 w9 t/ g5 |/ I! J3 v
arrtbox.sort();8 ?2 O6 W+ r! K) Y: r2 A: K

$ x4 l9 ?% U3 I9 Sfbox.length = 0;
& }; M6 _. u  e6 o( etbox.length = 0;
/ u& W0 g# q3 V3 ?% I4 Nvar c;
9 i# t7 O+ U& e2 yfor(c = 0; c < arrfbox.length; c++) {' n9 T, x  N0 X4 e  t( v
var no = new option();9 r5 f. w2 D3 P; u' h& J: x* S
no.value = arrlookup[arrfbox[c]];5 f$ [% |" t/ {0 _
no.text = arrfbox[c];
$ L6 H( U1 m0 i5 |: ufbox[c] = no;7 ~# N. i, k/ ^3 ~% K$ ]/ t
}+ _1 I( C0 \; b
for(c = 0; c < arrtbox.length; c++) {
3 j! G$ P. n; O3 Avar no = new option();
$ g; w# m% F) nno.value = arrlookup[arrtbox[c]];9 C; t4 |) R( x# z' E
no.text = arrtbox[c];
) q0 }# h7 P' ~0 O3 q' ~! s% Htbox[c] = no;/ ]- u2 L% ~, v
   }
) n3 t0 p% j, B) s}
1 Z- o/ r" @- W2 F  [. y4 c7 N( e  g& C</script>
1 r/ ]" Y5 c9 i</body>. C1 m6 i& ~+ k9 g1 z





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