返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"0 ^7 M, k& F9 R4 |1 V
         c pageencoding="gb2312"2 g6 [+ W. G6 T* M. _
%>
' i. v! m3 j  u: b# `' l3 v<style>
- G( h! k  o+ c8 J.f9{ font-size:9pt; }
: p* U7 L2 G+ c* ].bgc{ background-color:#aecaf9; color: #0033ff }1 p- S" G/ }: f. t: C+ A/ n! U
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
/ Z. N; S% F% U  border-bottom: solid 1px #4e7dc1;8 s2 s( Z$ b  D* k! R( D
  border-left: solid 1px #aecaf9;, [2 V, U5 ^1 c# ]7 ]( x
  border-right: solid 1px #5679bd;
2 Z% g; G+ T* G/ q* L$ Y# x5 I  padding:1px;* m! c6 v& r! D& e) {5 W5 i8 }
  margin:0px;}' z4 D/ _/ H1 w5 i2 G' A! D/ d
</style>+ C. n7 [; w# J2 N& F: X  S- f
<script language="javascript">. E) x; v. f3 R' @- r
<!--
+ a  v, t" y5 d8 n2 ~0 `8 o' V; Ffunction rv()
2 [/ b9 L) B" D{
* N7 H6 ?2 T! N4 J( S" G+ t9 s  var val="";
3 Q1 v& }- _6 A2 g* h! l" z; S) x$ y- O  for(i=0;i<combo_box.list2.length;i++){
3 Q. K7 h* m8 U- E. N* p6 I( C! Y   val+=","+combo_box.list2.value;) _  D& `) v, v6 i0 `4 `6 C# f. u
  }
# N% A7 K9 W: W- @! e  if(val.charat(0)==","){
- ^4 I0 @( h( K6 S   val=val.substr(1,val.length);
, U  R3 V" B* m+ Q. U& `  }7 v1 A4 g8 {# g
  opener.form1.frecname.value=val;- E- c- l, \: W( G
  self.close();
0 v: z7 J: t6 b' `; B}  P' t) M$ ^, B; v  j
//-->2 ]* R3 c  l  ]  q. o! }
</script>! @) _1 O( b/ R
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
4 J' a8 D0 p- ?/ D% ~- T( u<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
: {: k* U! {$ d( q. N<%, Q7 I8 A" f/ C" S: [* p
  cdatasource ds=new cdatasource();  //数据联结bean实例
/ _$ p+ |" i# `  java.sql.connection conn=ds.getconnection();
* p7 ?# U* y- c# d  java.sql.statement stmt=null;' N/ d2 ^2 M; B, X
  java.sql.resultset rs=null;
7 U( u& }" i+ d8 }  cdatacheck dc=new cdatacheck();- Z/ x( i1 M$ L' Y8 M; R2 [6 v5 \+ ]
%>
4 M* e  m$ L; ^8 x' b8 |" V<%( o0 U& c) Q/ ]4 a- 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";
% Y- ~3 q% p3 Vstmt=conn.createstatement();; I3 b7 Q/ O' T( n) a) H* F; P
rs=stmt.executequery(sqlu);
3 ~" O. |6 a; ?+ P, h7 `%>
3 q3 j1 s( z: ?2 D<script language='javascript'>
" ^$ W0 l' H7 Z5 B* p2 K( parr = new array();
- J1 a) {) o( m: f( m<%  int temp=0;; _, {2 ^) A. l9 q/ }3 J6 h
while(rs.next())
6 r( I, C" r7 P  V% E& H( o# s{
# p5 [1 Y  x0 R$ A+ r/ ?5 e  j%>
) A3 o$ I# |3 S7 G8 ?5 U; warr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");  T& N% u* k% c7 \+ Z
<%
/ w6 @3 ^$ |+ U7 Ctemp = temp + 1;! [: X$ F) X& X! ?2 D+ d* h
}
- F9 Q9 G3 h8 P5 j# G1 g  y# p; a! S%>' f! S) Q  n( g! m' N4 @! J- a
temp=<%=temp%>;' }1 L8 n0 u, r6 i3 a0 J
function changelocation(id){
. p1 W7 _/ `  e" y. P" R% J. P( ~! adocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 / a' ^1 z, v; d
var i = 0;
2 I2 n5 c9 U& W0 {document.combo_box.city.options[0]=new option('-------',''); 5 J1 ~9 p8 I+ v) ^2 B& N) \
for(i=0;i<temp;i++){
  {3 D& b) c& mif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
6 U: \) P' u4 I3 j2 d0 R! X$ x. ndocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); $ n; P7 K% x. Y. O9 m
}
1 L5 F" n) o/ J}
7 I8 R( z9 @4 {$ B0 S} % E, Y5 O9 h5 ?2 K
</script>
: S2 v7 w  _+ G" g8 b8 G1 L' g7 _0 T5 [- `0 ^, Q
<form name="combo_box">
# u( O8 p: |! }! {0 X3 `" t/ K<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
; k& m8 G3 k, p2 @. a5 C2 Y  <tr height="24">
+ v% W( p7 o- d# p; {8 v, P    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
9 q' H' H$ a9 N" h, u    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>" F, U* k# B: A- z( h9 X  r
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
8 F- |/ _; U0 h) n" }- U    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
1 ^& J" G( L) p: w  </tr>2 N5 m2 ^! _' W/ l/ H8 B
  <tr>
. H/ Z5 ~2 s) y' g. w4 W3 w  S- H    <td>* N% ]: F7 t/ ^" s$ Z- f3 X
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">+ [$ b+ w- t- L/ W6 Y7 p
  <option value="0">请选择部门 ---></option>1 O7 i! a. h. ~5 w2 L/ V" C
<%+ c9 Z& Z4 O, c" a3 v* g6 o
    string sqld="select * from tdept";
* k7 y0 G- S( C4 R; b! T. ~' T; Wstmt=conn.createstatement();0 d2 I; ?; y  F
rs=stmt.executequery(sqld);
7 _8 k* ~$ Z9 T# Y6 r9 E( S& Gwhile(rs.next())
! B; G9 Z! X" v$ [) o4 C{
& F& c. u' k8 p4 h%>
" w9 i2 ^6 |4 @9 ?3 g, R0 W5 f0 }  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>4 L; k! b9 r7 s6 F8 b+ ]
<%
, b; m- v5 K( ^}
, H- m& \# _9 q/ g0 D7 _; p( N- H%>
' }' T& o% R9 U! t% h3 S$ M  </select>4 |) T$ A8 g$ u0 s
</td>; q, {: t, v' Z+ l
    <td>4 F) ^' G' c+ s' D# H3 D
  <select multiple id=city style="width:150;height:200" class="bgc">- F) a6 }8 B3 g3 w: p* Z
  </select>$ `6 e4 Z( j- [7 V( }
</td>$ P) [. L" l; Q, g: S1 K# {3 c
    <td nowrap align="center" class="bgc">. l) {' u+ [' D  ?8 D+ _% i
  <input type="button"  value="<<" class="buttons">
6 U9 W* Z4 g; b% W6 u  <input type="button"  value=">>" class="buttons">8 K. q8 }$ c8 ]/ c; I) i: |
</td>
" W$ x% p( G% b; Q    <td>
% n+ F7 u' S! G: K" b  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
: Q# y7 ?1 z; s3 m  </select>% ?2 Y* ^# k' l- h0 j
</td>
3 {8 c; s: x2 k$ e  </tr>2 S3 W& S% ^0 _+ r7 G
    <tr class="bgc"> , e% e/ Y: |4 z0 J% V7 `
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>; A4 k7 h: N2 w
  </tr>0 K: r/ ~9 G. v7 ]2 g
</table>
5 a- d, g' [* g6 Z) |</form>
2 B% y4 g/ e3 L7 J! M( J  l6 g<script language="javascript">4 @. V1 ?& }# z# Q  E) f6 L- K+ Y
//人名移动
! c" T1 i0 Q/ Ffunction move(fbox, tbox) {7 j4 V9 B) e8 h! ]& q" h9 N3 _
var arrfbox = new array();, W4 `/ w1 s. o! e9 E
var arrtbox = new array();& _4 x( ~% }( a. L( v# J2 T) m
var arrlookup = new array();+ h0 T' c/ ^4 n( d" d  ?# ^
var i;
. w/ \. I3 J! ^for (i = 0; i < tbox.options.length; i++) {* }% w, q6 w# p+ o. L1 _1 p( {
arrlookup[tbox.options.text] = tbox.options.value;
! B- ?0 T0 ?6 r0 warrtbox = tbox.options.text;
7 [: g8 M) n& U! R! q}
! T# f( u( @$ [, y" P0 [. svar flength = 0;
: e1 h6 o7 t8 m7 }" G5 z( J' nvar tlength = arrtbox.length;
% j; C) ]& k# E! ?8 N  N/ K1 E2 hfor(i = 0; i < fbox.options.length; i++) {
+ W6 t5 h1 C# H+ [# D! [* iarrlookup[fbox.options.text] = fbox.options.value;
4 [2 P+ G2 h5 i9 qif (fbox.options.selected && fbox.options.value != "") {' @( D; s: v1 T0 e
arrtbox[tlength] = fbox.options.text;8 [6 z1 o2 _0 w
tlength++;
  o# r$ C8 D7 [0 h, ]. x# i- c}8 B. n& |6 a: J8 F' p) e
else {
: B: B  ]! k: o7 c9 ^arrfbox[flength] = fbox.options.text;
% L7 j4 C9 D. A# qflength++;
3 m2 ~; D" t0 Z. C: F) t0 B   }
5 }+ G2 I+ u, S' J* Y4 q' O* G}) P: T" a# T3 c# B" ~
arrfbox.sort();
' h+ v. @" E* F& m4 I9 {arrtbox.sort();/ o4 C; {: p$ {6 G

) j6 z+ R$ v; g  y( U5 afbox.length = 0;3 a: q2 R4 f2 h
tbox.length = 0;
4 W1 @4 U. J+ g& R$ y* l7 d8 t! Dvar c;
4 `& x$ J: f3 d; o: K/ Z2 ~for(c = 0; c < arrfbox.length; c++) {
5 T* D( @) m0 S# {+ u; Y  p0 m; Bvar no = new option();8 O5 D" P$ R9 E
no.value = arrlookup[arrfbox[c]];
8 |1 F; B# n: R2 {& V) C1 c) M) g7 lno.text = arrfbox[c];2 s" N7 A! i: T+ x- n
fbox[c] = no;0 D7 e1 ?3 t4 |/ o: y5 c- d7 d* s
}
4 \( `9 Z9 O# A( R+ j; H6 ^for(c = 0; c < arrtbox.length; c++) {& F+ K+ A) h& R* [
var no = new option();
5 q+ B# h% i$ W2 t" ?2 Z; o. C6 lno.value = arrlookup[arrtbox[c]];2 Y, S0 {" N. q% ]' n  h" a
no.text = arrtbox[c];9 ]+ Y4 g3 O1 v! w5 ?" @" D
tbox[c] = no;* B# ~% h# S- K  |! m8 F+ W
   }7 L3 b0 X( J" j( X6 u5 O% v0 {  R
}! q& S9 @. r/ N7 R( F
</script>
: ^6 u/ q( E* i</body>9 s6 `0 w" [! g$ I, ]1 u

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