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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
) K- ?: R9 m8 O- B2 k         c pageencoding="gb2312"4 U0 c4 k' [' ]' X" f' R2 M
%>9 C; ~2 E; T5 y, F: q
<style>1 ^3 I! ~$ ]! P5 s- a: M
.f9{ font-size:9pt; }2 S+ m5 Q# A( {& [/ M2 r
.bgc{ background-color:#aecaf9; color: #0033ff }- _- q2 _0 [0 O+ _
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;; N- Y) Q$ ]) |
  border-bottom: solid 1px #4e7dc1;
/ `2 S3 M. y. y3 Z5 _4 n( ?; h! O: x6 R  border-left: solid 1px #aecaf9;! Y5 `# q. l& Y4 \% v5 R) f+ x
  border-right: solid 1px #5679bd;# x$ x. n% Z" {+ `) p  l2 J  G* r9 A; [# v
  padding:1px;% A2 V! e5 S* @
  margin:0px;}; x! m9 p! N7 g. e$ o( I. j
</style>
3 J* K' _5 |+ x8 p: z" j<script language="javascript">1 m  K$ O& }" K$ ^* g$ o3 p
<!--
9 ]% f4 x& `1 E+ O8 d! Afunction rv()
+ S" a! z) t8 V' s) `, \{
) U; M' `$ L$ \7 _: Q. ?( l  var val="";0 b6 v& [: Q! F! m- X
  for(i=0;i<combo_box.list2.length;i++){
1 b2 w* u% N* u2 s6 P7 c   val+=","+combo_box.list2.value;
. w6 n. m- J2 n2 m  }
+ T7 j8 K6 U; p6 w  if(val.charat(0)==","){
; |  t' e) n1 Q6 T   val=val.substr(1,val.length);
  s5 q3 L9 e. r% ^+ `+ b  }
4 ]. `+ r; v' |1 A! U  opener.form1.frecname.value=val;
3 ?5 ?9 R5 g( i6 v) A  self.close();0 r- P9 ~4 n( y5 A
}( n7 |7 D9 C+ F( c8 K
//-->
8 L" K4 V& Y$ y5 s9 o! G# A</script>
( l' n. v, r9 _7 q: f* G<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">6 q; [  ~3 X7 Y. }1 t8 q6 T( p7 s  _
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
  e8 I/ f7 P, q2 k<%
+ W8 p7 l0 u: S  x. z0 H2 }  cdatasource ds=new cdatasource();  //数据联结bean实例
1 d0 @( v4 J1 J  java.sql.connection conn=ds.getconnection();
3 F! R- r0 I, Q  java.sql.statement stmt=null;0 w- C# \9 J5 p2 f
  java.sql.resultset rs=null;
% I- G# H+ I- H4 ]  cdatacheck dc=new cdatacheck();
; p8 M1 }7 l6 @/ {1 M  p0 h3 \%>
  G/ i2 E' P2 X1 X1 @! u5 a<%
( C# B" e% \; P" S( p0 [6 sstring 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+ a2 \# E! p' S* }$ o, ^stmt=conn.createstatement();
& Y% p8 C5 r" j6 _/ _$ T5 {* hrs=stmt.executequery(sqlu);3 \0 i1 \$ e, r$ N! B
%>. u% j3 f2 q# ~
<script language='javascript'>4 k) `% f  b2 o% L2 H
arr = new array();
) I  K  {; I& w( g<%  int temp=0;
* v) P: `( Z, b9 Z+ ^( V5 a+ {while(rs.next())
. n# x: |1 N0 O7 n{' g! U0 r; x% C' F
%>
! n1 c/ q; j4 }# |) barr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
, H# g6 D" @$ d<%% s- ~5 `& m1 N! Y: p; M) @
temp = temp + 1;
, m/ L0 c# j5 i% N7 G% ^+ v}' B3 o2 ^& X- q: f0 X
%>" O) `& x& N: u5 t
temp=<%=temp%>;
& F2 K" O' ]. e1 ?function changelocation(id){
/ j; f7 v0 I, o. @document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 6 p' O1 ?: N) ~- V( A0 C
var i = 0; 0 T3 D" r5 z& j# D8 {7 S0 S1 G$ B
document.combo_box.city.options[0]=new option('-------',''); 2 }8 O% A$ P3 X: s% X% g
for(i=0;i<temp;i++){   K% x$ D9 ?" L& ~' _
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] ' M- [7 h0 \1 Y* Y9 m* v: M
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); : V3 v5 u1 k/ N. t
}
7 _- F+ ~3 d2 x* q- D} ! M1 B7 P2 p( S5 v6 Y. b
} & e. s  _- ?* z& ^5 R; i9 x; {
</script>
! U0 k3 U4 c4 y# H5 A' J- w
5 g0 o% t' r/ z<form name="combo_box">1 G) B6 m7 I# N# K7 ]" ^  g- @
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">8 Q6 f: E9 Q7 m' M+ N7 |" \
  <tr height="24">
: p8 d3 x$ Q, z# m1 o    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>2 y# A  u* H, a
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>- q3 H% d6 O4 `. t" z7 L
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
3 S' C2 L5 u& s" }8 @8 @6 w- J    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>3 z4 ^, Q+ }, O, X
  </tr># N7 X8 C. F: `$ l$ w% Z) E+ D* s
  <tr> , w5 ~- d/ v; ^
    <td>
; g" R/ x+ G$ m: n0 P3 k  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
0 S5 {& ]: z/ f' h" K9 W  <option value="0">请选择部门 ---></option>
1 a) k* j" X- S; [# M: n8 i<%1 R2 g" s- N  j9 `  I$ c
    string sqld="select * from tdept";6 O2 u2 {9 X' M2 R8 ]# u& O
stmt=conn.createstatement();) _3 u9 D. z7 g. e# R* d
rs=stmt.executequery(sqld);
6 _) s) U2 ]) U% R* s" J: G3 V" [3 Bwhile(rs.next())
) \3 Y2 G- J0 h) q0 g3 i2 t{" I0 d) O+ N1 V3 \0 |
%>8 k( @4 G8 C' H8 t' P# a; N9 P
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
; U" t/ b# G( g4 `: _: l% G5 B; v<%
" {& V5 }/ {- u/ A" m) C3 q, V" L& e}
& x& p, \! h7 V, A' o, ]3 Q, M%>
0 \0 `" U  g" s  </select>4 B3 S2 F3 X- h5 l  m+ O
</td>
% E! _! i1 v( @5 c% I0 m# x    <td>  e9 ?: p) f4 U
  <select multiple id=city style="width:150;height:200" class="bgc">, W3 k# G7 W1 W1 t4 V
  </select>5 e; F9 G- q8 x1 G# U( I
</td>
- U2 Y& W( D0 ?5 c    <td nowrap align="center" class="bgc">
# v0 u3 L& o2 m8 _, a$ C8 ]+ I2 p  <input type="button"  value="<<" class="buttons">
0 x6 ~2 d6 }: L! R' b+ P$ a0 G, s, x/ [$ Y  <input type="button"  value=">>" class="buttons">. }. I5 z  |0 Q7 P- `2 N
</td>
  s0 d$ S4 n# y5 U& ?    <td>( F4 d; ]. R+ l0 m
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">+ i8 g) ~$ v, F4 R2 E; Z2 H+ g8 ]
  </select>
