返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
  P3 x$ r( F* |# k% U         c pageencoding="gb2312"
- V! S4 ~/ z2 I# g2 C5 a" b, e%>  O8 U% e+ s1 Y9 j
<style>3 k3 t$ Y: n9 y% G- _/ j5 R" R
.f9{ font-size:9pt; }8 `9 }, R; y* H
.bgc{ background-color:#aecaf9; color: #0033ff }
3 S: H# X  u- I8 s, J.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
2 f, Z% r  N' @8 B% n- O  border-bottom: solid 1px #4e7dc1;
+ n* ?9 y' j. A, S" _* R5 m0 |  border-left: solid 1px #aecaf9;3 o' _* i2 O8 `/ o* ]
  border-right: solid 1px #5679bd;
2 H+ `6 i( |! K  L% t' X  padding:1px;3 j  H5 o9 q$ H& f+ r
  margin:0px;}
+ b) T7 Q( q& y% q</style>$ b7 z* _' ]5 ]
<script language="javascript">) J* p* G. }1 m
<!--* H7 C/ u3 }6 {" Y1 f7 \; d5 l, B7 R
function rv(), [/ P  [' I% k: o7 [
{
, w& I3 ~$ ?- k; l  var val="";
- |* ^4 O9 x- L& s9 T" k1 t7 E$ Q  for(i=0;i<combo_box.list2.length;i++){
' W4 ~6 c* V( T   val+=","+combo_box.list2.value;$ Y; A* f2 _  d: Z5 q
  }
+ N7 ~, }. Y* S) m, o0 V* j  if(val.charat(0)==","){
4 P; k2 e2 F1 B. o9 y- h% P0 [- H: E   val=val.substr(1,val.length);! ^7 j* t; `' q( ?  W
  }
8 m+ k7 Y$ R. h3 \0 Z# F  opener.form1.frecname.value=val;# e# F$ w& i9 \
  self.close();. s) s2 _1 v$ e- B  I; H5 R
}
, t" t. }$ ^, h: v& c//-->
" x( L9 S; S2 W5 e</script>8 D& a' v8 ]. P0 e8 q% E
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">$ H8 ?" Z' S) R0 E% A$ ?! D! W
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />% Q5 t3 V9 s' N' s
<%
7 B9 f) I; A' o( J0 V  cdatasource ds=new cdatasource();  //数据联结bean实例
% ?+ Y3 A, j* j9 m  java.sql.connection conn=ds.getconnection();2 r. i. }0 ~* f) B* \8 J
  java.sql.statement stmt=null;' e3 t; E4 [% W; t0 `
  java.sql.resultset rs=null;' K' |. R, e' m, X
  cdatacheck dc=new cdatacheck();
