Board logo

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

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

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
) P4 V' F9 Z1 n; u         c pageencoding="gb2312"
0 K: {3 r' e2 ?+ k7 E( s6 D%>9 u$ H. T4 P7 @4 Q
<style>
8 y* ~& i# t, q9 K' z+ C- _& ^.f9{ font-size:9pt; }+ y6 t; p: E" b1 N# O$ y' q
.bgc{ background-color:#aecaf9; color: #0033ff }% U9 F* a& g) \! T7 _
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
- d6 C0 ~1 _. O9 y, ^/ p  c  A  border-bottom: solid 1px #4e7dc1;& b& T& q! c) F2 U+ o% T5 |
  border-left: solid 1px #aecaf9;+ V. C) R# r9 h! ^
  border-right: solid 1px #5679bd;
: w) n" A6 [4 t& j  padding:1px;
6 Z. s! Y! _* S* j5 u2 y3 w  margin:0px;}1 I6 G9 h2 P$ {- h: K2 S
</style>- S9 b6 U2 A$ Z7 j/ w2 D4 ?% f. W
<script language="javascript">
& V( ]( Z! j( i9 z<!--
: ]. h/ O: m! z; z2 I' i- Vfunction rv(); e( R. B6 M$ z/ i, }
{- R0 l6 J+ D! c
  var val="";( w9 S# P7 @, q9 {+ D5 H0 C
  for(i=0;i<combo_box.list2.length;i++){
0 N) |2 b. A( W; }7 t) ]   val+=","+combo_box.list2.value;
4 n! s( G: I. f( g  }
( \4 t% k( e; y  if(val.charat(0)==","){9 }  q3 `. g- F: g% \) E
   val=val.substr(1,val.length);
; ^- I- X! V& g/ L& A) B- e) G5 l  }1 o- c. V- M3 S! F
  opener.form1.frecname.value=val;9 V3 D  T- g% x$ r7 R- Z" X/ G& s
  self.close();
& a; V, f9 D, `}  E- r' |' c. I
//-->- r! ?, k1 p- y: r! _" k
</script>8 H% g- B( G; g4 o
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">$ W9 x& C! J! a7 Y4 s9 _
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
+ z  s: U" u* d9 h4 S<%
3 I6 @: R8 m1 n9 P+ Q4 V0 K5 |  cdatasource ds=new cdatasource();  //数据联结bean实例- _5 C$ l0 _# j/ [4 {1 b5 j
  java.sql.connection conn=ds.getconnection();
! s5 F9 w% H  d: i; Z; V  java.sql.statement stmt=null;
/ j" F9 }' {  Y  java.sql.resultset rs=null;( ]0 f0 W' _, O
  cdatacheck dc=new cdatacheck();
- T& [( E- y, t0 Q& J" l%>
% R9 [2 k7 @5 U& _) |; F<%; H. u+ |" m2 ?4 {
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";
6 P( I8 p( _5 A; y4 [0 N4 Istmt=conn.createstatement();% K% I7 m& W8 J) Y& H
rs=stmt.executequery(sqlu);% y, x! r$ h. H+ d2 d5 R. T
%># Z9 Q# }" x  G" j8 X7 Q$ `* f
<script language='javascript'>
, h, Q: @! |4 e. t# yarr = new array();
4 B) r) h; j' S<%  int temp=0;) ~' D+ N$ y3 P  F
while(rs.next())5 D: O- i0 A* P0 k; M3 o
{
; f7 e; N. ]+ {7 U1 v! C& [+ V%>/ Q# m% I. D2 L7 n$ q
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
) O2 w1 q2 d6 P# v# q6 Q# W<%
" D/ _' R. T' C2 [/ qtemp = temp + 1;+ m0 a% }. [. i0 f3 s& y
}4 C% F8 W1 R1 g/ X5 ]9 q7 X
%>: B- e6 X4 ?: U) o' P7 ]# A5 O. ?
temp=<%=temp%>;* M% }+ u$ E3 n7 @5 }
function changelocation(id){
2 G  |1 ]! Y4 ?- ~" \2 @7 ydocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 - R) |2 h6 [. o5 D0 {# M
var i = 0; % D" [- L" q. Q$ m7 y
document.combo_box.city.options[0]=new option('-------','');
) F, i$ `2 V6 c, r% Q5 lfor(i=0;i<temp;i++){
4 q$ ^" w6 X" fif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
+ _* I( a( W. ldocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); % E0 E. |& w5 h9 N
}
& N* w4 x; d9 e}
+ X% b; k$ J* ^; V/ o} 7 \" R  f, e7 _" V( g" }; p' ]* ~* z" S5 S
</script>
: e  Y) H+ ]& T/ S
. o  ?5 l, l- j( J7 Y! S' [<form name="combo_box">
6 f- B; @- s- W$ m! n( u<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">' N8 G( H* n  D
  <tr height="24">
7 {. K% x  ?9 T0 P- q    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
# M% E9 q" U. ^    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>( `- W" V* k% s5 ~) L8 S
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>0 V+ g( U- N, \" G  O+ N
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>4 e6 p% w9 |$ D, W* b
  </tr>
2 ]. A, T& q0 V5 j  H  <tr> " i; K/ w9 n+ X. \/ ~
    <td>" ~8 g) x; d% q- ]" e, k
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">) |5 B1 P* @* I% z
  <option value="0">请选择部门 ---></option>
! t) C# m* ?  P  L8 U; C<%
, H) l  r/ p/ {1 I/ s    string sqld="select * from tdept";$ J2 ]- e9 @5 Y# @, a7 L% k
stmt=conn.createstatement();* M; r7 z: l" q) _: Q! F0 Y' D
rs=stmt.executequery(sqld);# d. S, p1 K5 |" ]9 H
while(rs.next())0 p% @+ O; A3 E. k1 ]# q. s- U2 D4 D# D
{2 I. T" I3 s% ^: C3 `' k$ u" \
%>
0 q8 v4 w5 F/ B, s! U4 T9 F  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
/ t7 U2 l4 O. P8 ]' f<%
3 M9 X) c) M7 C3 I7 H  ]}
% e  i7 O! {# n%>
4 h& W; K& p, O7 m% D. F* L" Z  </select>
1 G- H6 ?, Q, N* N</td>
$ G# y: ?$ e+ q* m    <td>$ ~) C" l0 h9 f- ]; E) o% J0 J
  <select multiple id=city style="width:150;height:200" class="bgc">3 ~6 \7 y* E; X) J! o
  </select>
