Board logo

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

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

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"9 Z' k  a4 d2 t, j7 J# g
         c pageencoding="gb2312"
3 h0 ~* M  `' E# w' r6 b9 E%>
$ n& f9 L$ l; K9 q+ Y! C1 L<style>
2 D4 ]' d, p3 i8 D+ b, R# j.f9{ font-size:9pt; }. @7 @: k( t! n8 ?9 `" d
.bgc{ background-color:#aecaf9; color: #0033ff }% W: ]4 X4 R4 \
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;$ A' f; }+ K1 L/ |" i& S# Y
  border-bottom: solid 1px #4e7dc1;& h! g7 X0 h! q
  border-left: solid 1px #aecaf9;" x- }8 z9 m; g3 q) \
  border-right: solid 1px #5679bd;8 x+ T; y/ z% p0 m; X7 t  V* m
  padding:1px;3 @/ j9 J# H+ H) a
  margin:0px;}
8 B& @# u- Q3 E7 G- _0 n! m: P- b. I</style>( }7 l3 s4 v8 z, z( {; e, v
<script language="javascript">
# h2 Y: R: A/ I2 f. Y( ^" q& T. u$ O<!--
3 Y  h; K' ~* n; zfunction rv()% n0 M- h/ i# e, _) B
{
. g: C* ?; t1 D6 h6 f  E) S* Y  var val="";
8 m) ?9 n# o4 p1 J$ G( m# e  for(i=0;i<combo_box.list2.length;i++){
  e; Z4 A. a& S: |" C5 s   val+=","+combo_box.list2.value;0 ^# \) W( ^: j
  }/ L' H  }' s( g! b* A, o
  if(val.charat(0)==","){, ~9 G# t# p% G! W5 u! [8 [
   val=val.substr(1,val.length);% q) n5 n7 a3 `( r$ e
  }
" y  p- B( U3 ^, K  opener.form1.frecname.value=val;; [, H0 C& e" n6 f5 c& M$ n
  self.close();
5 \% S5 z+ e) z. z5 ?, R1 K9 ^* z}
, {6 b7 _% \3 c0 X4 ~, Z% N//-->( O$ ^8 Y/ T) ]  i) |
</script>
% _( d) F. N; J1 i  H  S<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">2 W+ Z0 @/ \! v! C% F
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
* _2 a) T' K8 {' S+ T, p4 u<%! _* V- c( r, L8 u' u( H. y
  cdatasource ds=new cdatasource();  //数据联结bean实例" R6 Y, H5 R$ o9 a
  java.sql.connection conn=ds.getconnection();
9 w* a) q- \+ [+ ^- ?  S  java.sql.statement stmt=null;2 E4 k1 e3 |( [. v- W% }4 l
  java.sql.resultset rs=null;$ y6 g% ^' L- l' G8 q1 k6 U' Y
  cdatacheck dc=new cdatacheck();0 S5 M0 P. W& n5 ?$ j1 I1 O1 m6 b
%>2 a  k: }. `% S/ H- o
<%9 W0 J0 w% I  g8 w7 v/ p
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";
& G6 G& U9 \# bstmt=conn.createstatement();0 ^( B' J  Q% m' {2 O+ b
rs=stmt.executequery(sqlu);
& ]+ {8 M- h* a( P/ l8 t( C& ^%>8 ^' j9 r* U9 f; U
<script language='javascript'>( {, L7 K) D6 g/ b' N0 T1 r
arr = new array();
: \8 S/ a( Q) `1 `  Z7 ?0 Y<%  int temp=0;
6 x  V5 E) X# W- wwhile(rs.next())6 n) n0 o) w" g7 G5 x  `5 e
{
' p2 G: Y7 m; d3 K0 l%>
& U1 |) c$ d; v# J1 ~6 h8 P- _arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
& j1 n& ]: I! c7 U3 K<%
$ O/ |3 }3 W$ y& ptemp = temp + 1;
2 o1 c3 B+ Y# J+ ~}( A5 u" V8 P. a% L) A0 X4 N7 f2 n
%>
3 C5 R2 D6 B' |3 y7 }/ Dtemp=<%=temp%>;
* M7 a6 b& b" W6 e2 Rfunction changelocation(id){
2 I4 k" S% N2 e. G% Tdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
4 ~7 y9 O1 h8 o7 z7 g4 Y; a, Ovar i = 0; 8 o. S0 {* r" M5 A2 C7 m. u+ \
document.combo_box.city.options[0]=new option('-------',''); . W3 l; p' l, @% U6 l
for(i=0;i<temp;i++){
: Q8 x3 g, q) C3 @' T  xif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
% T  X2 B+ J% k/ @+ _4 h) tdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
  Y1 a3 l1 \1 j: e* I2 P} + q7 ?7 h1 G9 W5 G! d. H7 T7 l" Z
} ) w. _# A4 W- _9 q, J5 z& P6 ?! Y
}
& }3 ~) Q: I8 |9 W+ t</script>
! n# `) f) y* P& l* i* R( H7 f4 e- j8 M4 \$ z8 \  y4 w
<form name="combo_box">
' e8 ], L+ Z/ ^$ T<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">5 l4 B4 r+ w5 M- o+ ]
  <tr height="24">