* q: i3 q) O  _2 n# Q%>" X8 ^, x6 I& W
<%5 a+ g2 t' N- X( B2 L! \
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";
. ]; S; Y3 Y6 p  S# s. t. e! `stmt=conn.createstatement();/ H& o: x2 P/ {5 r/ I
rs=stmt.executequery(sqlu);, q% g( T8 {2 a
%>
# A) J; ^  G: \- Z3 i' [3 }' y<script language='javascript'>1 B, L7 y" e" }
arr = new array();: c9 y6 s# m; o9 y
<%  int temp=0;
) G0 d/ q- t  Swhile(rs.next())
/ D3 q0 }2 V, r{# W& @$ t/ S$ e4 K# G
%>9 U& _9 `: ?( O/ M% n
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
. u$ I" G$ W( C. V5 j+ z<%+ O+ f( c: p" c" t
temp = temp + 1;3 \7 a' l* H. u9 R: u0 u8 V
}* P4 m$ i, D. R& b* F
%>' `! z1 G/ X- [- G: u0 q& M& {
temp=<%=temp%>;1 {' H& O  D' h  W- p7 [% X
function changelocation(id){
8 e2 r& `5 j6 v) }document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
8 \( s. ?5 ], a, K8 svar i = 0; ! R9 p9 X% C' G
document.combo_box.city.options[0]=new option('-------','');
$ G0 v* L2 t* p" Xfor(i=0;i<temp;i++){ 4 x- q2 n; E: b5 z6 \7 u! d
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]   ?+ U0 o1 `9 l; s6 _) l- ?+ A
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); ' U3 Q# ~; a3 ], k3 K2 q
} 9 M0 d0 w, g  `; Q
}
7 X9 x  `2 Z! e0 ^( [} , H) r* x5 k$ f# u9 s
</script>
1 c' v: ~! U. S, m: a7 a, L; x
' _, v3 ^$ ]. g<form name="combo_box">
7 |- q7 Y9 n8 E: X2 w0 d<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">4 q* q3 O3 _5 D! E" p. a! e! u6 l" |5 u, y
  <tr height="24">
: F1 [: Y2 K: M" k$ K9 K' Z3 G    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>' G7 t5 @# ]  g+ V4 Q7 M
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>3 p+ C5 M) H: Z8 R
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>; ?" N  E+ a! {2 @; y4 [' c  d
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
6 b9 r7 P' @& v) o  </tr>
, O7 e$ U) ~" k9 b, [* u$ a/ ]1 U/ N  <tr> & s( U' G3 W( d" c* ?# \
    <td>
" \: R3 J1 u4 F0 [9 `, r$ c4 h% }  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
! J9 p  M2 k6 Z' G  <option value="0">请选择部门 ---></option>
* m. b; l# h0 S  t. l2 M7 f<%7 g, {! S' ~; g
    string sqld="select * from tdept";
0 L* e" O! P# \1 \8 h/ u4 e& z+ z9 Cstmt=conn.createstatement();* u% e" v  x8 [& w
rs=stmt.executequery(sqld);
' ~* s$ I: U! C& X+ Bwhile(rs.next())
4 `. \8 M, F/ G* V6 C/ [( M{
4 U4 e( H9 E/ [) y8 R9 b%>3 B7 H# S1 u' T
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>4 q! L2 b! ^1 y, }' O
<%
$ C& k# J0 l6 `4 Q. J}
! S) F3 g# L# Z7 c1 a8 {& t%> % Z8 f# u! D8 x) I9 b9 d4 G- n$ z4 f
  </select>
' T; u8 m# c! i8 @( `- ^</td>; G+ m3 T& l# P# S
    <td># ?- }- u+ z* L; x: {- M: H
  <select multiple id=city style="width:150;height:200" class="bgc">" h1 m" q0 f6 v$ f; A$ M
  </select>
0 D9 L6 i" g+ z0 U</td>2 b! F. a1 E' i- |' q, G( E
    <td nowrap align="center" class="bgc">7 j% j# ~7 `/ b7 {0 e6 b. n
  <input type="button"  value="<<" class="buttons">6 J. q9 G5 A4 j, ~; B0 E
  <input type="button"  value=">>" class="buttons">
. v. O3 S! Y7 i5 i; W# {, N</td>& b2 F. F; p0 ?' }& j9 m/ y
    <td>
( F: Z6 a7 f8 t9 T* K0 }  v  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">; |& p# k3 P, N; N
  </select>
  V6 s- r4 i5 p3 ^$ X. W</td>
1 C+ F; u" L" Q( I* O* c  </tr>
/ e* x) L( ^' O    <tr class="bgc">
4 k4 _0 E4 N! @2 W    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>- i& L4 c" i0 Z3 `! `) y, a
  </tr>
3 ]- y% E. W$ ~( \+ y  a</table>
5 ?' |. z: `" `  l1 d</form>" J% N. V1 \+ h0 ~$ S+ L1 `$ \
<script language="javascript">0 P# Y8 ]; i% V
//人名移动
( V& j' e, p6 O2 nfunction move(fbox, tbox) {
/ T5 z$ `: W8 E+ ovar arrfbox = new array();( V, _4 r( O* h( e4 F/ g
var arrtbox = new array();7 t3 z( ^( g; E$ L  }
var arrlookup = new array();
6 p% a4 c8 C% H' A" @var i;) {7 K8 Q; q. ^" a+ b9 Y
for (i = 0; i < tbox.options.length; i++) {
1 f# e1 s3 P% P; B2 n+ Narrlookup[tbox.options.text] = tbox.options.value;
# W$ n1 R. E2 ~7 S# m3 Q, I& Yarrtbox = tbox.options.text;
0 O# M! B6 X  t' T* X}! L# C2 K; F% C. G
var flength = 0;* }' y+ a/ s6 ]7 l3 e/ m. G
var tlength = arrtbox.length;2 `  }5 Q/ T) |$ a+ k
for(i = 0; i < fbox.options.length; i++) {
+ O+ {! y0 T6 d- R  ]8 |arrlookup[fbox.options.text] = fbox.options.value;2 p: d8 U+ W. X: N6 v  R
if (fbox.options.selected && fbox.options.value != "") {
6 ?7 F, J! J! W$ s  parrtbox[tlength] = fbox.options.text;4 c+ N4 N9 y0 F7 l
tlength++;
9 K9 e& M2 p& R% N1 A}
+ Z2 x% g3 k) u+ C' Telse {
% c# w3 x" ?$ \: M6 Marrfbox[flength] = fbox.options.text;
  D* O* b$ P. F" aflength++;* }& h' @6 ^+ X. P7 F( r
   }
- Y- ^) e' a3 G6 s1 l! t' O! b+ y' e}) B* |/ m: e3 E" G$ a& W
arrfbox.sort();
# A2 z3 B$ E, }. carrtbox.sort();
2 `4 O* _' K( I. z$ G
8 y* [4 P( U' l, ofbox.length = 0;
* l  m8 L9 e4 ?tbox.length = 0;- c+ I7 `4 f8 O. ]: o; _
var c;5 B+ }7 B4 d# Y: e. T: P0 z
for(c = 0; c < arrfbox.length; c++) {1 h/ y/ d' J: r! z6 F
var no = new option();
( Y' j) e2 C, ~3 C# E' N* ^no.value = arrlookup[arrfbox[c]];1 |2 ]4 A, o& j8 k: x
no.text = arrfbox[c];  g; Q! k- J9 @9 E) ~; r
fbox[c] = no;6 Q5 A( o) _6 T3 E2 B! T/ @% k8 Z* q1 s
}/ _" q0 u( M! n. z: p. b) m' v1 q) W
for(c = 0; c < arrtbox.length; c++) {
$ x8 y# T9 Z8 O9 V8 C2 j# L6 G$ Yvar no = new option();. I3 k, |: ?# ^' G, E
no.value = arrlookup[arrtbox[c]];; J' v! e* T1 o( W8 }
no.text = arrtbox[c];# l7 W9 l) b0 t. c6 b  n
tbox[c] = no;
& {7 f! k8 r& c# w: R   }3 H7 V+ j6 W- ~$ ~! _
}
$ q8 q1 M* {2 p- l</script>
7 U* y7 L1 s* k</body>, y( i* {% n# q. H0 G( G- X

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