返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"( m4 j7 }4 G; s6 G) ?
         c pageencoding="gb2312"
! M) @4 ^9 \2 A' A% W3 a%>
; Z' k7 B+ P3 U9 U( G<style>
- d9 \: R- s9 y( ].f9{ font-size:9pt; }- ^9 \$ Q+ F) b: y9 V
.bgc{ background-color:#aecaf9; color: #0033ff }" B2 N. S" K8 ~2 Q, g0 f
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;4 F# m3 y5 S0 A
  border-bottom: solid 1px #4e7dc1;
, r5 [3 Y! A% j5 S; u  border-left: solid 1px #aecaf9;
& H2 y9 k; Q3 \8 ?+ X% T; D  border-right: solid 1px #5679bd;
# M/ H, e+ @. J  padding:1px;  |* Z. m8 k+ j+ A/ k6 E2 v% n) T
  margin:0px;}
7 X( M; Y: m9 D  V' I$ |</style>! P0 o- O+ m5 R7 n# P! ]0 |! x0 z
<script language="javascript">
1 s7 G& R' a! Y<!--0 H& D: R9 u1 R& g' O! \5 f
function rv()
5 K! M* Y. Y% e. v0 A{
" w" Z) @* {( X  var val="";: P' a/ d# f3 M: {
  for(i=0;i<combo_box.list2.length;i++){
& h% {; I: ~: J   val+=","+combo_box.list2.value;2 R$ s- n. d4 W2 k
  }- L5 C$ P' ~5 N# l; V
  if(val.charat(0)==","){
$ S( E' }) _! x( c: D  U   val=val.substr(1,val.length);
+ \. m" e8 y. }9 Z9 ~  }8 J' n& Q6 [0 n" D3 u
  opener.form1.frecname.value=val;
  `, e: |  E* L8 g! u  self.close();
% {1 n; b. V6 @1 b}  T" v; m+ h$ W& w1 _
//-->2 z  ^( s( [3 G  ?1 c, n/ ^
</script>
* j: G  Z* i8 I+ Y4 i$ v<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
& Q8 r& F0 V6 d: ^( {4 w' s<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />7 V, \# U5 [, ?5 D9 T) P1 Z- u* D
<%" w7 F4 V; h& K# r+ k0 c" j
  cdatasource ds=new cdatasource();  //数据联结bean实例
4 P' L9 D/ U( X3 B+ I  java.sql.connection conn=ds.getconnection();
: v4 O6 l7 _# R$ I  java.sql.statement stmt=null;$ i0 [! T8 `" E+ b: U0 g- t
  java.sql.resultset rs=null;
1 _$ [! g* K4 B  cdatacheck dc=new cdatacheck();
1 ^% M5 P3 ?/ Q, d%>
8 w7 ?4 R$ n- f9 N  g0 {# H4 j6 t<%
, i1 g* o) h9 g5 zstring 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";
$ @- ?- Z/ y* ~8 J; h- \. r8 Rstmt=conn.createstatement();3 g7 U. ^! v- w$ O
rs=stmt.executequery(sqlu);" w4 [" `' e  G8 p) M& z
%>! B6 n7 w' F' O( t* W# o, f
<script language='javascript'>
2 n2 D: M1 N. J  aarr = new array();
3 r! P: d; r9 i; \4 X<%  int temp=0;
0 r2 O- T4 }+ U) K" `: \while(rs.next())
2 E4 B  [" E8 c4 n{
# L, y) w( |1 F& Q* m%>
$ g8 y; W3 e- O" W9 parr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
! J2 z. n: P& R" j/ `3 N2 q9 @- w<%- Y$ P: p; N2 p  N: K
temp = temp + 1;% |% @1 [% e% J2 n6 [" Y1 n
}" h  }! G9 e5 \) p* M; i! G5 X8 f4 p1 V
%>
( j5 |- I1 `' a# Ttemp=<%=temp%>;
/ W% T( X. |+ Qfunction changelocation(id){
1 E1 J" P- H: p& cdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
3 E" c9 s8 |' g9 Tvar i = 0; 5 A5 [+ ?$ L. y" G) T
document.combo_box.city.options[0]=new option('-------',''); % n4 M0 o! }& I% X) k- F' ^
for(i=0;i<temp;i++){ / m2 @* a& d. g3 B. E' }+ J
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
' A5 }+ C" k& edocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); % \) `/ M; g8 K, [
}
0 c6 i( N- _( I} ' e4 p) K; x; X
}
" a& Z: f; F. L</script>) r# q( n4 K6 B2 G- z7 y& z
" M: ?! U) c+ I& _8 r7 \6 M
<form name="combo_box">
6 q9 G) Y! S  C) X, w7 u2 X& \! ~<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
" c! k0 Q- C6 N" y- P  <tr height="24">6 y, Z& H1 ?4 o5 M4 c
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>; U- [& q+ ]3 s3 ?+ a
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>6 n7 E  Y8 N* @0 L* ?
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>! G3 _8 `' r' m( C# {
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
) y7 d- Q; {9 p) L+ o( ]0 K& x  </tr>5 A8 r' @0 [5 V4 W, D
  <tr>
5 K9 x  s# i0 Z    <td>
+ V, s+ t0 f7 Q& y4 l  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
- `. O" Z4 U; R: ]* y5 l0 v- T3 z  <option value="0">请选择部门 ---></option>
" R. P  z. h1 T! P8 U+ a& ]7 I& V<%
9 a* N9 Z3 D' D. d    string sqld="select * from tdept";
& L: y! q% P; x4 ?; vstmt=conn.createstatement();7 l9 B1 j' b4 R) Z+ N
rs=stmt.executequery(sqld);
$ S1 \0 f. T$ Q: f* Z% fwhile(rs.next())
% Y- ~9 b5 N/ U  B/ _{
: k+ q7 u& c0 N) r0 y; i: ?5 m% F%>) }. Y; f4 |: w9 s9 }  K/ }
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
* S2 f  ~# W( u3 _& e' W9 w! _<%
3 B4 m4 x! }) D3 l" K  \# l}" l+ e' r  d9 h7 h+ n" M' |
%> " q/ S; v' E, ~
  </select>
& T  K" @4 U* T0 V</td>
# k6 Y, c- A7 f+ L' o% f. f    <td>9 X. j) a2 I) f2 q/ ~7 E/ c" `
  <select multiple id=city style="width:150;height:200" class="bgc">) e0 p% A3 I3 _) ~1 q
  </select>
" m* t5 f( _" K" i</td>
1 F3 M+ c0 N8 q% C4 j6 N! p7 k- c1 B    <td nowrap align="center" class="bgc">, _. C( _2 H5 Y  C
  <input type="button"  value="<<" class="buttons">
/ t2 q2 h6 q' R6 e4 O  <input type="button"  value=">>" class="buttons">  o" \, m  d" @; I5 n  w$ B
</td>: S# y) H* [3 |- H- e
    <td>" U/ u5 V4 L/ h( R) X* b
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">0 P# ~- g: U3 H. D1 z
  </select>3 _% v% |0 r- l  Y2 X  W4 O2 S
</td>8 w0 e/ v0 r) K5 }: i; L
  </tr>9 o& `! p& t3 ^
    <tr class="bgc"> & Q, }4 s+ D+ J' B/ O- A
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
& O/ q# u* M) `- j  </tr>
& A0 k* `9 d& H' G3 i! E/ _. f</table>
6 x- R. K8 [5 J( R# F4 v* _& t</form>- k5 [4 b- m$ n( e9 T
<script language="javascript">
: a) w, g, x2 W+ ]& L9 ~% K//人名移动
; b, F" ?: ?& O2 h5 q8 {function move(fbox, tbox) {
- b7 ?+ x- s1 f0 rvar arrfbox = new array();
7 c& Z' W0 Y$ T3 k: uvar arrtbox = new array();
2 I7 m+ _6 X* [  F' w; i. rvar arrlookup = new array();
7 H; b4 }  a7 m$ fvar i;5 u- ~; H8 R" j9 z
for (i = 0; i < tbox.options.length; i++) {
; u, v$ K, ]: Z! W0 n* Marrlookup[tbox.options.text] = tbox.options.value;
- F4 X- n7 p8 v  Z0 D" _% |) Jarrtbox = tbox.options.text;
" q. t* Z) K2 H# u6 L1 C4 j7 i}. {# [( _+ ~1 f( X$ T' x3 i# v
var flength = 0;0 {* @- K, W* z' F4 z0 k
var tlength = arrtbox.length;
3 Q2 X2 B/ h( e7 i! i3 }* {for(i = 0; i < fbox.options.length; i++) {
* ]! C, [8 L9 l: e6 a4 b) garrlookup[fbox.options.text] = fbox.options.value;: [9 Y* n% z. _, y
if (fbox.options.selected && fbox.options.value != "") {0 R8 V# g. i% B) t
arrtbox[tlength] = fbox.options.text;; R/ C) M, y8 M. n9 G  Z
tlength++;* T5 D8 s" m8 O
}, _2 E: b% ?  }4 Y' k$ c0 H
else {) m8 T. C' T% w' w
arrfbox[flength] = fbox.options.text;  ?9 V" n: c' u0 ^2 e7 b% p
flength++;0 U4 V- K1 x  F5 T7 n2 d3 w
   }
" s3 X1 x, f: M, J}1 Q/ t/ [6 G% i1 E5 f
arrfbox.sort();
5 d6 _- v3 |* earrtbox.sort();9 \: c6 t$ O( x+ b# @

: F- U3 M2 U- S6 O& j: J8 Hfbox.length = 0;+ b) S4 }# B$ \. m# K
tbox.length = 0;
  V  z2 Y% [4 u# p9 kvar c;* F; d4 n$ u2 K' L1 T3 D& \  Q
for(c = 0; c < arrfbox.length; c++) {6 P% P8 o+ K: L+ `! ]1 v) z/ M! }
var no = new option();
6 u' s& ~4 ]& u  i3 Fno.value = arrlookup[arrfbox[c]];
' ?7 N0 t8 V; Lno.text = arrfbox[c];
2 j/ u& i; l. ffbox[c] = no;! ]' g' u& y$ Y( G
}0 q5 ]2 Q/ ?7 f3 _; ~( P2 N9 J' J
for(c = 0; c < arrtbox.length; c++) {
2 P' \1 i" J' D; D: avar no = new option();" k% F/ F' W0 g
no.value = arrlookup[arrtbox[c]];7 X5 Z: g! g1 H2 R0 k* e7 K
no.text = arrtbox[c];
; {$ H  Q9 A. Vtbox[c] = no;. g: ~' ]0 E2 [
   }. }4 b! P* Y: w/ q
}
0 B, k9 u8 m1 {' K+ j; ?5 ^# L/ m; p</script>
7 S* K- n" z' @$ o0 J</body>
8 _6 s# O! q; n1 w

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