返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
& p: u) c" e& B( o         c pageencoding="gb2312"
0 e8 {9 r( C. F( P0 |%>( q4 X. s5 V$ a) g* m) S
<style>+ |  d% A- `) A" D
.f9{ font-size:9pt; }
- e7 b. r5 P: C( K! \' V.bgc{ background-color:#aecaf9; color: #0033ff }
/ d0 A3 C9 C. `! o.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
$ V/ v* g7 Q; r; r1 w5 C- a  border-bottom: solid 1px #4e7dc1;9 g# G4 Y( W6 I& I2 j; |& }: Y! r
  border-left: solid 1px #aecaf9;
: u% ~0 T6 }& Y1 S! }+ J. B- k* }  border-right: solid 1px #5679bd;
1 r2 x* D  w1 R2 S7 H+ G3 ^8 y  padding:1px;8 ^9 `8 o0 F2 c! R1 P# v9 X: T
  margin:0px;}
4 K& n9 g$ n- e( I</style>7 Q/ A  ~7 H' z) v9 ?! }" \7 _
<script language="javascript">' U0 ]# H2 L1 a1 r+ v8 H) D
<!--0 R  V( i; L! M" z9 R
function rv()9 T' [! g  s, ~6 `
{
* `" ?% X5 u- p' }$ Y  var val="";5 b5 b. B. c. ]% t8 V/ z2 K
  for(i=0;i<combo_box.list2.length;i++){
* H) o8 \) |4 \   val+=","+combo_box.list2.value;1 V, [) d2 o9 z: F1 A) w7 R
  }4 c! y: b. S) a+ ]2 I
  if(val.charat(0)==","){
- I8 }9 k7 p0 r1 C" s: V   val=val.substr(1,val.length);9 v8 L5 R- Y. O5 T' d) t
  }
; d4 l1 R1 L2 M" g8 @5 B, ~  opener.form1.frecname.value=val;
% v! @3 Y$ o6 O- V, I: n1 T  self.close();! E+ t1 X9 v$ s* @1 y) _
}  ~* ?' }0 \9 L2 T. N& B
//-->0 L! w2 h5 |; B$ `8 w4 m
</script>
, I% N' e: [, i/ ^5 @) j/ l<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">6 f) R% u  G' k! w, |; I8 E" g
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />. T0 n& B% @! z+ C
<%
# X! l/ H! \9 X! ~3 q  cdatasource ds=new cdatasource();  //数据联结bean实例7 L! q# Q; M& V- e) {: [& _
  java.sql.connection conn=ds.getconnection();
: e3 Q5 |8 i' `; J6 x  java.sql.statement stmt=null;
/ P( O  L+ Z7 g& C  W) d: ^  java.sql.resultset rs=null;
$ f  c: K# j4 K2 P  cdatacheck dc=new cdatacheck();+ u2 v8 n# b$ |) m& c+ l9 q
%>9 I1 D0 W3 C9 F
<%1 W0 \6 l: ~: P! i) o. ?" e# H7 |3 i
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";
$ i6 X0 n; [- U$ L4 _8 [; [stmt=conn.createstatement();
- G+ s0 f! l9 p& @* f) n; _) @* Srs=stmt.executequery(sqlu);
. h% s' h' z! N- g' }%>
" K- U. V" O1 V4 ^4 P1 U' i  I<script language='javascript'>$ s- X$ a; G* S! ]  ]( d' U* S
arr = new array();# ]! g# b+ L0 _7 f& {  m
<%  int temp=0;
. h- r% B/ V& y' z3 Pwhile(rs.next())
6 J5 c' `! G+ R# J7 c" }{9 Z; u7 D& J( G- C9 m; s
%>
6 G+ `- Q4 k; O' A5 {' \0 ]arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
$ \( d2 a$ a9 m' Z& e<%
8 C4 [- H2 M3 F; A) utemp = temp + 1;
" \6 e" Z) _+ R) G# `}
' _; v/ w8 [0 T' U" h%>6 @% F! C6 `" J6 w2 E% l5 n
temp=<%=temp%>;
8 X, D" O0 y# m7 V: yfunction changelocation(id){ 6 u/ H6 w8 b/ j" b
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
3 Q2 ~/ a5 W* p3 yvar i = 0; * T' a2 V& ?3 L! e' ~9 m
document.combo_box.city.options[0]=new option('-------',''); ; p) w9 V1 ~* H# n2 Y- I
for(i=0;i<temp;i++){
1 Z% m8 ?5 O) C, U, x& J, yif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
1 O( W" i& D% |, t9 K% ddocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
6 C. K" O7 ?& ?2 D( ?3 K* X}
' n& p. `3 d2 Z  j. r: R} 4 ~- p0 v6 d: m, r1 e# X
}
* a( I: _. w8 m; Q" Y</script>
$ w1 ~6 S/ H, ]  D# `& ?4 w( C& T) s) C; V
<form name="combo_box">
$ R+ v! K+ b, b) O6 c% K% V( l4 A<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
/ f, T" \2 Y% \  @% _& j  <tr height="24">
4 X/ P7 V2 J8 G    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
. ^- ~  [3 _7 E    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
- D$ p# o6 P: G+ L4 N8 a4 y    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>  A- ]* T1 o2 t* A" Y% U) q5 Z5 J
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>6 r) M( |- g: O  a; Z2 W3 e# v
  </tr>
6 s( }5 Z/ E( }* c4 v+ ^% B  <tr> # ^6 q) `8 U! n
    <td>' t" F0 I- U& P) ]& r# i, H
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc"># A: B7 l3 b% a
  <option value="0">请选择部门 ---></option>
' Y2 n  h( t) Z5 E6 ]<%
! h5 q, K* M: q    string sqld="select * from tdept";
& b* i9 S& A$ @6 A9 u7 Ustmt=conn.createstatement();- U1 `3 V8 S5 l1 X( ?
rs=stmt.executequery(sqld);
3 U3 d$ S* m7 e! U. U: Twhile(rs.next())" a; _, `4 P+ w% ^! y1 p' W' F! _
{; q7 C5 n2 r  k7 y8 e
%>7 h7 }6 Y5 R! k6 Y# x- w
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
3 h  e) }! V" R3 N<%
, u: T  M+ J5 U* u8 p}$ }' c/ l6 _2 B7 [( ~4 J: h
%> , U& D! A# [2 H. W
  </select>  x3 z4 Y8 U" F* X! }
