获得本站免费赞助空间请点这里
返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"# e4 @* N$ ?9 j9 S4 `" g
         c pageencoding="gb2312"
9 e" j$ p, s( M: r: X%>
& h; h) d: ~! q& c8 f! Q3 c1 x( ~/ i<style>
- z. J, K- B! [- e3 k* q* ?.f9{ font-size:9pt; }
! P* ^' C0 |* G1 h+ O) d/ R.bgc{ background-color:#aecaf9; color: #0033ff }
  S+ D- B5 a* h4 ?2 s2 E" q.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;; F3 o( q2 ~: F/ Q- q* ~6 V- W
  border-bottom: solid 1px #4e7dc1;
2 }3 e3 g4 `- ^& J! T0 B# L# J4 U  border-left: solid 1px #aecaf9;
& l1 |& Q* X1 S9 L& T  border-right: solid 1px #5679bd;8 P- ~( M0 F0 l$ Q7 e- Z! t: I9 [$ z
  padding:1px;( z) ?9 r6 z" |
  margin:0px;}7 y* y' v; J" A+ P
</style>
0 m; x5 o0 M8 h, R, h<script language="javascript">
/ o( _, g! A2 q* b0 w8 Z<!--& n% g4 ~' W/ s$ _' x4 r  [7 r2 \
function rv()* e, o. q4 s7 p; I
{* j: b4 O7 o) S+ `% ?
  var val="";
+ b. x: T! J  U% N9 K  for(i=0;i<combo_box.list2.length;i++){
7 f) d0 s8 @$ X5 R3 {) F( R3 v   val+=","+combo_box.list2.value;* |2 i- v9 B- ?, L8 }& y# A
  }7 n9 X8 _3 k: }
  if(val.charat(0)==","){
! k" K, m" Z; O   val=val.substr(1,val.length);
; f. v! Y1 e8 R- D9 D  }! p) S6 l8 u% z" w0 v
  opener.form1.frecname.value=val;
, v3 R1 p9 {. L. T( ^# l  self.close();
9 \$ \& j$ k' o4 f3 |}. `2 ~$ z6 O! W' r4 _- ?. @
//-->; E! T; z; j; b3 a- ~7 b" f' q7 M
</script>
4 s' J& @* I8 ~<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
# ]" h& p7 Y% A1 Y6 I<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />; r- Q! Q; `9 F4 z% L
<%* V2 V) s; c- s8 i/ B
  cdatasource ds=new cdatasource();  //数据联结bean实例% R& E9 }  o( |: j* s0 _( P* e) s3 M' @) F
  java.sql.connection conn=ds.getconnection();7 ^7 p' p0 L' Y* k- P, M2 `; H6 ~
  java.sql.statement stmt=null;
! x2 L6 Y& k# J5 ?# w( c' Y  java.sql.resultset rs=null;$ [1 j' P% M2 ]9 f2 e
  cdatacheck dc=new cdatacheck();
6 V; k1 W$ K, g) F% i% W( t% J7 ^%>7 u" d8 d/ Z4 B0 N  T
<%
* ^( Z5 J' N& _$ J$ S6 L2 Ostring 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";9 K: \0 `1 E/ \" P0 |
stmt=conn.createstatement();
+ d! }* t' t9 c* a8 ]( w' |" Frs=stmt.executequery(sqlu);
' B' g6 O  E" B( `%>
2 j) S- B& \3 Z7 M! ^, a4 Q+ L<script language='javascript'>
4 W4 B! C+ W+ p" a. y6 carr = new array();' a6 B; |2 V/ b0 Z! v
<%  int temp=0;0 n0 N# }/ W& i. J+ t+ ]
while(rs.next())$ r* H' v: w. H: \- p: R, C: M
{
% @& |$ T+ V1 I, u( ~%>2 ^3 g+ {" `, {8 W( q4 m- y1 f1 C
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
4 V( S  }8 J8 O5 N  D! y+ `6 F5 |<%
! m2 w, J0 e! G  s5 u) l6 v( H" K0 ptemp = temp + 1;8 X. Z5 ]: H& T# B/ i
}
3 [- w1 L- F& K; ~: n  _5 G4 l%>
1 Q* W$ j$ y' q1 ]) btemp=<%=temp%>;( H: G1 W; n# V4 V
function changelocation(id){
: E5 _/ _1 x& gdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
# t. `, ]0 V( R- n# dvar i = 0; . l/ ]/ }9 _% q, \5 \* J
document.combo_box.city.options[0]=new option('-------','');
/ q- k6 G3 P' M+ Vfor(i=0;i<temp;i++){
8 |4 x- x: [% z, I. y/ a. wif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
1 E$ Z  ]( s- K6 U. _document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 8 _' L/ `/ U; z! I) e7 A
} # I7 ]4 Z7 \" I: |: Z0 ~/ \9 d
}
$ e1 [$ b% a9 ^} . C) Q* M) v' F; w: ~8 |7 x
</script>  L* ?0 Y% H- F8 i
8 d/ j5 q# G7 X8 y
<form name="combo_box">
' {. v- Q* b7 b0 t. z6 M<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
% M; p, G. t. J' p  <tr height="24">) W6 N, ~& Y; `$ E; Q
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
$ A0 O  W# S+ e" m, _    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>5 F% z, s' m* r0 k
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>  D7 K* R' U% v8 V$ ]- H/ i, K
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>- i4 z* p" O2 P3 ~/ i2 p% p+ J9 N
  </tr>
