返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;", n. q5 `$ r6 u4 L" n
         c pageencoding="gb2312"
. N" X2 Y/ H5 j8 M2 U2 H! y%>
5 ~: z. ]0 t$ }<style>" h+ m; |( m8 A$ N" C( @+ r
.f9{ font-size:9pt; }
9 `4 `$ L* u% S6 g1 V5 T.bgc{ background-color:#aecaf9; color: #0033ff }% j3 o6 D: `1 k: p% `0 Q+ E/ ~0 K; H
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
7 A) p$ s$ P1 t5 p* y  border-bottom: solid 1px #4e7dc1;- k' G! Y+ S: K+ n: o
  border-left: solid 1px #aecaf9;
' a. @% L, l6 z  border-right: solid 1px #5679bd;
. l, m% R" l5 _% e  padding:1px;( b/ Z' Z) y) X$ e2 w/ e% h
  margin:0px;}
$ W* l8 j* y* H, m+ v( `</style>
% E/ ~+ S+ A: C2 }4 v6 v<script language="javascript">* A) X6 L+ p7 z& s7 Q
<!--' F" d0 e5 O" \; U) \1 n5 x8 N
function rv()
2 h0 q" U: x' }$ D$ `{. ?2 `' N  |0 M, J6 D0 F
  var val="";9 s' s# {2 D- b( [4 k5 `/ t; R& m" d
  for(i=0;i<combo_box.list2.length;i++){# Z% i* ~  e( L' y! F' K  p1 N2 ~: W
   val+=","+combo_box.list2.value;( `0 w6 y) B0 N. Q
  }
; s$ V8 i4 {# [/ [* j4 H  if(val.charat(0)==","){
4 M" `1 U- ^; }   val=val.substr(1,val.length);
1 U& o. e# u* U* g# K% v  }
6 J2 L* g7 F0 _' v% W( ^6 [  opener.form1.frecname.value=val;
, z; d! G0 e" {# }# p2 F7 N  self.close();* H1 C" j! Y% j. u+ K& O1 Y
}6 V5 ^) X0 g$ J5 p: p
//-->+ A7 q7 O# T* l  l9 X: X
</script>9 M  M6 l! e- z7 ?) w1 _
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">* B4 n& `  e' ]) E" b5 [3 u0 j& j. b( u
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />/ ^, I) b$ A9 j0 D
<%
5 y% _7 x+ z+ ^1 [+ b6 G  cdatasource ds=new cdatasource();  //数据联结bean实例
% `+ `; H/ c6 a6 n1 @% h2 |% R  java.sql.connection conn=ds.getconnection();
: b+ E7 l9 b+ j. y0 S  java.sql.statement stmt=null;1 E* V/ G# _; E9 M: B
  java.sql.resultset rs=null;
. J5 R% B  e, C/ K  cdatacheck dc=new cdatacheck();
' `' t1 O- k* N8 y+ @5 V' a%>$ {% Z' O1 K* F
<%. P- y5 P3 A: ~) D. d
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";
& S7 I: i( W7 Wstmt=conn.createstatement();- L) @* K- s% h, i) k8 _: x# s: b' q
rs=stmt.executequery(sqlu);* _3 M  p$ F, M% q' Q* r+ |
%>5 Z# S+ c- x% @0 J: S6 @" O' d
<script language='javascript'>
) ~- d! }6 o: T, S- z; D% Xarr = new array();
( i) X+ H: [: ~* ~% M<%  int temp=0;4 X  X" ~# D) N, }
while(rs.next())
4 e5 y& @* _- P: A$ s' q# g{
& v' k/ B6 e' L; X%>
2 W( _! U! o$ Y. jarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");6 M6 l% p% v/ b6 C
<%" h9 l/ F$ U; @4 T3 ^# L; L% e- K
temp = temp + 1;3 J# U5 t& L& ]# l0 }
}
7 l$ F* L7 l0 a$ [%>4 s/ j# p7 y1 W8 ?+ E5 m
temp=<%=temp%>;
" E2 R  M& D' m7 U# cfunction changelocation(id){
. I, O" K0 R& b1 k* ~document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
1 `& V, Q7 T! y' ]+ Evar i = 0; ) Q& I9 _+ O! B4 g: I( t
document.combo_box.city.options[0]=new option('-------','');
* @, x9 q: C. m6 j/ ?/ Q- r. rfor(i=0;i<temp;i++){ 6 M/ C3 y% S7 l5 T% D% _' T2 H% ~7 ^# z! C
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
$ U& N  c" }8 W. L) Qdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
2 M$ m2 S6 j, G! Z! A+ E}
- F. D& Q+ p3 ]1 C; f/ D2 j: }$ g}
' e' K& ?" W- [' l; ~}
9 x  G8 J8 q3 S- C</script>, V/ l9 O9 H; r4 m& }5 G1 a
* ^* q) N  ]9 J5 ^* K
<form name="combo_box">4 G( |4 ~1 \! `. R1 a- D
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
) r$ _: _" @/ E! E" D$ j  <tr height="24">
1 \" L* ^5 b1 k" d- c8 I9 w7 v# @( {    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>1 r, A# O2 r1 r- B2 B" L$ r
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
! c/ ?) a* Y/ e" {$ A& G    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>+ a% |% a8 f+ }, W: \' g" t
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
+ U5 [) x4 ?$ {, ]  </tr>
& F3 v/ Y# D5 L- u% ]  <tr> 8 \3 n, I: e, D  Q2 d/ n; @
    <td>
