Board logo

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

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

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"4 F1 \! o# B* ?5 `* B
         c pageencoding="gb2312"
2 _! F7 N( s. L" p; ^  N%>
6 Q: O+ e/ O8 S( Q<style>; c3 [5 L# A- p
.f9{ font-size:9pt; }/ Z& I7 C6 Q5 Q! `1 N0 R5 q6 s1 {1 K
.bgc{ background-color:#aecaf9; color: #0033ff }. U/ E1 V% M6 l3 w" C
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;  r5 v* f* N7 |5 _
  border-bottom: solid 1px #4e7dc1;
$ ]" n% F3 x. t2 h0 n" a  border-left: solid 1px #aecaf9;3 v2 C# ?9 D+ W  c: U! {( U, X
  border-right: solid 1px #5679bd;% J: A* _+ t! K) [2 ~
  padding:1px;9 F, p& t7 h" H) N0 S1 q
  margin:0px;}4 X4 Z/ E& _7 ]. t+ m0 {
</style>
$ l; v$ s9 j; }, `) ?* N; Z/ Q2 g<script language="javascript">
+ c( A3 G( r" z) m<!--
3 U0 x# }6 n3 W7 T5 ^function rv()0 F& c# I7 G- D5 c
{  x. o/ d$ _! X
  var val="";( V! X3 V+ V) L3 j8 G* e
  for(i=0;i<combo_box.list2.length;i++){' x2 Q7 d& A2 {5 ?; p* \  ?
   val+=","+combo_box.list2.value;
* j7 F! r* O3 d  Q" x1 n1 s  }7 V- c5 S( O. {+ v0 ]6 j# ]# C% G
  if(val.charat(0)==","){% ~! t/ {* K0 d* ?: e$ W2 [# I
   val=val.substr(1,val.length);
% H5 s8 X2 Z! I2 a( P& y  }4 l( C/ Y8 P: V" `; x# C7 f+ j( ^/ Z
  opener.form1.frecname.value=val;$ q& X4 D* J$ T: r" O$ D, y
  self.close();4 ?- U: _' C5 F3 Q9 M% r) o. w
}7 z1 j. _+ K8 s: k7 J
//-->8 T8 `; u+ i/ z( ?& d7 \3 ]
</script>
" v; Q+ Z' R) @9 a) E<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
1 F0 w* k  M! s6 W2 {9 k* e<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />) e4 e8 G3 t: P* m$ E
<%
$ o8 ~3 b9 H! V; ^0 N# g! v* v  cdatasource ds=new cdatasource();  //数据联结bean实例) q( K# b7 [) n; t
  java.sql.connection conn=ds.getconnection();
3 H! g. A# |( H9 d  java.sql.statement stmt=null;  ]% N, Q" C# I3 N$ y, M
  java.sql.resultset rs=null;
2 o6 N, Y# P5 [! i: P' p5 e  cdatacheck dc=new cdatacheck();6 v; G& q. I# E' K" }
%>
8 a8 d! H, `% n7 v# o<%% O9 j; s3 m& O+ k
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";
0 E; l- Z% b6 _( x+ @' G1 @stmt=conn.createstatement();  T$ [/ j/ n6 S
rs=stmt.executequery(sqlu);
+ P& \. N9 P; N1 [! F6 _; s$ N%>9 ]1 z  T' I1 G- v% z9 ]
<script language='javascript'>" x1 f) E6 l" _
arr = new array();
* p; _7 }2 V: Y% p3 n<%  int temp=0;+ G/ i0 h2 g5 I* V
while(rs.next())
6 K, E" {4 Y+ v0 V{: S/ N6 }3 J, p, u% Z$ Y9 }
%>
& e: w4 b8 h9 K/ w! Garr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
7 l+ p& Q% E; \! @<%
1 |* \& [: Y! j: z5 {temp = temp + 1;
* _( [0 t! @" ]4 @, G# W}/ y# W3 n0 m" u
%>! L. Q5 z; s% L" x
temp=<%=temp%>;8 ]( d4 J* w/ k# y. V1 b/ F
function changelocation(id){
4 L. v; V/ V# I4 h, X+ k$ i7 Cdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
; D& G# V( q6 f8 m) |& [var i = 0; , ^# v) r  Q7 C
document.combo_box.city.options[0]=new option('-------',''); 9 d' {% F- R4 R
for(i=0;i<temp;i++){
; \; R1 p$ z) R0 u3 i- Sif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] * J3 b. J' W. f: D- n% X6 G, |! V/ B. c
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
: ]$ }# \( I8 s! g} , \0 i; }5 M) ^! A2 f
}
' d5 v( j% D; r: _1 k( m2 S} * d/ I9 N  P2 n* Z1 G% o0 h3 U
</script>
5 z+ q; T* e% A. y) {5 T
+ J8 p9 Y$ n/ G- b! O<form name="combo_box">, S9 j5 c6 ~# J) i" q7 S4 H) v9 b$ ]& @% n
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
  ?9 z% P5 q: o% u0 U# t  <tr height="24">4 @7 Y8 M8 g* Y' E6 A
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
% G  `" v0 u' c" ~7 B8 n    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>) h8 ^  s3 b6 N
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>7 w) ^7 V: i* |9 g! a/ s
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
. ^; z1 f. B3 f* v" V% s  </tr>& k: O5 q/ s, ?) C. R
  <tr> : v, I  ]8 y# b1 X! B
    <td>  m) f, e& `+ `" d4 a
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">5 |, h, e1 N0 |) B
  <option value="0">请选择部门 ---></option>" I' C; h# D+ l6 _3 p
<%3 a; G) ^- ]- S4 X2 u
    string sqld="select * from tdept";  L! T+ H' p& }% H8 ~
stmt=conn.createstatement();
# d, h8 ]1 e% y% U, K) ~1 J2 m7 f5 Vrs=stmt.executequery(sqld);( C* W; @) R9 |4 P8 s
while(rs.next())
% O' r3 R' v9 D2 N) C2 i" [{
: i% k1 V! I7 g( a7 ]0 g%>
3 W! b0 F; ]+ A4 @  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option># k( z% U" O$ j5 L/ f2 ?% _/ l
<%
  l8 |7 r) j- d5 a& Y9 s/ ^}