& X7 B5 ^' r/ |- i% ~2 o) j  <tr>
5 q/ ^9 L+ B) ~3 T    <td>
: o: y7 h/ v- v* |; c  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
9 I% X1 ~7 ], {: x3 z) n  <option value="0">请选择部门 ---></option>% M1 _" c- Z* t0 B, y
<%
; ~+ ?8 A/ A9 m9 ]" ?2 a    string sqld="select * from tdept";
  g/ I  `4 j! G; \* T! estmt=conn.createstatement();4 q  M7 t5 s! K9 Q) a% M+ t
rs=stmt.executequery(sqld);
* P4 r+ S* ^0 f3 x$ Z6 |, Dwhile(rs.next())7 ?9 i1 A) w9 L0 r
{
+ X1 o( D6 p6 x$ F$ z4 h%>
3 G: F2 P! @( v  z# W  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
+ R& X- f# B8 }& c/ P; ~<%
5 S  m& \: g9 a}
, d. d" x6 U' u+ W%> : F0 u% L' t' \" [  _
  </select>
! }& k$ f. E' X' S- v! s# @1 z5 Y</td>
+ ?3 [/ z! [1 ^! i6 `  r    <td>8 U+ Y# ~' n, Y6 P. q) f( H
  <select multiple id=city style="width:150;height:200" class="bgc">! M0 o+ l, S4 z1 l
  </select>
! \0 }0 _9 |6 M: b, ^# y4 P</td>" s4 I) W0 p- W6 [6 o
    <td nowrap align="center" class="bgc">9 F- V& J( A1 Z
  <input type="button"  value="<<" class="buttons">
: f. \! h9 x' e) x  <input type="button"  value=">>" class="buttons">
9 r5 ~7 Z0 o% a) w" V5 O+ a</td>
- N. s9 u% M& f- x+ N! i# G    <td>* [. k& N$ p" N0 Y8 N6 n
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
. m# G! T# j: X+ |% \' }% f+ r  </select>
* [4 j5 }( S, w' F% }* B</td>5 ^1 _- J; Z  g/ M* ?/ S+ j
  </tr>
# q! u+ ?( `7 h1 d! f    <tr class="bgc">
" N9 a1 C1 P) T; N2 O+ }0 S    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>8 D- s/ D0 s6 ?8 B( a& h
  </tr>
3 |( k3 P3 N1 ^3 o' C</table>
# i( d( G2 G  m0 }+ y: ?</form>  @8 g" \5 u2 A* @6 \! J
<script language="javascript">
3 B- z! E( W8 T! q( ^5 ^4 I//人名移动
0 _# A: F6 k. u6 I% ufunction move(fbox, tbox) {
% n5 t$ T" ~+ O/ |var arrfbox = new array();
# m+ V3 h6 C5 vvar arrtbox = new array();
0 }  G9 M8 ]5 u7 e/ m5 C8 N) ^* Avar arrlookup = new array();" ~' c8 L3 F' W1 j$ o5 R6 q
var i;
# e, l3 ~! y) O; F' z& @  j6 m; nfor (i = 0; i < tbox.options.length; i++) {
. V5 @. s' q( z8 {arrlookup[tbox.options.text] = tbox.options.value;* {& `1 a' ?( l6 J$ T- F
arrtbox = tbox.options.text;
8 |$ W6 @0 [% l  H$ ?) i: t  l% J% S}
9 @/ R$ `, F$ W+ T8 h6 R: [. q: T, Qvar flength = 0;, A5 |# y6 y8 [  `( Q
var tlength = arrtbox.length;
: D, \- {) E8 K1 x! f% sfor(i = 0; i < fbox.options.length; i++) {+ _  m" p1 d5 ]- P3 T/ ?
arrlookup[fbox.options.text] = fbox.options.value;! z" y+ _  o+ K% H  m9 k
if (fbox.options.selected && fbox.options.value != "") {! {7 D) n# y; z7 v4 Y
arrtbox[tlength] = fbox.options.text;
& G* [  y/ Y0 K6 g, |( O9 `7 l! U) ~tlength++;
( k% n% F7 `1 L" X0 q- m# m}
, S9 P* V! h/ v5 x$ k/ }: ^, selse {
( r% n' E, _+ Marrfbox[flength] = fbox.options.text;
5 x! T9 d- U2 |$ ~. \flength++;, ^3 }/ K2 y7 k5 \8 p9 q
   }3 Z9 E- U8 U' d) |. H5 A/ T) f$ \
}6 q2 W3 R1 X. t4 E
arrfbox.sort();
  p. }4 _+ Q. J' @0 a" varrtbox.sort();" Q1 h/ l% L5 W3 D2 w
" e1 S' G( e9 q" n( I
fbox.length = 0;, S- p0 @5 \4 z( [
tbox.length = 0;" x9 P: N0 o6 T5 o& g, l+ I
var c;
( a% [( \( R' B3 b- j+ ]( xfor(c = 0; c < arrfbox.length; c++) {
% \( M2 m; }' Y. i' fvar no = new option();
( b" I% {  l; A  J3 |no.value = arrlookup[arrfbox[c]];: z& g7 ?" E! v: {* i( r
no.text = arrfbox[c];
; g2 ~+ V& e3 ^$ J* E3 L. p4 ufbox[c] = no;
2 ^" U& Z; Z+ O1 ?: g; N+ _}
7 ?/ @- `* H- \! C1 c+ efor(c = 0; c < arrtbox.length; c++) {
/ ]1 ~$ E: ?/ o( I0 s- Avar no = new option();1 {2 B% L% i9 h
no.value = arrlookup[arrtbox[c]];/ |: a- ^+ p+ ~* p
no.text = arrtbox[c];
' \$ l" n8 p) o8 E% O, c: S& h/ a0 |tbox[c] = no;1 R6 D4 m' @7 \7 ?9 G
   }
* M8 G: Q4 h5 Y+ q}, f" k+ b) R! j1 e, N+ G' \( P
</script>
5 a; q1 W& J* ]3 G. C</body>* @7 G! G1 ~. u8 b7 H6 u) c8 V

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