: v5 L' r6 |# F. X, m7 f3 d7 Y</td>/ F; s" O- q" P* H/ r" z
    <td nowrap align="center" class="bgc">
9 u& L7 K: O" w- j% q. V# J, h# ]  <input type="button"  value="<<" class="buttons">& [( z5 _% ?  W$ i1 I, Y. s
  <input type="button"  value=">>" class="buttons">/ H2 ]8 @* L5 D* Q. p9 g
</td>
5 T. Y/ q5 n: o2 @4 }    <td>
" C4 h( Q' V: ?6 @  f  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">% A, s, C+ A' j# Q' G
  </select>8 s" _* R" g& Q9 j4 Q) T8 `
</td>
( ]- X. N. a' O8 l3 J9 U4 h  r  </tr>4 C& \5 H3 N# ^' I( ^
    <tr class="bgc"> : b( p4 B# c/ w1 e: _! B
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
) s* O2 W6 Y& J1 d' k& T  </tr>8 Q$ C+ }  G7 M$ T
</table>
! F. r) L/ \. F6 u</form>
* [* z- v% r! m# p- I, v<script language="javascript">
- Q7 |  c# l; l- w& u' S' q: s* W//人名移动
( u0 d0 e* D  T/ M+ W  Efunction move(fbox, tbox) {- W2 }  I1 \5 ]* g* |5 j3 ~
var arrfbox = new array();- w# [! H8 T$ ^
var arrtbox = new array();
9 B: |4 K* I1 q/ S7 T5 s5 @var arrlookup = new array();+ G5 s2 }! h- ?) v  }4 p
var i;9 I: O% a/ X. ~) C
for (i = 0; i < tbox.options.length; i++) {& s. {" R' |: m$ Z0 _2 P3 S# P+ m- T
arrlookup[tbox.options.text] = tbox.options.value;
( I" {$ I4 w% d- ^( z3 Jarrtbox = tbox.options.text;
" j, D; D& ^$ P. {: k& x3 L; ~}
& k7 B! i2 k  U! T- ^! Uvar flength = 0;6 O+ \* g' l" H$ T$ O0 j$ O" i
var tlength = arrtbox.length;5 ]8 d# m. }# @4 \4 m6 o: ]
for(i = 0; i < fbox.options.length; i++) {6 S4 I% U. u* g/ k& [) n% D
arrlookup[fbox.options.text] = fbox.options.value;# Y! D8 C  R7 ^0 ?
if (fbox.options.selected && fbox.options.value != "") {
" J! I& b5 a# f# u6 Karrtbox[tlength] = fbox.options.text;
: {2 q! d! ~7 F7 J7 Y: ~tlength++;
8 m1 u, h4 Q. g}
6 u) R0 z$ ]! L7 G* r& O4 yelse {; T2 i: t. z# b, F1 _. p1 W, E. H
arrfbox[flength] = fbox.options.text;
  d& a0 w% X! _* m! p; R) I9 K8 {3 J$ lflength++;
8 ~9 d# W, S! `) T- Q. g' }   }
! X3 k' U" I% v& X* C# r& y}
( D' x+ _1 V3 ^1 f* i" {- barrfbox.sort();
- K; k+ {9 W; l( ~1 harrtbox.sort();: l) W! ^- N7 p0 o! q: U- I) q
1 K2 w  D& v" d3 ]( b
fbox.length = 0;
6 x/ c! y! X& e# ttbox.length = 0;
# [0 ^2 x% A, Z! ^5 l2 ~3 Tvar c;
$ Z" H, K1 v6 Nfor(c = 0; c < arrfbox.length; c++) {
6 I( s- d  o, Dvar no = new option();
: n( T5 }$ ^4 c" V. rno.value = arrlookup[arrfbox[c]];
- @# f# M( W! `6 ino.text = arrfbox[c];9 {# F! X) x" b
fbox[c] = no;
6 H1 }" n7 ?8 i% \}+ u  b: f( x; U1 p6 b& u
for(c = 0; c < arrtbox.length; c++) {1 T) c# _' ]: [" }" J( j0 Q. ]
var no = new option();# k; u* S- ~5 d7 A  E' l1 k" S
no.value = arrlookup[arrtbox[c]];
" S1 |4 o6 Y5 v4 P  a$ Yno.text = arrtbox[c];
7 o# {: H5 f* g/ @0 K$ Mtbox[c] = no;; x5 K! P, Q& {1 K% K# {! N
   }( _+ m% x. h: P+ y
}: y3 s7 k/ H; C, Z' l
</script>) v) s$ w( p) T, v
</body>5 P! q1 |6 X0 L1 E& o& Z/ t& C





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