返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
  [2 W  n# G% |- e1 y& W% H         c pageencoding="gb2312"0 j; {  W2 P) U
%>+ ?" G  S' A4 b+ ?
<style>
7 e: \6 ]/ R! K! X4 n.f9{ font-size:9pt; }
) E8 G8 z. |" a% e  S.bgc{ background-color:#aecaf9; color: #0033ff }; [" M, J3 W9 |' a" \) v
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
$ |6 S% u- e3 B  Y  border-bottom: solid 1px #4e7dc1;
; p7 s: |, c/ _6 [9 n  D  border-left: solid 1px #aecaf9;% H4 T! t& q+ y* @" g
  border-right: solid 1px #5679bd;
4 d/ o7 ?& ]% Q5 z* O  padding:1px;% O, H1 H) W' w; J* E# ]+ ?
  margin:0px;}% Q7 o+ S" z. ~; ?* s) Y
</style>3 {8 k$ [3 n9 O8 j, `
<script language="javascript">, h* p* ]) I& O4 o$ w
<!--
& |4 ~7 w9 b- [' ^9 Q4 rfunction rv()
9 o" y: W8 V5 x( C! x# r{
; h$ t! K( g) V1 r# G* K  var val="";" _+ V$ o6 x4 A" _+ C
  for(i=0;i<combo_box.list2.length;i++){! z+ ^8 K7 ]: ?: ]4 ^2 a% ?! Z$ T# X
   val+=","+combo_box.list2.value;
- J1 M  d2 ], L) o: H% S6 K+ x  }3 e" S* M, T( T' w! F& l: g
  if(val.charat(0)==","){
, ^& [6 A1 \; @/ B0 h- o& Z   val=val.substr(1,val.length);( y4 {( z8 Z. e: G
  }
3 h& F  k: N! j, o. R3 ?7 r( \) M' a  opener.form1.frecname.value=val;
( V, Z- `6 y8 Y* x: N  self.close();* i& }2 Q  Z% ~+ |
}
6 h! m$ r5 V% y( K9 S//-->
+ `+ ]& F+ T2 q</script>) Q" \  m2 S+ O4 \' b# C, Y
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
9 d  @; A" j. a) ^<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />" o. G9 L* x0 t: w& z8 ?/ s$ a
<%
$ e1 ]8 y3 }5 \1 A  cdatasource ds=new cdatasource();  //数据联结bean实例
4 A! {3 T! v( ~$ c7 ^$ W2 Z  java.sql.connection conn=ds.getconnection();; V2 r. M" l% B, ~
  java.sql.statement stmt=null;
# ]; l8 r: w9 V- r  java.sql.resultset rs=null;
" p, \) j& @( T  S8 r3 M  cdatacheck dc=new cdatacheck();
3 Z, D$ B5 K1 H% n1 L%>
* K+ n8 w( H1 d: z<%3 R: b, E) ^$ G* B
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";
7 a! l2 [# ~$ Nstmt=conn.createstatement();/ f+ g2 r) K- ]7 d$ [% ]  |
rs=stmt.executequery(sqlu);
% E2 L' j3 ^4 y* A%>
, W- ]: M/ s) _& G  ^, E$ R<script language='javascript'>
2 Q7 n/ U8 q9 L7 Zarr = new array();
3 {4 ]9 {9 K; b' t' F( t<%  int temp=0;* k& h# r5 w1 o) [9 u- g4 G' r
while(rs.next())
5 h4 _6 U& Y+ d1 _- [: g6 A& m{0 \9 \0 V2 A5 c+ k9 K
%>, \4 x- o3 v- D" a. b; q- b0 B5 q9 ]
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
. k" v4 |5 m8 w+ w<%
  |/ V: A$ J3 f# v3 E# Otemp = temp + 1;/ d% Y/ ^& ?# j  O! M
}
- a# @! `' K( R2 C  P8 R%>
, ?. \# q& h2 Atemp=<%=temp%>;
7 H' W7 r6 `& {4 T* I# ^3 bfunction changelocation(id){
/ r9 r. @- {* w' Hdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 2 z  v6 {* Q, T
var i = 0; 3 r/ _5 W, ?+ n, i0 N
document.combo_box.city.options[0]=new option('-------',''); 1 I: z; p& a) X+ m- i: g5 s" h
for(i=0;i<temp;i++){ # R$ r4 ?9 m) m, R: n" z- k
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
8 @, J" W* e& y8 Cdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
2 m& }- i5 x( B}
5 x' t( b* ?9 D, e  {! Q}
& i9 T$ T" @5 x# R1 n7 `. a  Z' C$ ^} 2 y. X0 G, h4 X/ A# Q1 Q' f
</script>
$ F; F: W+ m9 [; J1 n8 Q" d& q9 O3 q2 K9 J' r9 `! K0 P. n; q
<form name="combo_box">
: S; X+ l/ M1 Y<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
% t# Q& e0 i" X+ \0 R4 w  <tr height="24">5 e0 `( x; a: i1 U+ ?
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
- p% s" H0 N; j    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
1 e1 r( ?1 m! R9 ^$ n    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>6 j# p3 I" z& l+ K
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
1 D' ?0 Q3 L' |. A' T3 \2 q" f  </tr>
8 z! o( v  o, M! i. L0 y  @8 H3 e  <tr> * f  p% u! G" p+ G% m0 B+ D  a
    <td>. m' q+ J. E+ M/ f" n) y
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
6 L; E( A' E5 p$ n  <option value="0">请选择部门 ---></option>
/ X" W6 Q$ q, A# l7 D/ J<%9 ], |& o: a1 z
    string sqld="select * from tdept";
% `$ V- [- m* n: [stmt=conn.createstatement();, }& I+ \6 ?6 U/ _1 v2 B
rs=stmt.executequery(sqld);
* S; l) D- w6 G  J  m  X. |while(rs.next())/ E! i( a$ ~4 ^: x% d
{
' y/ w) R3 z) m. j" d%>8 t) W* X  Q7 f9 v# j, l( m% f
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
6 A' h; W; G% D% Z! O6 H<%: x0 f  C* i7 i8 W. ]: e. A
}
! D! h) K6 B; @%>
3 G9 [0 H; P4 K4 \! n% e# p3 @  </select>; [. ]- O! Y5 L0 z$ N3 r) B
</td>
3 ~. D' X4 }6 k2 X    <td>. D6 `7 o' }) _6 z
  <select multiple id=city style="width:150;height:200" class="bgc">
: F% l! J1 Q; h9 l9 A  </select>
8 m& \+ _" N$ }* T2 I</td>
9 m! i* K4 [( T    <td nowrap align="center" class="bgc">
+ G, D5 F% {/ M: @( ]  <input type="button"  value="<<" class="buttons">9 c: ~" }$ z' f9 v3 k
  <input type="button"  value=">>" class="buttons">
( C' d: M) S/ E! D& `</td>1 M1 [- N: z% \( j$ X
    <td>
4 j% k4 y+ E% Y/ D  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
$ P. t9 B* f5 \$ c  </select>0 H; e% R$ V9 ^* |9 A" ^
</td>
" t' A  g. E& R; ]  </tr>
6 L. b: Z# ?) ~    <tr class="bgc"> 0 J0 F7 V. G" ?
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>4 f3 |) I1 C0 K# Y- ~
  </tr>
( v  t1 s. `0 r: |6 x" q6 V% R0 X</table>9 [; k& x; J9 D! e
</form>
2 M, o, u) S3 r% O- q  L* d, Y7 x<script language="javascript">
; S7 ], j  b1 e4 R5 A//人名移动
1 S5 i# w3 ?- Pfunction move(fbox, tbox) {/ X& u2 T' J" _
var arrfbox = new array();* u7 {( O# u5 G  O! E, E
var arrtbox = new array();" @: ^% v" `8 {8 L! G0 r
var arrlookup = new array();/ D- j% }% ?% ~4 X" ~" D+ }
var i;
3 O. A. c% J+ f( U) Ufor (i = 0; i < tbox.options.length; i++) {
$ n  Q, i' `8 A9 F' T2 q: w' farrlookup[tbox.options.text] = tbox.options.value;9 `, y2 C9 I/ _& s! h4 F* Q% G! q
arrtbox = tbox.options.text;
9 K2 Y; a2 M, V- y( B}
7 K8 j, F: x0 l7 M, ~& P2 zvar flength = 0;2 t2 P; k; S. w5 x) S1 T5 z
var tlength = arrtbox.length;7 k( @; |% V+ V3 s2 L
for(i = 0; i < fbox.options.length; i++) {
* i) m- g4 K5 J4 k! U0 S, ]arrlookup[fbox.options.text] = fbox.options.value;2 G% B& s/ N. K3 h
if (fbox.options.selected && fbox.options.value != "") {
  O7 b4 W. i: j1 o( o; q! K* s6 garrtbox[tlength] = fbox.options.text;3 o  h) g( c5 T- s( F% @
tlength++;, y7 V/ q: C* Y3 W; _" ?8 F
}- `5 D- F: ^4 d: L) u5 C# _
else {2 l$ j: Z. |8 u, @+ W" D: v
arrfbox[flength] = fbox.options.text;& v8 f4 R+ W: u2 n/ v
flength++;
& Y3 |: e4 S, M$ x/ \, z   }" p5 u, O7 D2 a) ?% {
}( Y1 v- A8 K, t3 `  A% r/ [
arrfbox.sort();/ t$ G2 p) q9 }& I4 {; v
arrtbox.sort();
  F; e2 ]0 s& F/ s
: y3 k/ P4 B" \fbox.length = 0;! u8 H8 p7 u2 t% O* U1 R$ W$ \
tbox.length = 0;( n+ e' S/ F; {& z3 O0 T3 u- ?
var c;
0 O3 k. r9 y/ e  Q8 T: m" ~: Wfor(c = 0; c < arrfbox.length; c++) {
/ ~: q$ `; b* Y9 c8 }+ U0 qvar no = new option();
3 T2 h) R2 a' T0 ^7 h5 O( S  ?. f+ cno.value = arrlookup[arrfbox[c]];
- P" Z# l) n" D0 E* kno.text = arrfbox[c];
6 R" i! ~5 q+ t0 ufbox[c] = no;
: ~$ c. D+ N/ `* v}
6 M& l+ P- P/ G' Lfor(c = 0; c < arrtbox.length; c++) {" N' I) G- l; N8 S
var no = new option();
* W1 F# I3 l( J6 g1 h' J* E( Mno.value = arrlookup[arrtbox[c]];
) i$ E, B  L2 T0 @no.text = arrtbox[c];. H1 r1 \5 w) w4 L
tbox[c] = no;
* C7 X; w0 H5 S  c4 E6 p' H   }
) [. z& G. O( d" |, l* j0 ~}
9 V  [0 e7 n, Q# k. q% _; e" g2 {" d</script>4 a7 F8 V* e) V" j( u$ u; p
</body>8 K2 j9 V. S. Z1 V  a! `

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