返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
$ N5 C0 c$ k, i4 G         c pageencoding="gb2312"
: X1 l& u$ I& ~' @* G0 J%>: I; u6 R0 g' c6 E+ p5 d) ~, m3 s) p
<style>' o4 Y( M2 y9 n( U! z
.f9{ font-size:9pt; }' v# q  d) T+ w
.bgc{ background-color:#aecaf9; color: #0033ff }: i7 u! G+ s% D% w( Y
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;4 }+ \! c4 O$ F' \; ]' y
  border-bottom: solid 1px #4e7dc1;; f% Z# w( y5 D  Q
  border-left: solid 1px #aecaf9;
: X* v+ G' ~# E" \, }! ]  border-right: solid 1px #5679bd;
5 |% }2 X& P# U0 e! S1 f$ X  padding:1px;; q; P  G2 L. B3 d( R
  margin:0px;}& K; c  U0 ?9 ?
</style># p9 F- l/ H% |1 I. a, W
<script language="javascript">, y+ m/ @9 D; v+ V+ G3 S+ R
<!--
7 Z- W. L: X0 A% jfunction rv()/ _" t+ H& s2 R
{
9 h0 U/ r$ u3 @0 w: q% J$ p/ x& i9 z  var val="";" F3 T' J( |% @' \+ l: a: d3 ]
  for(i=0;i<combo_box.list2.length;i++){3 r+ j/ }, L/ i- K/ g# g
   val+=","+combo_box.list2.value;' ?  u+ Q8 @& Z, f9 V
  }
& q3 F- P8 z+ w  if(val.charat(0)==","){# i0 H2 }- W, x! _% N* t
   val=val.substr(1,val.length);  `- P+ g4 w7 ]
  }2 k. ^. g; w8 G: s6 e0 }
  opener.form1.frecname.value=val;
" |4 E+ r$ |7 D; m9 N  self.close();5 R+ V  d/ h/ o, E1 ?
}+ c5 I8 J4 ]. x9 H' w  {+ V
//-->( G; N5 g4 X: K8 l
</script>0 Z* w7 p9 W# S- L
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
/ j) R# \7 O+ y- X$ k8 `7 A2 j5 ^<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
) u" g! d2 `/ k8 S% Z6 g<%
) `/ T( D# x" C! p" F( F. d  cdatasource ds=new cdatasource();  //数据联结bean实例! m5 j( M% J2 g5 f$ r
  java.sql.connection conn=ds.getconnection();( u2 Z% g* P- r# v& V# v: M
  java.sql.statement stmt=null;- Q! E" d. D6 y3 A( g) ~* i
  java.sql.resultset rs=null;
  j; S2 H* g' s4 g$ l# O0 Z  cdatacheck dc=new cdatacheck();
0 C  a% E& d) J2 s%>
7 z. S' Y- M! S- ]9 m<%
" f/ h8 v; p5 b1 A* S+ C2 v: ?, Pstring 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";' R3 G) w& @4 b% d
stmt=conn.createstatement();; V2 R1 p* A# {) N( o4 _
rs=stmt.executequery(sqlu);
6 m' o' O# L# `# \  R; H%>
% d# |& y0 K# h4 w# Z<script language='javascript'>
5 }) s5 Y8 E1 {2 carr = new array();8 t) Z* h. `# W9 ^# l+ @# I
<%  int temp=0;
) x: t' v9 s* s3 d/ i7 t9 E  m$ Twhile(rs.next())8 _) u$ q! J% F1 Y- ]2 F* z
{1 f0 L  A# q, c. f( {
%>
! H7 v2 H3 P) yarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
/ S1 @2 V) D& t/ |$ ?3 R; T<%5 O* R# s5 `$ V
temp = temp + 1;" T' k$ b9 q& P  Y0 K' S" H2 l
}% R. v; z9 z% J: |& D% c& v
%>
$ V, f6 h* h: b; gtemp=<%=temp%>;
6 m. U: q5 R& T0 E- y- [function changelocation(id){
/ g/ u+ d8 Q# k  adocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 ) b& x5 o' i6 n8 w' k" }
var i = 0; $ I9 Z9 g, J6 {5 V4 e' F
document.combo_box.city.options[0]=new option('-------',''); ' S" t* w5 h3 n
for(i=0;i<temp;i++){
, B+ ~8 W; [/ wif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] ' Z! [1 p$ t+ c& m8 j/ \$ c
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
+ j% r/ F  \  R0 \8 Z1 }  W/ a2 [6 @} 7 i, H6 j  j4 u$ R
} 3 Z' k  a# K9 i# U" Z) ^1 _, G
} 1 s: D- v  W% K1 _" M5 @2 o
</script>( U, [+ ]  o) ^! M, ^, e9 W
- [! F4 |% S1 _; O
<form name="combo_box">. x9 P& J! `3 v6 R$ C2 x6 X
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">" p1 F9 a& D, p, X
  <tr height="24">
$ k# x+ c- P) G# @$ F    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
. q- `" s, d! Q& v+ h) ?  c7 E  K    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
' ?2 h. C# f, B; L    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
4 K8 w! t! D) G9 s    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>/ ]# L4 x' m% i" T, h9 P+ o
  </tr>
% I1 c' O  v, j  <tr> # g  I* q3 o4 k1 f
    <td>