% r) @7 a* t. [! a( e8 F%>
7 u$ |& A$ H$ a1 |  </select>- D# r, O0 Z3 M4 w9 W
</td>
0 D$ H, N3 ?7 O' w5 @# T/ S    <td>
" b0 O$ A: @9 {5 K  <select multiple id=city style="width:150;height:200" class="bgc">
$ Y) B! @/ g8 p4 |- [  </select>9 [$ R/ E% q8 `& H
</td>
: X. j) m& f. q7 i' b/ ~8 P    <td nowrap align="center" class="bgc">
6 w$ V3 l% }$ g2 d  <input type="button"  value="<<" class="buttons">2 d' Y1 Q" i# n/ P# ~" N6 s) D
  <input type="button"  value=">>" class="buttons">$ P0 a( r) a& t+ ?/ ]
</td>
, g- m+ a1 L% J" K- e9 w    <td>. c8 i- ]! W4 W0 n) T
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
- W* H, F$ D9 A0 H  </select>4 \7 T) z# }3 p+ e; f* X- j, H% Y' S
</td>
; P" r) @; S! J( x  Q0 j5 F  </tr>0 U1 e  a; x' m  t5 B; U, h) n& ^/ T
    <tr class="bgc">
6 o6 R7 M3 X9 X% I( V4 I, D, U2 r    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>; R' c! c" B2 B% u% ], l
  </tr>1 g  f/ S" a& I2 D6 ^) g
</table>1 B6 d2 v/ Q, a/ o( u  c
</form>
6 b* `4 b+ `* B% E<script language="javascript">1 j$ q2 E) s6 y* c) z
//人名移动
9 M/ i' @4 B* pfunction move(fbox, tbox) {
4 g/ T6 {& O) s0 p; X# Jvar arrfbox = new array();6 `/ x8 S5 {; B, T* E
var arrtbox = new array();
2 j3 q$ a! S# x9 C  Gvar arrlookup = new array();+ C- r1 Q" f4 K9 l5 z2 |  Y
var i;
' A# J- P9 Z' ^+ k& n9 t7 ]for (i = 0; i < tbox.options.length; i++) {
) h$ N  j; N0 varrlookup[tbox.options.text] = tbox.options.value;' x% l! S6 e" `% m% f, f9 p$ L
arrtbox = tbox.options.text;
& `  ~9 F# p. h0 b9 D6 y. R$ W}
; e6 Z' D; v+ o" K' K* ^var flength = 0;
/ m8 I; n3 y' S: z8 |var tlength = arrtbox.length;: m. V& c4 C  s2 x( e
for(i = 0; i < fbox.options.length; i++) {  t- {4 v" a: q  d" w
arrlookup[fbox.options.text] = fbox.options.value;
6 m  L5 q2 B  c8 P( Dif (fbox.options.selected && fbox.options.value != "") {9 H8 S1 r0 H! l( Q' E* i* L( I1 U' }. J7 I2 V
arrtbox[tlength] = fbox.options.text;+ M3 T  x; E9 f! }9 ]& ?+ m) b
tlength++;
/ a% m8 }6 C  t- G9 s* g; r}; b0 W9 d" o8 t, b! ~
else {( R# f7 z! Q9 D* {1 |  e( Z
arrfbox[flength] = fbox.options.text;$ ^( C4 r# F/ R2 K" J8 \8 I2 U
flength++;
/ R- F# R  i6 [* b   }& I2 q' A2 ?9 ~. o+ {8 Z
}
$ i% b5 R. o* U# n% Oarrfbox.sort();3 x3 T# N7 ^4 y. R. ]! H1 y
arrtbox.sort();3 y' C  q* F5 B/ d0 D+ O3 J
8 l1 z8 L2 B( F3 z- G" H5 g
fbox.length = 0;
- [+ K( h, H# K% U- U8 h% x, Ctbox.length = 0;
; e" P( v/ Q1 u/ H* Nvar c;+ i6 _, ^" z* \& M
for(c = 0; c < arrfbox.length; c++) {! l% r- Y9 p- g( P( j/ A% G
var no = new option();
2 k6 H6 R. R$ x' X( ano.value = arrlookup[arrfbox[c]];2 |9 n" Q1 q5 s9 T& x/ i: J, W4 D
no.text = arrfbox[c];! x! h  m+ {2 d7 Z5 ^$ l/ u. O
fbox[c] = no;
+ _% h. v: M+ h( F}+ |' U6 T$ _2 ?8 i* E# C
for(c = 0; c < arrtbox.length; c++) {1 q% s8 `' b  q9 v+ Z4 Q
var no = new option();, |. I- e8 n7 a4 s
no.value = arrlookup[arrtbox[c]];' L; K* O% t9 _* `
no.text = arrtbox[c];
, r0 L  a; Q! \. W1 E  W% Etbox[c] = no;9 w6 w( g& L* Q
   }) `2 D5 W- D: D
}4 _8 k0 @0 B: j$ n) X; d
</script>
; A4 V9 O4 d( U" p( _; O# _; L</body>0 i, p. o0 j  ~( r





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