Board logo

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

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

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
' K% b; L+ k4 |# ?7 {+ E3 U         c pageencoding="gb2312"
! Q; P7 n4 c/ K+ O%>  W& t3 x1 [- m0 H
<style>
$ j) Z0 x( N, [9 Y" S$ C1 F.f9{ font-size:9pt; }
$ F1 P3 t8 A5 W' `7 B/ j' C7 v; r.bgc{ background-color:#aecaf9; color: #0033ff }
+ `5 b. @  W9 a8 [5 q" x.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
7 l* s$ S* a: }8 e6 H  border-bottom: solid 1px #4e7dc1;
0 {2 [& O) y( j2 \% h  border-left: solid 1px #aecaf9;9 a: D3 h! {/ c8 ]) {4 h
  border-right: solid 1px #5679bd;) s( B) F- h! ]% C" T
  padding:1px;
7 }: {$ Q  q+ u5 ?5 v5 J  margin:0px;}" ^: a1 Z, H: m3 W% y
</style>
2 O4 g* y, R- q! m$ O( @<script language="javascript">
$ u0 W# z2 |  Q( @<!--/ I; s. `( P4 z' P8 l" A
function rv()
/ i3 E; R* J9 \8 E{
# I+ J" ~, M8 Z- Q9 y& x  var val="";
( S% ]8 G8 }- n# d6 J8 K  for(i=0;i<combo_box.list2.length;i++){4 L" p  ?# Y* d0 \' w+ X
   val+=","+combo_box.list2.value;
1 r9 Q0 `; K/ @. s  s  }
% [0 M( y( y; y% D  if(val.charat(0)==","){
/ f2 Y; M6 b! ]) ]* m9 R' h  G   val=val.substr(1,val.length);
6 b2 l' }, @  t& D8 M0 G  }" E) q6 I0 d- u9 v% `
  opener.form1.frecname.value=val;% f( v( q- H2 K0 X
  self.close();* j$ y; G3 F: U( Y7 H
}
1 ^" M7 B+ J/ Z$ x//-->6 e  ?' u+ c$ ]8 Q- I8 ?
</script>
7 C+ W4 [' @5 @- d* V<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">) x! e8 q% P& z
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
1 B1 ?2 m; ?( X; P% P" d<%) f+ a! }; A# M# n
  cdatasource ds=new cdatasource();  //数据联结bean实例; M5 Y- R6 E. u* ^6 H6 |. h2 |  w& N
  java.sql.connection conn=ds.getconnection();9 k: e% r# l, o3 O. k
  java.sql.statement stmt=null;
. [  E0 ~8 e0 N! m  java.sql.resultset rs=null;
6 U4 W' f1 `. R3 o  C* Z  cdatacheck dc=new cdatacheck();6 L. y8 p  _, B- e8 i
%>" D# J+ I( D1 v: H7 B. S! n$ h
<%$ W7 _0 s, y8 M' r3 p' C9 X" v. u
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";
. R4 h! G5 L/ Q; astmt=conn.createstatement();
7 z% R! o" @/ [- @! Ors=stmt.executequery(sqlu);
6 R* r/ @* E1 H%>
' U, ^% b4 e# g/ e" X<script language='javascript'>' m; L5 ]7 z3 S, n: ^! g
arr = new array();) k2 M5 ~/ s- K
<%  int temp=0;/ S- D1 q$ f# J( V: ]2 b* E
while(rs.next())
% j; S/ p" a( R7 v( \{
& D! D: E3 p/ I0 E  b%>9 ^9 p1 O' R6 m  W; y+ ~& b. i
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");+ C" s0 g2 ]/ Q2 y
<%0 s. c+ I8 v0 p7 v, b1 F
temp = temp + 1;
( N( S+ n; {& b4 M}3 o- k' V# x' z8 Z: P/ S5 W$ H
%>
" P& Q6 ^9 {. n) M5 {# v6 |: Z1 Dtemp=<%=temp%>;
4 H  J) L8 ?2 }, h: f1 Cfunction changelocation(id){ 9 e0 D5 E+ o% I# u: @
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 , f. X. ?: I( h+ u5 w2 G# R/ u
var i = 0;
5 i+ y# m7 E. W3 G( [document.combo_box.city.options[0]=new option('-------',''); 5 E# k' _* K" K9 S
for(i=0;i<temp;i++){
: R" h4 d0 Q# X4 S% pif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
8 q* A' B$ K1 J8 W& bdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 7 g9 v& A$ [( B, j3 S$ \4 A
}
( W" v# m" p, Q1 `}
! J7 h" I, |5 V, i* p; W}
& _8 B8 u0 f5 b' ]9 v' H</script>" F) X5 Z3 M3 y( V

4 l5 Z5 b; D# z5 l% l<form name="combo_box">
. w* }8 c7 C6 S- {1 j6 \5 A* `<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">: j' K# c# h1 G( W
  <tr height="24">
; b' q' z7 @* B9 j    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
7 m* u1 E+ S6 _1 M7 E, y# v    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>5 ~# g0 r3 Y$ v7 K2 \
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>* D5 ]' _$ P  \6 }/ _  }
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
4 n( o3 o5 G  N- `1 V  </tr># H4 F* {* T4 q  N& V/ f# \
  <tr>
2 f6 k9 G/ {# q2 w4 E  i    <td>
4 h3 r. x' S. ~1 m+ }5 b. N  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">, _  u/ W) q; y  i- `# l" r
  <option value="0">请选择部门 ---></option>
/ F0 C; m! k7 j  `4 N1 v9 |& E6 K<%" p4 M' E4 B% H; R% c4 D) @. |
    string sqld="select * from tdept";0 _4 o, A, O) l4 Z1 j/ {
stmt=conn.createstatement();
) {, V# W3 }5 Wrs=stmt.executequery(sqld);
0 f" h: d2 t# N2 G0 Hwhile(rs.next())3 _9 }7 l6 G- q1 `
{6 }, Q  t" |; \/ h- E: {
%>8 F( c( \0 h+ E
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
) _; h0 v  [: G/ ^- ?3 N9 ~& u5 K# Z<%% F" S$ M7 p" E( H2 c
}
% Y* I/ P: y0 }) v; z. P%>
1 \3 }( t0 s2 I1 B( _  </select>% i; Y2 P7 @3 J8 E9 T+ \% W% S# f" A
</td>/ W0 v! U: ^9 T2 a' D+ g8 S
    <td>
3 d; z7 g: }5 l1 W3 M" C9 H  <select multiple id=city style="width:150;height:200" class="bgc"># `" J( q& Y6 n4 \3 B% x8 {
  </select>
2 p0 j3 M+ d# [& ]3 K</td>
/ k, X7 b' g/ P. z1 X8 d1 i    <td nowrap align="center" class="bgc">" J* C9 T, E$ }; k. b
  <input type="button"  value="<<" class="buttons">
/ ^( J' }( l* i5 q5 U  <input type="button"  value=">>" class="buttons">
. R+ c+ X1 g2 ^; @  J( ~5 M</td>
! E9 A. c6 y$ ]" B# D; {1 B    <td>; b. w) E$ g; y/ x0 V
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">* s5 x+ i+ X" c$ H
  </select>
. Y& W( ^  U- r- M1 C</td>) p& Y$ \  Y$ \) |% l; C/ ^
  </tr>
4 H( O; W' [9 U* W3 k% G  m* D; l; c    <tr class="bgc"> % x+ j9 z* F6 Y! Z- D0 m7 Z# Q1 P
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
4 G' I4 L( ]3 j/ U  </tr>2 _8 O' R1 W" F$ B1 g. [2 y
</table>3 O, V" I+ G' M  n2 d
</form>9 y4 W; w; N# ~6 ~/ L
<script language="javascript">9 z9 l( v) L) V( Z  p0 h
//人名移动- J) v* T( ^9 [; ]
function move(fbox, tbox) {7 X5 y7 H' ~4 A) N
var arrfbox = new array();/ M+ x2 C% F! }4 v, r; J$ U
var arrtbox = new array();
2 g0 n$ [: {+ [8 A+ F& W7 P+ rvar arrlookup = new array();
- Q4 F! E# e' q: F7 gvar i;
$ V! |/ t1 [  ?, J- W" Afor (i = 0; i < tbox.options.length; i++) {
+ v# E6 c+ X( O3 `+ barrlookup[tbox.options.text] = tbox.options.value;4 g3 j+ Q' H# M! q' }$ }
arrtbox = tbox.options.text;/ ^5 T& q/ ^6 M3 I7 s6 Z
}# q8 A3 i. ^3 |+ ~0 j
var flength = 0;( _$ L6 r" o3 W" h: m& p0 Z) A
var tlength = arrtbox.length;
* ^% M7 T9 \4 h0 v7 p' t9 a' Sfor(i = 0; i < fbox.options.length; i++) {& y* \# g* Q1 d2 k& ~4 J
arrlookup[fbox.options.text] = fbox.options.value;
% r! h0 n, N' N4 Rif (fbox.options.selected && fbox.options.value != "") {' p8 n, E. y/ l9 W. U- a- t5 @
arrtbox[tlength] = fbox.options.text;
; F- k! v2 K$ _$ K- \' xtlength++;
/ Y) X/ g6 P* Q( v2 I}
$ C& Q7 S, n. P/ n' _else {
- j; V( T# l4 k5 M% F9 W4 farrfbox[flength] = fbox.options.text;  ^) n% V# m8 }5 n3 W- |
flength++;+ J4 Y! K  V" @8 w7 Q
   }
' Y3 M/ D" x5 Q# S}0 ?! F( Z  S/ D
arrfbox.sort();
: C. F0 A9 E& E, U9 ~( Barrtbox.sort();
( ]8 M! Y+ j, n2 }
: {8 A4 ^) {4 I8 Wfbox.length = 0;
- x( E! [! ]7 a. M% T' m- _tbox.length = 0;
! h( V8 h' n1 A! Bvar c;
( g8 k6 {5 V  |( f6 }for(c = 0; c < arrfbox.length; c++) {$ {/ C, _; Z+ Q. j# ^6 Y! p
var no = new option();
: [( T' ]1 n! b$ E: `no.value = arrlookup[arrfbox[c]];# k, [1 j9 K" i% Y1 V- i0 l6 h) W
no.text = arrfbox[c];# V/ @6 r& m- q/ o! u" Q
fbox[c] = no;0 S7 s( v+ i0 S! Q4 [
}4 Z/ o  Q" V7 C: k6 \% R' n
for(c = 0; c < arrtbox.length; c++) {
" y, C% a# H# @) s( Z7 pvar no = new option();8 @4 Y0 d6 S# \" d- Q$ l
no.value = arrlookup[arrtbox[c]];
, U2 _' |# [6 `3 ^: c4 o' c5 kno.text = arrtbox[c];
9 T- i- L8 z- n2 H1 b, Otbox[c] = no;+ e; }+ z; B% y0 N" K
   }/ E9 [1 A3 H5 y% h& t# ^* a' [5 z
}
+ E( J8 ?  Z! }2 I3 I; R</script>! ^8 v5 R! {% A8 I: A, W
</body>
" Y5 S# a+ D# `2 ]+ g5 u) L. ]7 w





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