</td>9 ]. w/ j( x( D
    <td>
& D1 t  v. r$ D$ C2 {  <select multiple id=city style="width:150;height:200" class="bgc">( H, }1 J( t: e- P1 O1 {
  </select>% W, t% L* S$ r/ v: b/ O& b% ~3 H
</td># o! P; _  p: s, P
    <td nowrap align="center" class="bgc">. H; o6 q% k# i9 k* |* w9 v' @( o
  <input type="button"  value="<<" class="buttons">
: k8 h1 N6 T% A+ @! m! ?4 m. @% [  <input type="button"  value=">>" class="buttons">3 ^9 R! Q. ^5 N; x; m" o
</td>7 [2 n1 X# S1 N& q
    <td>
* j! u7 `& O" n( N) E% L  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">! S- Z# x4 ?1 q0 A" `
  </select>: j, t; c( c  k
</td>
+ S3 v2 m. B+ \" O2 j# \, d( M  </tr>: I0 A1 d0 D; J% t; b3 g- R
    <tr class="bgc">
8 J6 e' t2 U& t  O$ G, h    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
5 t0 G6 K4 d) p% y" O5 z; i8 w  </tr>
# }% R% Q0 R9 q- S9 n$ l</table>+ j# v2 p  ?) \$ t4 N
</form>7 I7 O/ ~2 n0 Y: h1 p
<script language="javascript">
. d5 [/ I3 ?) m//人名移动
( F( e1 J) l) n$ p( B  @7 o- Z9 Ifunction move(fbox, tbox) {
7 w$ Y9 q$ T0 y- o# j0 V  a8 Yvar arrfbox = new array();" W, {! B/ m; L0 ^5 z
var arrtbox = new array();
% `( B2 b3 E9 [7 Qvar arrlookup = new array();. H& o' r7 P& m
var i;
1 }2 K* }) F% {4 s0 u" ]for (i = 0; i < tbox.options.length; i++) {
1 P& R/ O2 f; o6 t0 c1 Varrlookup[tbox.options.text] = tbox.options.value;
& k+ x) y9 s% ^( X# rarrtbox = tbox.options.text;
" v8 P& B# m8 D$ W) P9 i4 n/ i}
, Q( K# Z3 Y5 y! i6 C/ Yvar flength = 0;
2 I( l$ d( N7 v5 h# qvar tlength = arrtbox.length;
7 ?) Q% P# ~. m& J* b  S% C' Nfor(i = 0; i < fbox.options.length; i++) {
# y0 b1 |. B7 S2 D5 L6 Aarrlookup[fbox.options.text] = fbox.options.value;& a+ g. h3 G, V- _
if (fbox.options.selected && fbox.options.value != "") {
; x# x3 g6 X+ q% farrtbox[tlength] = fbox.options.text;
1 r: |$ }$ R, ~1 L. v' Wtlength++;
' Q1 C. Y! `* I( n* s# M7 z}
; f0 P5 e; |& h3 F# J* Oelse {
3 i: S: ^' f& p- [/ x& o+ {arrfbox[flength] = fbox.options.text;4 l7 G" i( I9 I! Y
flength++;
& @+ B  g# ^$ I- U. u# v   }1 s( u& W8 \7 z$ j
}
& J8 b- p- ~4 K. `+ x- h, K1 Parrfbox.sort();
, P8 N; s5 Y9 marrtbox.sort();
- B4 {# H& a8 A8 q, @9 [- \4 J& n3 N* f& D7 I
fbox.length = 0;! x/ K- K0 X; p' o. z
tbox.length = 0;
# @5 _/ {1 v* T% N' Q/ [  k& Cvar c;
3 w) |8 c1 X1 d. E' P. Ofor(c = 0; c < arrfbox.length; c++) {
& L+ _  H6 J6 Q/ j# N# Avar no = new option();; g' b. s5 v3 Y3 _& a. y
no.value = arrlookup[arrfbox[c]];
- H' y& @1 b  }* r6 W& l' jno.text = arrfbox[c];
4 L8 R3 e& z8 \4 z2 ?4 E- j& s/ Hfbox[c] = no;
' D  l3 z0 }' c- s}
5 r# g" b3 _; Sfor(c = 0; c < arrtbox.length; c++) {
5 M. `$ C. s6 J& Y! Uvar no = new option();" }3 a" ?7 v  z' R4 q# b4 \
no.value = arrlookup[arrtbox[c]];
2 O3 ]/ n( [- e" O$ k0 Y( a) Gno.text = arrtbox[c];! a( ^) |6 e, w- N3 K
tbox[c] = no;7 p0 V. G+ A* o5 @6 V
   }5 H8 M7 Z, C- E  t4 c1 H) O
}
( D. l0 y. i. l</script>0 i- M9 K8 V, E0 T: ^9 C
</body>7 @( C. W5 a6 {: b3 s" d& N

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