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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"0 g7 S9 n; i/ [; P; w8 {+ \* {. j
         c pageencoding="gb2312"
' A: v% I/ W' Q%>
4 M+ A3 S) A7 E+ ]1 k<style>" Q/ w4 j5 w! c+ i' `
.f9{ font-size:9pt; }$ O0 z; M/ i& ~- k" z8 ~* [2 D
.bgc{ background-color:#aecaf9; color: #0033ff }
$ i  b9 x! @  V' \1 z8 h.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
  K% b3 `2 C. q. B0 j8 `1 o  border-bottom: solid 1px #4e7dc1;
  l: d2 c6 v8 |1 e( q  border-left: solid 1px #aecaf9;
1 I% l  Q+ \+ W; L  border-right: solid 1px #5679bd;" }. i/ n  f+ D9 L3 k  |- _
  padding:1px;
) `2 H# D  {* u( m& k  margin:0px;}9 ~5 Y  T+ {- w- w2 U
</style>  _0 @, k8 q7 u" p
<script language="javascript">
' h  ~. s- w' j9 S3 N<!--
0 s8 D4 `; r' @) n5 R# Rfunction rv()& N: @% m, P' l8 ^
{- a- N& L3 f5 H/ z
  var val="";) N# |5 |% K$ U, Z# N/ r
  for(i=0;i<combo_box.list2.length;i++){
% v7 Y  G5 X- `5 S; ~6 f. \   val+=","+combo_box.list2.value;' a# n9 d+ f9 _* J5 w0 Y
  }
, j+ _) j; e$ y% J8 K% f% U  if(val.charat(0)==","){
- u1 E5 L) E- m9 i& G: f* U0 ^) r   val=val.substr(1,val.length);
5 h$ c; _  {0 O3 I  }) U0 q1 b- n( y$ i
  opener.form1.frecname.value=val;
& A0 U9 P# I: E9 H+ |2 O  self.close();
: s3 x6 }9 \2 D}
, k1 x4 z9 U7 I9 s3 o//-->4 }6 U$ N5 u/ s9 S1 q( l
</script>/ d. A1 `: B, O/ o
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
2 P# q  K4 s" [<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />) R4 N6 E/ T2 F7 S2 h
<%
9 y2 F$ ?9 q) w4 j" x; X  l; r: w  cdatasource ds=new cdatasource();  //数据联结bean实例
8 `/ d* {7 R4 e$ A  java.sql.connection conn=ds.getconnection();
7 U# ~9 @+ f7 t, K' q* h+ Q8 l  java.sql.statement stmt=null;
; z5 [6 X/ [4 M/ G. B  java.sql.resultset rs=null;
) C) `$ d" K# y2 m  cdatacheck dc=new cdatacheck();; v/ {  v, x, o/ x1 w" @$ o& z
%>. V) s; g: z* W( F. E
<%& h# M5 a1 i9 l% W; O0 d
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";6 R, j) G" [" S4 A
stmt=conn.createstatement();
1 b: Y; @/ T+ d( i0 Wrs=stmt.executequery(sqlu);8 }( s0 o  t% Z, \( t& j
%>2 B* `; H# r. y) s: Q+ J7 I
<script language='javascript'>" L" j( Z* l3 A1 I
arr = new array();  d) m' ^& M' v! j, q
<%  int temp=0;' I' j+ B4 W, p( S
while(rs.next())
, B0 d' E% H% q{( g3 T" z$ i) n9 `$ l6 t
%>* Y$ f+ b% X- ~; \. R* T. x
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");- |1 F2 q. q! M
<%1 W& C) m6 N& g" w# h8 X) {: H
temp = temp + 1;
. E: P( t, |- s( \1 }( d}. H6 t1 x/ M# Z1 l5 i7 P) |3 ]
%>
  ~, E8 Q: l& P& C$ qtemp=<%=temp%>;
1 T4 |& |1 A# Ifunction changelocation(id){ ; w0 z$ t1 r4 V+ e% m
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
3 n' t+ K2 A6 Dvar i = 0;
6 ]& K/ U$ V# jdocument.combo_box.city.options[0]=new option('-------',''); ' V; e) z8 S7 G( m* C. P$ Z
for(i=0;i<temp;i++){ + O8 X6 M( u6 M& P7 Y
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
6 F# l* ~- l8 _! ^: mdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); ; X. r8 f- I' o% \" X0 R
}
6 f" [7 k# Y( X  q* l) R9 H7 X}
$ ?: a+ g3 l/ n% Z/ c% V}
; e6 q6 i. Q. j) q$ b0 ~7 r</script>/ P7 p7 J: `! c

- O  g: V1 _! W- Z# q, ?<form name="combo_box">
6 c5 y$ }% J7 s: N# m2 S3 g<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
( e) J6 ~- W6 v% p) P4 X8 J  <tr height="24">- Z/ K: ^* M3 j9 S
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>5 c9 F/ n( s) i, M
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
; z7 T- D! X9 j3 d7 W    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
: \7 \0 ?( @( d' g  [2 i    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
$ L. `3 I3 e% ^6 Y( M  </tr>& a/ _$ b" z8 U# K
  <tr>
# c4 G7 {/ c2 Z    <td>* S4 x4 T6 {* o, S0 e/ f* \
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
( I/ C7 l' B, B- a4 l  <option value="0">请选择部门 ---></option>7 X; [4 h+ N+ g4 e+ P. _0 P. \9 }
<%6 G+ p3 F3 A* ?3 M" y8 h. o
    string sqld="select * from tdept";
) Y! X/ a: `- y& r4 u3 q. nstmt=conn.createstatement();: m* V- U) G- V4 {( K  J
rs=stmt.executequery(sqld);& l( H% P0 ]7 A- U% ^) \
while(rs.next())& _. f3 Y/ s9 V# O" i
{
! f3 ?; @: E8 ]. j$ m8 q5 G( d%>
+ O, |  _4 J; F) L% K+ B' O  k  j  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
4 S& {$ k" p( K7 @% a<%: o! X; V& ?+ J; j
}* e/ ?! X  [8 O9 F0 P! a
%> 3 x( T2 @# f* f3 U
  </select>; u% m0 ^/ q! A' h3 T
</td>
0 g% W3 i; ~, Y1 J8 C/ S$ C    <td>* Y2 @1 r' I7 j5 s& S8 V
  <select multiple id=city style="width:150;height:200" class="bgc">
  i0 o5 r- E- D  </select>6 v9 p1 u1 G. d9 h  j  p
</td>
+ H/ o- q+ {% {+ a7 o    <td nowrap align="center" class="bgc">) N6 E& u0 Y4 I
  <input type="button"  value="<<" class="buttons">
0 D/ P3 s+ K$ T5 j$ w2 U7 {4 r# y  <input type="button"  value=">>" class="buttons">) n. P+ A+ S7 [( K  S+ O6 j! J. |
</td>6 l5 j4 B$ k1 _) u" o
    <td>
% |0 L/ }: v' V" w1 H  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
, Q3 h3 o) f7 F1 T0 `  </select>
; q3 Q9 A( Q7 z$ i</td>
+ H6 d% i: h9 t' }0 T' _; c$ H  </tr>
. _3 h( b1 i$ J0 V- G) t    <tr class="bgc"> 0 w8 x) m6 z; C' x4 s
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>7 l+ V4 f  @7 Q
  </tr>
) {+ y9 E0 b2 A</table>
6 I, e2 `7 R" @$ M</form>( W" u4 R7 g- `+ j
<script language="javascript">9 ]# a! ?* a5 g  k, L- ?
//人名移动6 F0 v8 J8 W- H
function move(fbox, tbox) {0 \0 i6 o' {9 g0 z
var arrfbox = new array();
& L! K  b* m! k; r# s% d/ }& ]var arrtbox = new array();/ s! p& @* f% |- S" G- h; r
var arrlookup = new array();; X/ D( B0 F* T. o, U
var i;* w4 n( f; A9 d( j
for (i = 0; i < tbox.options.length; i++) {5 `( c/ s# G! x2 G/ O' X5 z
arrlookup[tbox.options.text] = tbox.options.value;  ?, R9 h6 z$ \: E" }
arrtbox = tbox.options.text;0 L$ F/ F! ]1 R3 ]3 p
}
* J3 i. H2 K) S3 u! R! F: |; e  G) wvar flength = 0;8 G; r; \* F0 w6 W8 i6 K
var tlength = arrtbox.length;7 i6 a. R" B" l/ c0 d0 U
for(i = 0; i < fbox.options.length; i++) {7 E+ T/ y) F$ u+ d1 G- W
arrlookup[fbox.options.text] = fbox.options.value;/ |5 W% q  g& Y( e( J
if (fbox.options.selected && fbox.options.value != "") {5 C+ D" q, _# `  g
arrtbox[tlength] = fbox.options.text;
! S. Q1 @6 q* n& u* F( ?1 Stlength++;
  t3 m0 ^5 W% o8 ?/ o% a6 j) z  l1 N, @}* W# L: b# [2 O9 T# R3 F
else {; R6 C! q+ K3 F0 S2 L! t
arrfbox[flength] = fbox.options.text;$ c0 {; D! X$ Q; M1 ~# M+ W
flength++;
! \5 |% c- n( F% J+ x   }
9 d5 ]% U! H0 F4 X% O}4 P' m4 y5 Y' v1 F# e! l
arrfbox.sort();
* M7 S8 z; F2 G8 _+ w0 S/ Q  harrtbox.sort();7 \  S; ^" u& u0 |

# z# V8 }% e' U; a2 l5 N  Kfbox.length = 0;
* ^& d. [9 X& ytbox.length = 0;4 L' C# K8 B. G1 v" [
var c;3 _( Y* U% R" Y/ X' h- m
for(c = 0; c < arrfbox.length; c++) {$ Z3 G+ X, f2 W; m+ s8 F0 t( C
var no = new option();5 [) ~/ R8 S; V% p
no.value = arrlookup[arrfbox[c]];1 F' W5 b' e" [2 S6 r: ?" v" {
no.text = arrfbox[c];
& c0 G9 E" F4 e$ b" k1 @fbox[c] = no;: ~; D- t- V1 e# |
}8 R3 |: Z. l, j- X1 r1 G) I+ ?
for(c = 0; c < arrtbox.length; c++) {
$ c& l- p( O6 B/ k  bvar no = new option();
% P0 u3 p' n+ y; n0 V. ~- jno.value = arrlookup[arrtbox[c]];( T  ?4 D8 j  D. f! ~" N  z
no.text = arrtbox[c];- W# n6 N- w% H
tbox[c] = no;5 v9 e2 d: W: m. E) O# i$ R
   }
( \  s* u" j0 }& t, V- e5 j}
0 S, ~, m" t4 c2 M</script>- A1 T' t, R& d
</body>
; @0 ~  Y  t; ~4 m7 Z5 V0 W7 }: L4 A

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