5 |* b( y' I4 u2 m. |' X1 J  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">4 |% I, _+ L% R; D. N
  <option value="0">请选择部门 ---></option>
4 Y! s5 ?' j8 H, T& e( L. N+ F<%9 b! y4 I' l  l$ s/ S# w, I
    string sqld="select * from tdept";
* t  [' O, n8 Z) O9 ?; ustmt=conn.createstatement();
) Y5 S# M0 {! T9 \rs=stmt.executequery(sqld);
4 K, d/ F7 i  ?8 j8 s  mwhile(rs.next()), w% W' r7 T6 k5 P1 x
{, w4 _8 X5 p' X0 @
%>
% }1 F3 f8 c/ w/ \5 x4 w  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>6 j- Y+ e1 G: U' K! h! ]  k
<%: E  Q( O2 I4 Q0 S4 ], h2 ?
}3 j9 o# V' |- n" ?- h5 k9 B& m
%> " y6 J; s' U  n) {5 w) S" c2 b
  </select>+ D9 C7 D8 Z! x; R) p9 v) S
</td>
* f1 E3 K( z% m& U7 e1 ~, Y2 a  W' t    <td>$ M3 t( k* i$ t0 v# \; C! E# [
  <select multiple id=city style="width:150;height:200" class="bgc">
! D$ \( V# v# U% v; @  </select>
( W  a3 g  Z8 G7 D</td>3 j; j2 A/ Q  n) y: x
    <td nowrap align="center" class="bgc">' {# |, V4 F3 g
  <input type="button"  value="<<" class="buttons">0 O1 P( M  `% y! S6 ^0 n2 j
  <input type="button"  value=">>" class="buttons">) C; r. T; m" O2 K* k( G
</td>. b! X9 ~' [2 v5 u. A" _( k2 t7 F
    <td>% r' q: v/ h) s7 E
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
- B. g* O% ]: X+ V( O- X! s* Q  </select>) O. l! J6 m; @. S  {' C
</td>% f6 j" a' I, s* u4 e
  </tr>
1 I' Y* t" d# v3 k    <tr class="bgc">
8 P" [, J& a+ d" Z, b    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>6 Z. R( u2 W7 ]0 k  d
  </tr>1 ~" U: |* v8 f! I& @8 L# D6 E
</table>
+ O8 L) l6 J9 {3 o, L& g</form>; D0 S! C9 m( z" [
<script language="javascript">. b# n) y4 J( n4 l2 T. O
//人名移动
$ Q, N# {/ I# h# \. @. w0 lfunction move(fbox, tbox) {4 M. W+ n9 a: |9 S5 P, X1 z  o* V
var arrfbox = new array();8 h/ m3 \1 d- r; d- G/ W& d
var arrtbox = new array();
) t' v1 Q: h  w/ i2 P' E; J7 Mvar arrlookup = new array();
; Z, q# _/ T6 P1 T6 Uvar i;
8 e/ r! q. c! l- }0 v" rfor (i = 0; i < tbox.options.length; i++) {
7 v/ _: W! F- |! i% K" barrlookup[tbox.options.text] = tbox.options.value;
5 s; Y+ N1 k" B$ ], [arrtbox = tbox.options.text;! }# B! g8 s) V; u6 i- J' W! ?
}
1 d. m8 ~: G: X/ Mvar flength = 0;" \2 N; p6 A) }; C8 Y
var tlength = arrtbox.length;
$ K- v8 I, B* S7 i8 A4 c1 c0 x5 I! yfor(i = 0; i < fbox.options.length; i++) {" {! g7 O9 ]2 y% O, C
arrlookup[fbox.options.text] = fbox.options.value;
* s* H/ @% ?; @if (fbox.options.selected && fbox.options.value != "") {
* g; L8 O" K; |2 n6 h: X4 ~- Narrtbox[tlength] = fbox.options.text;& X  n4 w3 @; u( q
tlength++;: P6 l1 v2 H  ?. u, g0 X
}8 e; H# \, u! t
else {
4 v" @* r  l, F8 {3 A. Qarrfbox[flength] = fbox.options.text;  G0 N+ w8 w/ [9 A+ q( }/ V
flength++;
+ s2 L8 V: }  M   }
/ t7 _" M- h. S$ i9 g}
9 @* W/ {) l1 p9 z2 C9 [6 N* Larrfbox.sort();8 `3 \8 @* x: b
arrtbox.sort();
+ ?/ ?$ h. g: W7 O3 \$ M+ R, [
' L9 G# Q7 `. d3 {fbox.length = 0;( k% X/ V6 I+ z" p: \+ O( U
tbox.length = 0;! l& {4 [9 E! O* O6 R. G. |# x
var c;
. r: e) h0 ^- g' B8 V& u- Lfor(c = 0; c < arrfbox.length; c++) {
  d% N( \) p; }' wvar no = new option();; B, @' |" d+ w, t$ j) t  ]* |
no.value = arrlookup[arrfbox[c]];
9 K$ E7 p* q/ gno.text = arrfbox[c];1 X, W9 s" c7 l2 L5 {6 w
fbox[c] = no;1 q, u, U; W# `5 s0 \. J
}
5 T* n) }: b5 n$ Q$ Sfor(c = 0; c < arrtbox.length; c++) {
% K) T1 _( C9 O2 h" ?' Pvar no = new option();
* n6 G4 J1 [( g* s5 y0 o: m, f: |no.value = arrlookup[arrtbox[c]];
$ [( K) o1 H: Ino.text = arrtbox[c];
  }! T* B; x# |$ ~7 xtbox[c] = no;
7 W/ n5 B: F; U4 M& G   }
6 Y$ z" V( [$ ]}
( e  R& P# @& r! x0 z& V</script>, W) o+ {1 X0 u" o; e1 k. {
</body>
; \: [- Z" R/ w, r1 r8 q& B# Q

返回列表
【捌玖网络】已经运行: