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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
0 f3 F$ u  d/ l6 L  T         c pageencoding="gb2312"5 L% Y+ F( S4 {; Z/ P( N# _( E
%>
# y% }# T" _: X: z: ?+ t/ h<style>1 Q* [- v  m5 p1 K6 f
.f9{ font-size:9pt; }
" D: G. b) m. d: }+ p.bgc{ background-color:#aecaf9; color: #0033ff }
% P! B% |$ [5 a' j.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
1 c% ?3 S: |2 Z/ ]6 [% H1 L  border-bottom: solid 1px #4e7dc1;
& u5 ]" W9 M2 v9 h$ r% Q0 K  border-left: solid 1px #aecaf9;
. r! Y" y4 C% y1 ~' ?! p  border-right: solid 1px #5679bd;% e) T1 G% F( D$ y6 M- z
  padding:1px;" u' e! P4 L2 W$ R: a# S0 L7 G
  margin:0px;}
( a4 G2 Q6 R* F2 c4 I( G</style>
  H! D; w$ H- M<script language="javascript">
5 }+ e; Z4 x' p<!--
8 D1 ?2 V3 M1 j, c& m- \' ]; P0 Bfunction rv()8 x! V5 m4 t. |# d# \: C
{- X0 U* P# i/ G7 N
  var val="";
6 p1 `" ?' ?$ Q/ W  C  for(i=0;i<combo_box.list2.length;i++){6 q$ c# z& g8 Q6 s7 T; C! F" o
   val+=","+combo_box.list2.value;- J: i" o+ G) o7 y5 G+ E4 `$ N& ~. F0 j
  }
0 ]1 [( o3 E7 x  if(val.charat(0)==","){
4 V* K1 Y: k6 y/ {5 `   val=val.substr(1,val.length);
' V+ c& y$ l# A6 n  }0 V9 C5 p* Y5 t2 h8 J
  opener.form1.frecname.value=val;
  A1 C) u* p) b8 R$ H! |+ m4 _  self.close();
' e, `2 ^- y& T0 ]8 s}" E6 N# M5 J$ `  o8 H0 \, t! E- g) t
//-->( ]( E7 S( H( I" e/ L' o9 @
</script>4 S' i1 i1 Q1 D( X' ^
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
( j: I1 L& {% P<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />2 M+ |2 Y! A6 ~& _
<%
8 g" S2 k9 g1 \. B! U* S  cdatasource ds=new cdatasource();  //数据联结bean实例
/ n' j  O4 l0 y3 C! z  java.sql.connection conn=ds.getconnection();
. \" w/ @  j3 Q8 ?' K3 B3 @  java.sql.statement stmt=null;% |6 @6 \( u6 I* b' ?: z3 ]. a
  java.sql.resultset rs=null;
8 e. C1 q6 k5 b) N' X; d- H, L  cdatacheck dc=new cdatacheck();! {$ A. B+ U* |' N
%>( {) P6 m" k4 K  _* r
<%; v% s7 r9 V+ \, [" Q
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";  J( t5 M( T0 _
stmt=conn.createstatement();3 H/ _* c+ l' s5 o& @
rs=stmt.executequery(sqlu);3 o$ x1 Y7 y" Z1 e" v' h* _
%>
0 y/ U: {3 T( `2 d# n# x* o) `<script language='javascript'>
. B9 e2 C/ m, N. Barr = new array();
2 @4 z. I. K5 E3 Z3 ^# U<%  int temp=0;
8 T& ~* r6 Q) X5 V% Fwhile(rs.next())5 N/ r" q3 m" W, _/ a5 E, I& d
{
' z4 L3 W3 W) o; M( q: @7 z%>
: X- p' A- a2 }1 Yarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
- g- a/ A! L- ^  A" i<%
: I$ I( `- k; T9 Atemp = temp + 1;
& x0 y7 G1 M- g7 D}
8 G" m. I+ U+ j# P% C$ O$ K2 O5 f%>+ W' ~. P% S! R9 F% ^
temp=<%=temp%>;
* W8 ~+ S) L) h7 ^$ g$ hfunction changelocation(id){ - |& O) L( m. d8 o/ {; S) D% a% ~
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
$ M- W) |+ i+ T  z4 G3 b% r$ q# q1 Tvar i = 0;
- `7 D, Z/ _6 _# v+ ?* H" D! cdocument.combo_box.city.options[0]=new option('-------','');
2 R2 d: k/ S/ A4 z7 ?' Ofor(i=0;i<temp;i++){
2 ?" n" ~: I+ c3 y8 z% g- c% \if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
0 T) E3 {7 W, v  Vdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
5 N' y! C2 U  h$ T/ S" ^# P}
3 Q) n3 Z1 q# R} ) Z! b# U. C# y- {- \: l# _
}
+ o/ B- J6 u5 Q9 w- ^3 A</script>3 p: F1 Y4 E- ?( @# q4 {3 W
+ A0 b+ Q- J7 ^& C. d: K
<form name="combo_box">' ~2 V; z. t0 k* Z/ o) u  q
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">, d. s- L- H( d4 `! S- r( e; l) h
  <tr height="24">
& H& t% ~2 j3 g) ~) j    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
' t' u& d& R# `; k; A/ N    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>+ T. a$ G8 w# ]( V
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>  B1 Z" d8 u4 ^( m6 l$ e
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
. J  }6 k( d1 w2 V  </tr>
3 ?/ {% M. M, T1 h  <tr> * [  y( w* h& B& S
    <td>+ N( p' G% j) T0 T6 y5 X
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">( ?- d2 u& V, j
  <option value="0">请选择部门 ---></option>
; v- d- N! k6 w7 ^<%2 X, N& z* H+ @8 g) f4 N3 v2 |* c
    string sqld="select * from tdept";
! e0 V) t  V6 b" R: Wstmt=conn.createstatement();4 Y) t, C- P" c$ ?
rs=stmt.executequery(sqld);' q- S* ^7 V! j2 ~1 _
while(rs.next())
% r' {$ L* t3 v  q+ N. T: G4 I{! M2 T/ m% m# f5 d
%>9 \$ T/ _% R7 x/ o& q2 C+ M  w  i
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
7 T& ?, L2 i; `% b; N<%
* k5 g  F5 M! ^0 {' a}0 `: n5 g# z2 E( P" t
%> % E+ D9 c. @& r
  </select>
1 E* Q" {3 h. O8 T</td>
- I2 W4 B7 m8 Q+ b$ q    <td>" ^6 N" V" V' Q, T- O
  <select multiple id=city style="width:150;height:200" class="bgc">
# C  O0 b  b# ]+ b  J- L  </select>
8 o: N( t( r5 x1 h. m; ^</td>
' S: E6 ^8 J9 I/ S9 D    <td nowrap align="center" class="bgc"># l( c/ N0 [$ S$ c! q$ _8 p
  <input type="button"  value="<<" class="buttons">$ _5 ?' u# [0 L
  <input type="button"  value=">>" class="buttons">
' V* g' q" |, _5 }9 t% e</td>8 E5 m7 D% O4 F3 G
    <td>3 j, @* _- X1 Q! B; ?
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
/ p4 s! P+ a% K0 l! W. d0 U$ E9 a% j  </select>
2 a# M9 B: s) y8 t! ?</td>6 v. g3 D" ?1 H8 R. w+ p
  </tr>6 ~; U+ x' A6 I4 K; B
    <tr class="bgc">
; @! n9 Y3 w' t* R; F2 n    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>: S" A' e& j8 Z' ?2 {2 }' u
  </tr>: |- ^2 O, r* s. P% V7 J. Z
</table>
/ s9 L0 m4 L" R. z. @6 t</form>; s: r2 y& Q$ |4 r+ A
<script language="javascript">
6 S& G; j8 d9 V( H$ u3 e//人名移动
7 ~. |( x5 q' q$ m2 M, _; ]+ lfunction move(fbox, tbox) {) g  B8 [  V9 a; }8 l! u  ~5 l
var arrfbox = new array();
7 J) W. s, H) xvar arrtbox = new array();
* L( X; |$ P* W+ Q. k' ?3 e* Xvar arrlookup = new array();9 r2 R$ A  t4 e- i- G# I7 x
var i;! c5 M( I' T1 \
for (i = 0; i < tbox.options.length; i++) {. d% G" S% s# x! H* |5 H! u
arrlookup[tbox.options.text] = tbox.options.value;6 o- l: P+ a% ^
arrtbox = tbox.options.text;
2 H. W. I7 d2 B; c% V* V1 I}2 @6 p& U9 k; }( B
var flength = 0;
! h0 B. D. i  V9 W1 Q" Dvar tlength = arrtbox.length;& l5 s! k1 N2 T& x7 L7 a/ H2 w
for(i = 0; i < fbox.options.length; i++) {8 H) r6 S4 W5 d+ ?
arrlookup[fbox.options.text] = fbox.options.value;& b' Z' q1 ?: {+ C2 }
if (fbox.options.selected && fbox.options.value != "") {) H5 c& F" ?5 |" X
arrtbox[tlength] = fbox.options.text;% d( F9 p+ f4 E1 t# D
tlength++;
; ~. I. ?( [# o7 r}
/ |, \) g0 Z- E! Eelse {
- T2 f4 ^& v8 V5 V, `arrfbox[flength] = fbox.options.text;+ l" E- {1 k. _7 L
flength++;
! u8 h2 M( D0 d& o0 R  W" x   }
/ y0 ?! b1 {3 ~4 G- P}
* Q' [+ n# p6 T3 I: E) {arrfbox.sort();7 c/ o; o' _. f: f5 j3 B
arrtbox.sort();" H: M, H( N+ O$ u/ F' m7 `
: B" D. F- Z; c3 ~0 i9 i
fbox.length = 0;
7 Q% q( T9 q; Z& W/ Vtbox.length = 0;
8 c2 t2 w. L9 o* G) y6 L* q) h4 R8 vvar c;
* ]' W  d7 X! Jfor(c = 0; c < arrfbox.length; c++) {# h3 i( o, ]# _' B- _
var no = new option();
0 a, X( R3 p7 {- Ano.value = arrlookup[arrfbox[c]];
6 e. m) \1 I* d9 ~5 \3 Nno.text = arrfbox[c];6 p* Y1 R' ^( p% n+ @. U! E
fbox[c] = no;/ F8 q9 I" D) N& H' P& t- y
}
5 @/ ?! x: q) c4 Bfor(c = 0; c < arrtbox.length; c++) {* r7 @) `9 n% f
var no = new option();
* A4 ~. v6 x9 A- w% Fno.value = arrlookup[arrtbox[c]];" c% ^) c' N) w5 O- e" `
no.text = arrtbox[c];1 {8 Q# e$ a' u( A$ T
tbox[c] = no;
5 @; n& g& [0 K# O7 C+ d# D& I, r  F   }
3 t2 b) [" ^- ], h6 w}5 `! \. f3 O" z% T
</script>
  V$ O- ^) `! O8 p2 K# D- `</body>; [8 Z8 A1 s( O/ ^  p2 x

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