Board logo

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

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

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
' H: m  k$ ~) T& H7 h8 o         c pageencoding="gb2312"! O/ e3 h' d6 e3 m
%>
; P- s; i" p' g0 q" U<style>
6 u. B5 w; [% A0 \5 c0 l. g7 H.f9{ font-size:9pt; }
2 R  }* @/ O5 W+ a: l.bgc{ background-color:#aecaf9; color: #0033ff }
$ Q5 Q: V% `# N" G: y2 C9 X# {- k.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;2 @: ]0 Y3 `9 M  x
  border-bottom: solid 1px #4e7dc1;
5 p3 K) F! }2 k  O- {  border-left: solid 1px #aecaf9;) ?( g  t2 a! K4 C
  border-right: solid 1px #5679bd;
" o* Y' X6 i$ V! v' A5 w" T  padding:1px;
8 N% q) F& T6 n2 N6 z  margin:0px;}
( H6 [" f  t' d* @2 n: m2 X- y</style>1 ?/ m  a5 N2 A  |
<script language="javascript">
, r6 d6 R# ^2 D0 z5 Q; n<!--5 X8 D! E8 s3 R! z5 m
function rv()
7 _2 [# k; J* g{
) p2 `2 s9 R% G) {. e  var val="";6 J5 t2 i) X/ R, X! S4 z
  for(i=0;i<combo_box.list2.length;i++){# G, w9 X. [/ U0 q0 {
   val+=","+combo_box.list2.value;( I0 N0 c* ~/ D. q
  }% n/ ?$ R. t, V- U' _& H. G
  if(val.charat(0)==","){2 S/ \6 {' s8 J! q4 k# b* Y2 Y
   val=val.substr(1,val.length);( J/ B! Y- h# a% L: @( w
  }
4 o0 M; K! e7 t+ m7 Y  opener.form1.frecname.value=val;) v8 C) o" w& Q
  self.close();; j9 x/ g4 A2 i1 C
}
* I/ ?' v0 M. \4 ?" w- w; L//-->
" k2 t8 o) g) v! j- x</script>. i# L) D3 p9 ?+ q! B9 d
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
: O1 [* Z/ j0 _9 H4 d<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />0 c1 L+ ]/ g: a+ B& `
<%+ B6 ?9 ~, w9 T' Y& [5 b  X
  cdatasource ds=new cdatasource();  //数据联结bean实例7 L/ n' v6 E5 c0 R5 l3 [
  java.sql.connection conn=ds.getconnection();6 x1 B- w* Z; }* ^
  java.sql.statement stmt=null;
8 }1 U3 G4 c1 K  java.sql.resultset rs=null;
* `# J  f! B  x  cdatacheck dc=new cdatacheck();5 D' v' s) [& T8 v+ Y$ n) I3 L1 \
%>3 A5 |7 q. b4 _3 B
<%5 X6 n* y0 u: j6 l
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";$ e7 w' S& Y2 |# d5 e8 v% ]! j
stmt=conn.createstatement();
2 W6 l: i2 I* p/ J, Grs=stmt.executequery(sqlu);
7 q7 P$ L. C2 v& l8 c" b%>; Y1 ~; f5 D, O
<script language='javascript'>
* F  \$ T) \0 @  q% Z% W$ jarr = new array();
% V2 v! ^# P* \; s4 S4 E<%  int temp=0;
; m" F, w" n, ?$ C8 ywhile(rs.next())1 L  w. c$ i/ v  U# S* j
{
$ v( O$ h! U! n  T/ _3 O%>
4 b7 R8 A* z9 S) N3 B5 t  H# Jarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
" h) a6 G: ^/ {9 b7 P7 p<%
! O. Q, ]8 U" D& X6 L- S; Ptemp = temp + 1;. m4 R4 L# [& t/ k9 W
}1 V3 r; L8 m8 K' D/ g* m) D
%>/ U. ?2 s# i8 a/ h- F
temp=<%=temp%>;5 z3 ^4 @9 o: ]. N6 ?! G( X. r
function changelocation(id){ + W3 A" C" t5 I
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
& D. w; [9 t, H" Xvar i = 0;
& D( ~( J6 o. s0 i' bdocument.combo_box.city.options[0]=new option('-------',''); ) T" ^7 _+ k) \, a# E! R* a/ @2 c
for(i=0;i<temp;i++){ : l0 }$ }0 O" O6 z
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] * F9 x0 x% K3 T
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
4 m, t/ {- }% P9 V+ d7 s}
0 B1 X$ a* D% `7 t0 y}
( S: B3 A$ w# G, Y* }}
& ^3 T9 }& ]6 Q' S/ p/ ^# K2 z: [2 X</script>( i& N- H" H+ N) u

