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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"2 {$ I% X0 L+ l3 P* i0 G* A, d
         c pageencoding="gb2312"% o% Z/ z1 L7 W8 A( F
%>' w) _8 m$ G. q# Z1 z0 u) R+ v
<style>5 m) ?: }4 v; c$ \9 A' k, f, r
.f9{ font-size:9pt; }
% d9 n" v4 a+ ?: E0 I. `.bgc{ background-color:#aecaf9; color: #0033ff }! o2 r% ]% q5 V
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
/ H  C. A) M. {" r  border-bottom: solid 1px #4e7dc1;
/ w, @& r+ S+ p/ |5 {( i+ O- J' u  border-left: solid 1px #aecaf9;% J( d2 H( A" o$ n5 _" f
  border-right: solid 1px #5679bd;
- U$ S6 ]6 {% w. P3 s  padding:1px;
  Z& _2 h2 t. n; t. q% P  margin:0px;}1 ]. @& b/ {1 t/ s
</style>/ W1 ^0 C/ \  v% g3 _, ^; w: H# z$ E! s
<script language="javascript">7 [- L4 ]5 ]3 S$ D  Q- E7 ~! P
<!--0 R* H/ ]& ]& E) f+ e
function rv()* F$ U$ [& B( T; f  V- \& ?' q5 r
{2 m2 v, p- J( j- I
  var val="";/ \5 [1 ?! L& ^: i) e% b4 U) G
  for(i=0;i<combo_box.list2.length;i++){' S2 o9 c- s: w
   val+=","+combo_box.list2.value;
( d' n5 o' m( {: j  }
( }4 l. P+ o2 ?3 v  if(val.charat(0)==","){
- b2 `/ A9 \$ U: t" m" F   val=val.substr(1,val.length);( k" y9 I' `- o- X& \* P
  }4 U; W5 s# s6 I1 e) q$ W& Q4 I
  opener.form1.frecname.value=val;
3 n0 {6 v8 O# m6 D% C4 U/ F  self.close();% e' ]+ G' m& t3 W
}
6 x: g$ S* d0 k  K* y//-->0 R/ D% Q/ F( p4 [& q2 t2 L
</script>0 {! v" @: K) u, p  u* X" `
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
4 W9 {" m( B  T) ]5 k1 B. Z; r<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
! s; p7 s% A0 {<%8 i  C+ [. V" ]) k
  cdatasource ds=new cdatasource();  //数据联结bean实例
/ Z0 N) {" a/ K2 |  java.sql.connection conn=ds.getconnection();
( }" U6 I) L: D# A$ H  c  e  java.sql.statement stmt=null;
  x$ y% x7 g3 j4 e! z  java.sql.resultset rs=null;: y1 n) P0 B0 w5 K) J/ k9 b5 e
  cdatacheck dc=new cdatacheck();
0 B) Y0 a. S5 L! P* J* u2 Z+ f%>. |! f! s, D6 Q; y; `) I, C" g9 l
<%  ^5 {4 n% ]3 k
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";( i# k3 s  q. c
stmt=conn.createstatement();
2 m# Y3 \7 O. [' Y# I  J9 J2 T3 yrs=stmt.executequery(sqlu);! x) L9 W; g# w/ A2 r" }
%>& |6 W* X$ p; q
<script language='javascript'>1 g3 R0 c3 u1 |  @" G) Y. b# R
arr = new array();* _7 `8 y* w$ P/ r5 Y6 k! ]2 [
<%  int temp=0;
, ~- |4 ^' S' g# bwhile(rs.next())+ [  }5 A# Q4 T" r$ j
{2 I* H# z" ?; T9 U$ k
%>5 n; f! k, {9 j3 b  R4 o
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");1 s! p% U& i& v
<%
: ]. g- [5 I1 s% \& Itemp = temp + 1;
9 x. c& C* _/ q* Q}
7 C2 t8 |7 w8 r) g8 x%>2 @) }* `% a! h# b
temp=<%=temp%>;3 s- [1 R) {  c+ x
function changelocation(id){
+ X0 \7 c, j5 ?9 V, W, ^9 A! Fdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 ( {: w" }! W& ?# Z& h. W
var i = 0; * B! g, ~( T  Y! Y# m! |1 l
document.combo_box.city.options[0]=new option('-------',''); & C4 }4 j5 z! H1 r* z% `! l: D- z
for(i=0;i<temp;i++){
7 v  Q; s' s$ D9 v* M# Eif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] : F) c! b$ x9 s4 C! s
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 1 F: |) l# U6 T- P" t/ l
}
& F9 b4 @6 N" s4 V0 L* s* L} 9 o5 M0 @; l0 _8 w4 c3 P
}
' T- m: O+ |# W6 ^  u- N* e% Q</script>
3 z9 t! k7 T+ b& U8 m6 k1 u& B- c: c- P5 l  O* J% x! X- y. F
<form name="combo_box">, U, m* l( z  R8 d) A  k
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
4 Q& q1 t% \. Y2 q  <tr height="24">
* L0 k% k( S' a- y. d    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>) x0 G8 }! {) J7 I+ j) R7 U
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
# D0 Q# d, D  ]$ C% n; j- c    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
) \, z7 Z: q' w) h/ S    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
& p: F3 N* m/ c3 ?7 q  </tr>
8 b$ d, h" y2 i6 }- I: E7 l" ?  <tr>
' D+ `3 _4 a, L) ]    <td>
, h8 o: y" S+ H( t9 Q2 u7 L( S  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">6 f- U! J2 N5 r& f5 J$ `9 R% d
  <option value="0">请选择部门 ---></option>
# {! s3 t* B: u$ F" j1 R# R<%
$ F2 i8 U+ Y8 s- R9 V    string sqld="select * from tdept";6 S) h& e4 w3 `( M$ s; |# ?3 U
stmt=conn.createstatement();. j( R9 C7 a5 v9 S9 }3 P
rs=stmt.executequery(sqld);
9 I2 i  p' r( K) V- E' Owhile(rs.next())
: t% y( p, Q! \7 j* M9 f$ v{
% p2 S/ l* N% ~' \%>$ K0 Q1 |/ L  A. c
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
5 M; l9 M+ \0 b; j2 j8 A9 Z<%
4 F) E) Z$ h1 d( T/ G}
; m4 M- L6 C8 e1 `6 v, h%> # w; }0 i/ L- h8 r' w/ f/ N
  </select>1 o1 p1 }$ I4 `% m4 M
</td>
& D4 X' ]1 |* c8 n: ?/ U$ a# K% j    <td>& ]  v2 j: f$ r' k) I" I7 m
  <select multiple id=city style="width:150;height:200" class="bgc">
) V. X& Q+ _- M" g  }5 v. c4 H  </select>+ ~! H5 V9 ?, m9 Z6 r) V! K& V
</td>+ ]- \5 b2 O% h* k9 M
    <td nowrap align="center" class="bgc">
  m9 i  }7 y' D2 H  <input type="button"  value="<<" class="buttons">! Z, w2 I, a7 P% q
  <input type="button"  value=">>" class="buttons">$ D( n, @0 r$ d6 F+ l
</td>: t; B6 N: B2 @8 T
    <td>; l3 B9 e5 Q/ }- c: m
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
3 h, V& c6 l- z- _: R  </select>
# o7 N& H/ p8 Z  e) M</td>6 d/ w. s& |4 Z% _
  </tr>' }2 H/ W- E: Y( j1 C4 M
    <tr class="bgc">
# X# P) ]2 |4 J    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
/ O* m" ~7 ~) C- C& S) ]3 G  </tr>
* V0 r1 @; v# Y9 t+ M4 S& E</table>  f( v; a* {! p, B1 \
</form>$ ~6 [( C' K$ E: l3 K
<script language="javascript">
2 A2 W; N* P) F8 g& O3 X& }5 F//人名移动
( r: K3 S/ ], |( l# a9 @+ g" D5 R4 vfunction move(fbox, tbox) {
% t4 e: Y5 v2 G0 w  Kvar arrfbox = new array();' _- N4 y; K  I, e0 Q
var arrtbox = new array();- c$ J+ h4 I8 f4 U% s$ Q3 d3 B
var arrlookup = new array();# @0 S7 v) O+ `: M
var i;
& F* N2 A0 N/ W. B% ifor (i = 0; i < tbox.options.length; i++) {
7 ~7 c7 Y# u" g9 darrlookup[tbox.options.text] = tbox.options.value;
1 G  k* t0 k5 e* m' g) k$ yarrtbox = tbox.options.text;
% K9 F% K* V8 N}6 S  C6 \2 j2 I0 Q
var flength = 0;' F' u) C8 w. |* }: y
var tlength = arrtbox.length;
" N  ]" T7 R) U; z7 Nfor(i = 0; i < fbox.options.length; i++) {4 ^4 Z0 t! R7 o, G' o# \/ N
arrlookup[fbox.options.text] = fbox.options.value;0 O" ?1 D& X3 ]  g% o4 p
if (fbox.options.selected && fbox.options.value != "") {
3 s4 i0 z1 N0 Q! N" R9 M$ uarrtbox[tlength] = fbox.options.text;
0 S4 T: p3 b/ V: P' Ytlength++;4 e' {" m& Z2 k7 ^9 q
}
+ S6 @$ L9 m) w9 O8 d( Pelse {! C3 V# ]) L, G/ I1 v
arrfbox[flength] = fbox.options.text;3 ]$ e/ h+ ?/ C) {6 K) R
flength++;7 r7 R" v6 M1 D( [$ Y" Y9 w
   }& K0 |% o* C7 L# F8 Z2 U  P: o3 c
}
# e* u- o' Y5 b5 Tarrfbox.sort();7 }, q( J2 G, U# s
arrtbox.sort();/ r+ u" }" J# @* ~8 O0 N7 O( w
6 @1 f4 v. ~: Z4 ^/ x$ k& L, s
fbox.length = 0;+ y2 J; ^4 v) |6 k" h
tbox.length = 0;
) h/ ^; b1 g9 tvar c;: Z' |+ a2 Y6 B. u% I6 N, u
for(c = 0; c < arrfbox.length; c++) {
' H* X% R& X5 C* _var no = new option();+ n8 I! ^& z, N# _# E8 O- ~! e
no.value = arrlookup[arrfbox[c]];$ Y9 r1 ?1 c  Z3 f, {
no.text = arrfbox[c];& G# q5 i) s% g& r: S! H3 ?( ?( z, K
fbox[c] = no;
# D, x! M, ]. h}! Q6 w8 L2 z' f
for(c = 0; c < arrtbox.length; c++) {7 ^- }# ?1 ~& d' |
var no = new option();$ f/ L$ v3 j4 H; q" \* a
no.value = arrlookup[arrtbox[c]];
" L' E! Z, a" D. @1 q* Qno.text = arrtbox[c];
$ |3 }0 _! l9 B# o# ltbox[c] = no;
& w, R1 R2 Q' y0 b3 i   }4 m& B, m/ T5 Z! v/ P  t$ Q; a' K( x. N
}
' i" |+ s- ?4 X( A0 m8 p; u7 B</script>
1 g1 C8 p, |! D2 q9 _4 k- L) |  X</body>
! _8 {3 E5 ]* k& D3 p$ [( n

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