返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"+ G! @- Z: P+ l; t
         c pageencoding="gb2312"
5 }* b8 T# l1 g  F& `* k%>
9 t4 E! S0 u2 H8 Y; n<style>! p& |2 @3 z! M
.f9{ font-size:9pt; }
: ?5 `) N) ^! j* Y- I5 _- I( h.bgc{ background-color:#aecaf9; color: #0033ff }# ]1 X9 ^' }. }
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;9 U, F% l; E$ t
  border-bottom: solid 1px #4e7dc1;
0 c' c  o4 Z# Z4 @9 s9 Z  border-left: solid 1px #aecaf9;
/ [# \7 Y8 y2 ~* n  border-right: solid 1px #5679bd;) R+ [$ C! h. x8 N9 S( q5 F& g9 k
  padding:1px;
" M; ~! w; d$ D/ x  margin:0px;}
7 S, @  r1 O- K; i1 J) G2 p</style>
8 c+ r; o, f" R6 T! [% K7 u/ I<script language="javascript">+ N! ~! }4 T& ~0 B
<!--
  V9 o0 O0 p# V3 r/ O- Lfunction rv()' u! l7 W$ S) X9 \. A( t3 d9 D( t
{
6 [  t' w! O9 J8 y! G  var val="";
: ]1 E: L+ S# n% L4 U  for(i=0;i<combo_box.list2.length;i++){
" ?0 X; S/ e5 Z4 }0 ?! [   val+=","+combo_box.list2.value;$ p) B+ w: n" u9 i3 n, Z" C
  }
# u( q1 ^6 B0 ?; _  if(val.charat(0)==","){
8 v% J8 s( W# {5 t( @   val=val.substr(1,val.length);8 y$ t3 @  i" I, k2 S, X
  }
2 Z  p) d( Q9 p0 f  opener.form1.frecname.value=val;0 n6 w8 k9 s/ m; k" k' |
  self.close();. `/ X3 m5 X1 K
}7 Y. [0 T$ m9 J0 k
//-->
' e( i, k5 t* \( i% y' f+ Z. `# D</script>
% b: V/ H$ W1 Y) P<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">+ P* L) ^4 @1 [2 B# N
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />" Z7 a/ e5 F) h% P
<%, R, x9 h1 v% U# }4 D
  cdatasource ds=new cdatasource();  //数据联结bean实例8 i9 e9 ]$ n/ h9 b4 y7 x
  java.sql.connection conn=ds.getconnection();
) I! c, r# N2 D: E( {9 @5 }% j, `5 J  java.sql.statement stmt=null;- n' y2 Z' B$ l4 m9 c
  java.sql.resultset rs=null;
) f& ?* [/ H6 L$ F6 j/ U9 o  t  cdatacheck dc=new cdatacheck();4 f" d5 \# g. s! k, s
%>
7 o2 N  J( [- y4 t2 n" \/ L<%& u# `1 F" [& `8 ^
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";+ A6 f4 e- Z/ R9 W% Y
stmt=conn.createstatement();) D" d3 n- T: u2 ^( ?0 A
rs=stmt.executequery(sqlu);! N0 R- a2 m" h* z( \
%>
5 H8 Q. z* v6 O9 G<script language='javascript'>+ w! z) N8 V) I
arr = new array();. G$ C2 }, v' |+ l) K: u5 Y
<%  int temp=0;% R, }8 z) |* ^1 o0 t$ |* p! L2 _5 z
while(rs.next())9 ~9 \, Y& e$ f: c  l
{9 D, e8 s% n: c- B: p$ z
%>0 T5 K6 g; M7 \1 F. I9 i3 o( w
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
( f, D9 E; o: G/ N" f1 G<%
* ]8 F: [  U7 I8 M+ v+ n  S* utemp = temp + 1;
8 ?- R  _: P/ E( `5 v2 R1 Y}
# S# U% t- K' _%>' b5 p5 F% z9 H" w
temp=<%=temp%>;4 j' A$ y9 C2 n$ W- S% U6 _" h
function changelocation(id){
  {1 q0 @% W8 c" v$ i* Ydocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
/ D( b& Q. k2 J' S' W2 f- a8 fvar i = 0; 2 l& l! n/ W, L2 ?7 P, s) t
document.combo_box.city.options[0]=new option('-------',''); 3 c# A. K: I0 T2 u( u5 m
for(i=0;i<temp;i++){ 0 e# W& n' u$ d. A
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] # [5 D$ D/ P3 |& A7 [
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
3 ]. X0 h4 A' t" V2 x1 R! }+ y} 9 F+ ^, D. }) a" J2 t
}
; D  j) F) A* E" t2 d}
! z* L; y7 s' e  _' t4 z" b2 O: h0 M</script>
% r( `: o+ A( F) P+ P( K5 s9 p' G% F8 m' W5 R/ B: {# q6 B
<form name="combo_box">2 u3 R3 _- K5 C) P
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">* Z& ^9 o8 i, o/ e! V5 b
  <tr height="24">
' @; K5 n" Q- h4 k+ v$ N8 |    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>* |: Z+ w# z1 Y8 m+ n
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>. E3 z0 V3 a* A" X! C
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
" ~8 a6 u( {8 F    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>5 c& {* }! J" {  k) m8 N
  </tr>, H8 Y1 q$ M# R1 M
  <tr> % B9 x( @7 C$ [4 U4 g4 c: m
    <td>
: V4 r( Y5 C+ `; L9 i# g/ ^( [  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
1 i! _) q- Y$ r9 a  q2 G2 O0 \  <option value="0">请选择部门 ---></option>
$ C; n+ k! W) g% `<%
4 `" i' u% N; C5 [# D    string sqld="select * from tdept";
. S6 z: [6 P% M6 ]stmt=conn.createstatement();: z2 o) o% u3 {9 Z4 i' s( U
rs=stmt.executequery(sqld);
9 d( D8 o" k* L3 J. i: j) Pwhile(rs.next())
+ o9 C- s3 g& Y" K( U$ Q{
/ m! M. p6 ?" J: ?; g# g9 A%>' ^( r1 ~7 r# g; ?! t, N
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>( n) q) Q! G8 A0 |
<%
( K7 j* c! z- l& B}
: @2 K* I5 y3 g7 O1 D1 c%> 1 T4 B7 f& H0 b& n5 q8 `! z7 j0 h
  </select>$ ?/ r% {8 T: p# W1 h
</td>
# ]3 \  d( Q5 j( @    <td>
- P/ @- d. K! N& w  <select multiple id=city style="width:150;height:200" class="bgc">
6 x9 [0 R8 s7 D5 d8 }: y2 t6 ?  </select>
5 j* `1 o/ Y8 a) U8 G7 A</td>2 V$ g: Y" C% |0 y5 A) R: a
    <td nowrap align="center" class="bgc">