& G8 u7 y, ]' h, t2 j    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>; y* Y' E* t8 n
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>4 G6 v1 T; R+ y. |# E1 E* S# A5 P7 ?( c
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>, q# r# A' V8 I# X1 @: a. E
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
4 y8 _& [% w; V: P3 @5 K/ ^  </tr>
6 g/ U5 t$ z) @; h0 H  <tr> 7 i9 u3 ~" L9 \1 l; H: T1 U) Z) u
    <td>( ~8 d1 b: n% t# {- k
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
' j* a* \6 c! [" [  |; Q0 s. f  <option value="0">请选择部门 ---></option>
" `5 l3 X" D" I+ i, [1 M4 L<%) n6 `" w$ P: @- s* ~& E! O" P5 w/ s- g
    string sqld="select * from tdept";: \( w+ a' j9 d/ Z
stmt=conn.createstatement();& q% O5 B! k# i) |
rs=stmt.executequery(sqld);
) V9 M( g  E) T: W# B. Vwhile(rs.next())
7 ~0 @' ~! S) p" j' _0 S/ J8 l{6 ]+ h0 w( p( i/ {2 Q
%>
) M  |1 j$ H' A3 \* t( l/ Y  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>2 S0 T3 s9 v; A$ S! J& I; Y. N
<%
- J. j9 k8 c: }" [# j3 p7 |4 h" S0 c2 t}
' @6 U* h( e4 ?1 T, ]% l* P%>
2 c" H# u- P% A/ R  }1 B  </select>
+ k3 l! v- Y% l7 J+ e</td>$ G4 {4 z2 i/ `8 [3 [) d
    <td>
; @- S  M4 [9 P# D' t4 k  <select multiple id=city style="width:150;height:200" class="bgc">
7 s0 s9 E0 q2 o* w8 P( L  </select>/ ^6 k7 y1 B% Y5 c
</td>
$ F3 @3 L* _( ?" j9 m    <td nowrap align="center" class="bgc">! H- \3 ~! h; H8 G; C2 w! I
  <input type="button"  value="<<" class="buttons">8 R& Z8 C/ u, C
  <input type="button"  value=">>" class="buttons">/ h2 T) \9 H0 S5 i4 u; \
</td>
$ x8 V* q0 n5 e" M1 f    <td>
( o( K* q4 L. E- a0 V  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
9 I6 Q' Y0 C1 @  </select>  Q5 X, `1 {1 e+ t5 O6 k
</td>' ?7 Y* B; {. Q, l; K, h) O% U1 [( J
  </tr>
& ?& E% W+ t5 m+ a    <tr class="bgc">
: e) z; D+ P7 @    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
3 O; v) _$ |) t  </tr>
6 J2 m9 ~! B4 y6 A4 y</table>& Z( |3 O& C1 S
</form>4 s! r+ l7 @( l: O+ L! _
<script language="javascript">: q/ a" i4 P3 }
//人名移动5 V6 a# v  V% @, r' s6 e- t% M
function move(fbox, tbox) {
/ ]$ F' `5 C, t; @* pvar arrfbox = new array();
# s5 {) Q  d  i# H- Zvar arrtbox = new array();+ r, E, q  H2 e5 }
var arrlookup = new array();! q" T: u5 C7 }. g
var i;- \. Q8 Q( K+ v" ~- m# ~
for (i = 0; i < tbox.options.length; i++) {
6 P! _0 i$ q- N+ \( X9 j1 L9 N2 Harrlookup[tbox.options.text] = tbox.options.value;3 m% f8 Q- z. [
arrtbox = tbox.options.text;& x. B) m0 A8 Y# C
}" L. M8 a2 C' b$ Y9 Y" Z
var flength = 0;4 ^3 _+ |3 @' L: G! J) v: {* m9 m( q
var tlength = arrtbox.length;, O' ]. h3 n0 u8 x  y, f
for(i = 0; i < fbox.options.length; i++) {8 O3 N, e/ D% L" V5 M
arrlookup[fbox.options.text] = fbox.options.value;. c. j, M* Z/ t. \* L
if (fbox.options.selected && fbox.options.value != "") {
" m& X/ }' N7 s0 G. harrtbox[tlength] = fbox.options.text;$ o# Y6 q- a0 p0 S- |  `
tlength++;
1 l2 L6 n. p$ s}
3 d; D# A# M0 g+ `" j: X+ Kelse {2 A+ E- |4 f* }: ?" a
arrfbox[flength] = fbox.options.text;
% d9 N$ b! D& {/ T; sflength++;% o5 `* J5 f' ?& Y* C% j
   }1 v2 j/ }3 h* g- ^+ F0 u$ P1 K
}
$ c+ H7 I6 r4 Q: J9 e% _7 _4 larrfbox.sort();
7 Y4 T% s  D3 N; o4 zarrtbox.sort();7 z: M) v  L4 D) ?% F& v, f
- G+ Q8 O2 o+ t* j, B. M, E
fbox.length = 0;
2 t: I' A7 f' E' t0 r8 r$ vtbox.length = 0;, P" c" A+ f9 |0 c
var c;1 L, A. f; x4 O. z# I
for(c = 0; c < arrfbox.length; c++) {
- A- H8 P! |) `# uvar no = new option();
8 {; E9 M' e# p' Q/ sno.value = arrlookup[arrfbox[c]];
) B6 D- c0 P$ @( W' u1 f/ [- t9 o  ]no.text = arrfbox[c];
6 `7 t" f  K0 gfbox[c] = no;
4 M6 {' O$ P. D  ?}
$ L- Y/ K& l9 wfor(c = 0; c < arrtbox.length; c++) {
7 e- ~. Y  S, Q" Vvar no = new option();
! j+ M: R+ D2 I( Dno.value = arrlookup[arrtbox[c]];- h' v0 R/ ^* t  ~
no.text = arrtbox[c];
; s) Y) \% _2 K% z+ `$ E1 T, Ltbox[c] = no;8 e* n  V% E" y3 w$ w# \
   }4 P. U& j% V# o0 e' Q& H- T0 b
}
+ S+ l  n! [" p' d6 N9 o3 [; S</script>* D/ T% K/ p' b! Q- l: ^2 s$ T
</body>- [9 _) c/ G3 D8 m





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