6 A. J( \. {1 [0 R  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
5 [2 c& C& e: L" P; z3 f  <option value="0">请选择部门 ---></option>* J' m3 m2 a5 U- g6 {- ?' C7 `
<%& U" Y+ V# J+ t3 m
    string sqld="select * from tdept";; X3 ]$ h$ A( v* {$ o
stmt=conn.createstatement();
5 z0 p8 p* w! u2 P3 Z2 _rs=stmt.executequery(sqld);' ^8 |) e# X% D9 \
while(rs.next())
, {4 [& C3 y* {{) A# K6 p2 v8 @! s, w. d
%>
1 a, Q! `+ N/ l6 S8 b7 e9 b  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
+ e' E' }$ O4 W- K2 B  Y" Z& h<%/ d( |4 J8 C6 Y+ P, _, p
}9 r: ~' I  V# P' D
%> ; Q: u: F+ i& t; ~% N9 E: _3 _
  </select>2 o7 _: u8 ?! i; V7 X
</td>9 m( ~. B; F* t" t1 e
    <td>
- f" t; p5 v8 g/ Y, T  <select multiple id=city style="width:150;height:200" class="bgc">
2 G6 t3 ~6 Z  T- d; Z6 @# i1 S  </select>6 E, f' h/ a8 a
</td>. g2 A3 `! A9 Z' i
    <td nowrap align="center" class="bgc">8 l; Z$ o& K. Q# T6 s6 r" r. b
  <input type="button"  value="<<" class="buttons">
# w) S/ _7 `* B- N. r  <input type="button"  value=">>" class="buttons">
6 J# U- d* k5 n' x+ M* p' z1 Z9 Q</td>' U& i% n7 N2 h
    <td>
2 L" p" l+ q5 P# Q; N9 n) \4 T0 k  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">: k3 \3 k* [! s' _, G" |  y
  </select>( e7 G5 k' z/ ]3 u
</td>5 a- F( J; [+ v. N
  </tr>; I% v  W5 y5 l& J
    <tr class="bgc">
5 K  t; A% w3 d    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
0 c. v, @) y( A: K$ @( u+ W  </tr>' f1 j  l1 P$ w
</table>
+ V- E; s" B6 D</form>
3 z. {1 t! [) Z; ~. P9 G<script language="javascript">" P+ [* j* s2 n( s0 G( R
//人名移动$ _2 V5 ^% j% i1 X/ j
function move(fbox, tbox) {
+ i; y" G; h& z5 G9 g9 {9 e5 c. @, Dvar arrfbox = new array();
7 ]7 u* B2 V+ Y  N* |var arrtbox = new array();0 U% x% ^3 w  o! q9 C! o
var arrlookup = new array();
7 d2 m7 w0 F" j) Q& ^, fvar i;/ z. d4 e; _7 a
for (i = 0; i < tbox.options.length; i++) {; s5 e  q; h: i4 P0 v
arrlookup[tbox.options.text] = tbox.options.value;
# ?: \+ h+ k9 X5 c& garrtbox = tbox.options.text;
$ T) h5 E; a, ~0 P+ Q5 {}% i4 Z  a2 S- }& k# _# a0 U. u
var flength = 0;3 w# n2 P4 |: K: n
var tlength = arrtbox.length;
8 a' t" t4 B, sfor(i = 0; i < fbox.options.length; i++) {
' n7 R: o9 x3 l; O, ~" Z  |) z, yarrlookup[fbox.options.text] = fbox.options.value;
  p  k2 x/ c5 Z, Sif (fbox.options.selected && fbox.options.value != "") {
$ l0 [/ F) t+ garrtbox[tlength] = fbox.options.text;. D" h! G/ x: {8 r$ ?/ g+ ^
tlength++;- n& X2 t* b/ D5 b. b
}
9 B; ^' E/ L; {/ qelse {
/ J' Y; x2 s  o2 Aarrfbox[flength] = fbox.options.text;
7 k5 o+ B; Z6 d, Oflength++;5 q, s, i& w* q. T% s
   }8 E! f; q7 X' e4 Y8 V! v
}
$ _! z6 T/ ^% Q) {% tarrfbox.sort();
- ?# B2 C7 _. t4 \arrtbox.sort();
3 N& @/ z/ C. e0 I+ U5 _1 p# x3 M& \3 j# R7 a: k! e# U
fbox.length = 0;
! s& n7 ^3 S/ `( R4 |, xtbox.length = 0;' S* M0 l- H" n$ M
var c;4 V' ~. A: I+ h1 c; T
for(c = 0; c < arrfbox.length; c++) {# [4 X) M4 G6 ]9 w
var no = new option();4 T$ J, _) w! C0 S+ P' u
no.value = arrlookup[arrfbox[c]];* @: z7 M! N/ c  |- F
no.text = arrfbox[c];
3 K% g8 f! ]0 y& F  rfbox[c] = no;& Q/ {  X% _* |% c, P$ p
}
" E! e3 P" _7 l1 ?8 Z+ y. bfor(c = 0; c < arrtbox.length; c++) {7 B8 {8 j" i9 ]$ j6 }4 G5 `
var no = new option();! v) R9 R8 R7 F3 w* z4 a
no.value = arrlookup[arrtbox[c]];- P# {( j; W6 U5 N8 g- L5 _+ |
no.text = arrtbox[c];2 o* d; A3 E+ ^1 i. t9 ~. M1 g  p
tbox[c] = no;; X$ K  Z2 f6 H4 [* X, Y
   }
4 H' ^! `# Q1 x; X3 ^}+ Y% V/ a2 o/ h# V5 |/ j5 d
</script>/ W8 c  j) i( P  D  w8 P: \: P3 ~3 _
</body>
6 t. @9 A* p+ q+ ^& F/ v

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