3 N) ?. h4 B5 U7 c% V) y<form name="combo_box">
% H7 [/ p$ _- i<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">' ^& @3 a. P1 P) W  O9 h  b
  <tr height="24">
0 s/ k9 Z" J% B$ r/ r    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>; W6 X! k# X: w* R
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
, p$ b( e  ~8 y4 A    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
8 R4 |. M- ^0 B. z% Z, b4 ]8 s    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
6 K2 i* N7 I. O3 L" Y  </tr>; y) |/ v7 E9 b0 q' a
  <tr> $ n- H* r" t/ j! n9 v1 Q( `
    <td>! l. B3 Y8 z; o% e; u- K
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">) c. d5 z# U& _
  <option value="0">请选择部门 ---></option>
) k+ s* L6 A) _% x, q1 @' S/ Y<%
; J% R% ^4 T! q! u# L5 G6 m- o    string sqld="select * from tdept";
9 v% A- U  v  Z5 a% `% @( U& v; Fstmt=conn.createstatement();
2 U/ n9 U/ G# s- Crs=stmt.executequery(sqld);: G2 M5 M9 \# s( [; _8 b
while(rs.next())
' o' N. o6 E: T{' y0 W0 Y+ A; \) Y) T9 N
%>
! K$ {& [5 Z2 V+ Q* P  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>5 Y* L7 T& t7 z4 D6 E
<%+ R9 p/ }: n5 x
}
, ^& _' w# [* R6 T+ K. I%>
/ }* V* x! _# T3 M# |& M* ~) h2 r  </select>
2 ~6 l+ m4 I# t2 l</td>/ N. y3 k" f. n' B/ Y5 F1 _% H  f
    <td>
7 H. h  {0 k$ {  <select multiple id=city style="width:150;height:200" class="bgc">
; E8 o6 K+ d# y  </select>- w  l- X, j) N: w1 G1 Q2 |
</td>
4 R! v* j2 B1 _1 O) G; R    <td nowrap align="center" class="bgc">
# C; U( r; `3 F- A7 @( b0 d( U9 Z  <input type="button"  value="<<" class="buttons"># V, p$ I  ~- Q, z: N2 A- m- Q
  <input type="button"  value=">>" class="buttons">
6 j' ~3 ~- E& e: S, j</td>
/ k5 D: O+ K8 f% c) ?    <td>& c' s5 a! B2 L6 `
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
. L# L8 ?7 ^4 z; q% q5 ^  </select>1 C7 \/ z8 k+ t, P
</td>7 f! T; i8 O2 O' n) }
  </tr>% G4 w$ y* B: K
    <tr class="bgc"> # E! Z; F& A! d. T
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>% a9 M) }$ I: o- h
  </tr>3 Y& G' G8 a/ r+ v# B! Q
</table>
5 C2 H2 S0 a0 M( \; I* Y</form>
& `# b. O- U! P+ n& a$ j* z7 X<script language="javascript">
3 t. A* K. l, J+ c$ @//人名移动% Q, R+ }6 J9 O% g, L: A
function move(fbox, tbox) {4 t/ G4 S1 l% V. G. m, I4 r" C
var arrfbox = new array();
: Z1 Z! i. W# Y9 F8 yvar arrtbox = new array();0 L5 ?6 }5 I( q; W
var arrlookup = new array();0 Q3 I( y! o0 S/ Z) b
var i;' g! o+ f' V3 G, s; k
for (i = 0; i < tbox.options.length; i++) {
/ N$ k) h. p0 t, I' f5 ^' V. j. Qarrlookup[tbox.options.text] = tbox.options.value;  p) i  R& I+ j+ Q" E6 c% W5 D# U( a
arrtbox = tbox.options.text;
7 a, {% L" g$ R}
8 G. |0 O! `4 l& u* ?2 q1 Yvar flength = 0;* }0 p, r/ K5 |; \/ Q4 z/ }, ^
var tlength = arrtbox.length;4 \+ D, j# z" {' q2 M
for(i = 0; i < fbox.options.length; i++) {
6 k& j4 V4 ~. M) {, v0 B9 barrlookup[fbox.options.text] = fbox.options.value;4 r0 A$ S5 y0 H& L+ Y6 H
if (fbox.options.selected && fbox.options.value != "") {
: f, c8 T4 Y# T$ a' Oarrtbox[tlength] = fbox.options.text;3 Q6 @+ x$ Q# h5 i+ \/ M
tlength++;9 y1 }. b9 g% K7 U, V5 i
}  B/ F& o; s+ D& Z. k- L
else {, m6 S8 q5 ]2 D7 p; q, P
arrfbox[flength] = fbox.options.text;" I& i; v$ w  x: @
flength++;
5 R7 G8 D# Y+ p/ ~   }
; u% l6 Y/ u. }& K! X' f}
; K% N% l' {# y0 v- rarrfbox.sort();
3 \* j" K! {$ s& W/ R8 J9 Rarrtbox.sort();
7 I& \& y5 M# T4 N- p2 b+ E$ C8 v" S" \0 Q- h$ e* C( r$ D
fbox.length = 0;! k; F' Y7 _9 v) a0 l
tbox.length = 0;
! E% e6 L+ k+ P2 {var c;0 u& O4 v2 l% g" y) l' H) D* [9 o( s
for(c = 0; c < arrfbox.length; c++) {
+ @# C+ D" w9 o0 C6 s: ~var no = new option();
! K  r/ ^# {' U. S6 C+ v# sno.value = arrlookup[arrfbox[c]];, H8 e, u( G9 z6 C* N% E: V9 B
no.text = arrfbox[c];' M4 H3 `, Y" x! n
fbox[c] = no;
) }, B& G+ x1 [# C! C3 |6 a}: J% z+ x  h/ V
for(c = 0; c < arrtbox.length; c++) {
8 B" E2 u3 \  j- @) {var no = new option();
& O, x  V% h. F, R3 Y" k% bno.value = arrlookup[arrtbox[c]];
% b6 L$ j6 N7 pno.text = arrtbox[c];
* t* }% o9 m' Otbox[c] = no;; q% W$ k# g5 x& N3 B9 s9 @  O
   }
5 `; E, O7 v. t' [; O}
$ q5 q0 |* V- @2 w  K: }& f</script>1 l, u+ v$ U) z' C
</body>
2 F% F- S# Y, d; F8 l% d, B. c6 _





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