6 A3 `  z! L6 W6 \3 U( L( n1 {  <input type="button"  value="<<" class="buttons">- b3 Y  y5 Q; Y; R
  <input type="button"  value=">>" class="buttons">
6 H; \/ `' P8 g! ?</td>
, P' l* U) h$ u  s- i3 V    <td>0 z* q( V. x& c" C) n6 L
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">" j& P7 Q& h4 M% X/ b; e
  </select>
! G* ~+ p5 H8 G</td>& F  ]' f: C% B( P! O  h8 ~
  </tr>6 `( N) K& q& {0 d
    <tr class="bgc">
0 j; K$ M5 V4 r9 n$ E) R    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>+ H- ~* P4 d& v* a; c
  </tr>
2 p+ x# n3 R' N3 c</table>
0 n  v) q1 d) y2 C" v</form>
% r8 r" j* H! ?) }, C<script language="javascript">) g: H* f+ a+ R& h, m1 ^. q
//人名移动$ w. H/ q$ U2 A7 ~2 a
function move(fbox, tbox) {6 l, j( g) D$ ]
var arrfbox = new array();
. l+ y) |! G  J( p( c7 s) Z# ?' tvar arrtbox = new array();2 S, D$ V/ c, R( K2 F! A, N) w
var arrlookup = new array();
1 M( l' T) `0 y$ V* {' t; ~var i;) Q5 p: U9 x; s) [2 m
for (i = 0; i < tbox.options.length; i++) {
8 m( M, I& T4 t$ G% q$ Carrlookup[tbox.options.text] = tbox.options.value;
+ n% Y1 G, d$ N' C0 ?' M4 xarrtbox = tbox.options.text;2 k0 p$ b3 m) m+ X+ A
}9 i4 T% D* x8 o  f5 n& U8 f
var flength = 0;; r" ]' Y8 q; V+ R* m7 E$ `! ]0 _( ?$ D
var tlength = arrtbox.length;- A1 I! P6 H  _
for(i = 0; i < fbox.options.length; i++) {6 F; o* g* w) \  \9 h  q6 ]$ m0 |
arrlookup[fbox.options.text] = fbox.options.value;7 S' L" m0 R/ e& q& k; o
if (fbox.options.selected && fbox.options.value != "") {
2 ~3 P, f! W# z9 V/ f- c3 Yarrtbox[tlength] = fbox.options.text;
5 M" Q* }0 ~% n3 Stlength++;6 R: `' X7 p9 W4 L9 N/ J
}
/ I6 A9 N8 z. q7 Zelse {. e4 n( I8 Y/ p" ?% ]' _) v7 ?
arrfbox[flength] = fbox.options.text;; E" G2 G8 r4 D% T% V
flength++;
  [, f" r4 ?5 }- G   }
8 q. K0 L4 q4 Y# T) A}5 f  c: u2 Q6 p9 Z- M+ s
arrfbox.sort();
  D; r' _  b) E( Karrtbox.sort();
; U1 ~8 M* y% z, A* S% A  k- ]1 k% q# z9 g7 f2 n/ S
fbox.length = 0;/ B7 p) D( S1 m! U
tbox.length = 0;, \9 E7 i7 Q5 U, G8 Q2 l8 z5 O
var c;* b. p" S# E; T" `
for(c = 0; c < arrfbox.length; c++) {$ |8 s6 I% F) ^* N
var no = new option();
) C6 g- i! c: Jno.value = arrlookup[arrfbox[c]];
3 d+ R  v& p0 lno.text = arrfbox[c];- z0 M+ f- i5 a. z
fbox[c] = no;
: X: k5 ~; b% ~, P5 w}$ {+ j8 u; t( [/ C# b4 o0 ]
for(c = 0; c < arrtbox.length; c++) {
. _  i* X# c# jvar no = new option();0 X7 ^5 B5 Q6 \9 n" @& Z4 Q7 g
no.value = arrlookup[arrtbox[c]];
8 z0 u$ F% ^8 A: ]  \4 Pno.text = arrtbox[c];
, o% A! w& ~+ f& }  `) utbox[c] = no;4 v  G2 M, i8 R% l, q! U* T1 f# o
   }& Q0 I" t5 g7 G, ^+ x8 y
}
5 o' f" p) C+ n8 k7 l  g</script>$ Z/ Q9 C; C. ^; H3 W6 p
</body>
0 V  T/ q) J# E5 _% I

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