7 {7 ^- `' |: F, W7 X</td>
' C" W/ p, A! u6 s7 d  </tr>
* w, }8 ?' {3 \4 Z+ @/ g+ H9 E    <tr class="bgc">
) r2 G# L* n0 y: w    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
" f. r: F8 u2 |4 T3 T7 u  </tr>, l( y' I/ o' g- i/ ]' U" T2 Z9 }
</table>3 `: G; g% C7 y/ a
</form>
7 x' j7 t- c6 `) @+ {9 v1 R<script language="javascript">
$ o  B; t6 H* g* w) V$ w//人名移动
1 L. e1 V* F9 V& X& F/ [; Kfunction move(fbox, tbox) {2 I& l8 P6 X# o3 P. Y: S
var arrfbox = new array();# r' a5 l  k, b' B% r6 I  Z
var arrtbox = new array();1 p$ W' r8 z; D: d+ `; q9 v% C7 _
var arrlookup = new array();; B2 b4 T, i1 Y3 |+ ]) p
var i;/ M7 {! r! I6 l
for (i = 0; i < tbox.options.length; i++) {& S. y5 P" Y9 t9 f4 o
arrlookup[tbox.options.text] = tbox.options.value;
- T# M/ c! V( R* [" yarrtbox = tbox.options.text;
% O) S% g0 N5 C, E8 |}6 \* y) Q7 w& Y/ m1 V
var flength = 0;
& ~3 U# J' n( J3 n3 R; O/ X# y) L- Svar tlength = arrtbox.length;5 {9 R0 ^) y: x9 J
for(i = 0; i < fbox.options.length; i++) {. \! P; G3 Z3 H- W) n
arrlookup[fbox.options.text] = fbox.options.value;' i1 A) l5 U& e5 M
if (fbox.options.selected && fbox.options.value != "") {
  G  e4 o2 F: s3 y, s3 D9 Yarrtbox[tlength] = fbox.options.text;
/ z* J8 Z0 y! W: U! g- z1 D7 |' etlength++;
7 `9 f6 }; s) Y. [) R}
5 g3 _% Z  S; K% n8 M/ Y; d- e& qelse {* q1 E3 [( A& ^
arrfbox[flength] = fbox.options.text;  R) ?/ g2 y9 @3 G, d
flength++;
8 M: k3 i  |5 a5 F   }2 \' _5 J" ]6 v! M
}
" Z; ^! @+ y7 m- N/ E1 d" J7 carrfbox.sort();' @  L+ u* m4 i' Q, V$ X4 N
arrtbox.sort();  U7 y6 F% m2 A, G

! c& K6 T# Z- c: P' Dfbox.length = 0;
2 g8 {/ y  T2 ^! e3 [tbox.length = 0;& d5 P2 N7 w# Q4 o: f% i
var c;1 X3 e7 z5 `5 Z! m5 j5 o! {
for(c = 0; c < arrfbox.length; c++) {
8 A# F" [9 u( e. B/ A. H, pvar no = new option();
4 ^& L# R; s% {! G3 b' p5 O6 v  hno.value = arrlookup[arrfbox[c]];2 }  A) O5 z; N9 n6 {
no.text = arrfbox[c];1 i8 Z( T5 S8 J0 H
fbox[c] = no;" L* x1 z8 w4 f6 N$ D: \* \
}
' i5 a9 D2 K- K7 O- Wfor(c = 0; c < arrtbox.length; c++) {7 F( V% M3 O* {# B4 B* J( J4 W$ I& F. A
var no = new option();1 k& b* M6 w% b0 @1 r
no.value = arrlookup[arrtbox[c]];
' c& o* r' q! i2 X) D, H* hno.text = arrtbox[c];
6 ^3 m$ a, |8 A& u. u1 k! ftbox[c] = no;2 L" l7 s& y- y, m2 z5 r
   }, k- o) p, {/ e- e" U" ^$ n
}
5 G  r3 I0 _/ i3 c( ~  L8 R% O</script>3 I) Z/ z6 i# I) \
</body>. m+ D/ T/ g" \3 Y

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