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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;". Z) g- ~9 n8 G
         c pageencoding="gb2312"8 ]* d$ V1 {1 p2 j
%>. i- f9 ^2 k2 Q1 J( M
<style>
3 x( b  e: M6 A8 [  q.f9{ font-size:9pt; }' `$ j+ c1 N2 P" Z
.bgc{ background-color:#aecaf9; color: #0033ff }
% x+ F: \* [- P" C+ y2 V.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
% v3 e  U# Z' ~  F3 D! ?6 ?  q  border-bottom: solid 1px #4e7dc1;
( d9 M  Y2 g; J0 m2 y  border-left: solid 1px #aecaf9;, x0 F, m6 r% d
  border-right: solid 1px #5679bd;
7 |+ `, I6 h) _$ ^  padding:1px;8 ?6 `, \" s! V
  margin:0px;}
, d/ F) ^$ [7 y3 A</style>( T9 T  i6 }7 f, p  x8 j/ W9 i) ~
<script language="javascript">
* S, X  x7 }. a; A2 z<!--
5 O4 a- o) }% N/ Q7 cfunction rv()
8 {# r$ G6 Y, V; L' x- o{4 v, k% x7 p* o" n6 X" H* |- C) k5 V
  var val="";
& ^, J) b! [- l+ J' i$ R' ?4 v  for(i=0;i<combo_box.list2.length;i++){! P% q, ?" s/ j6 M
   val+=","+combo_box.list2.value;  G9 Q" D" I  v
  }
( B6 R; ?' Z! O9 \. \# h  if(val.charat(0)==","){
7 ~  u  V& ?- B   val=val.substr(1,val.length);* y7 s5 b9 {8 A/ n/ O0 i8 l
  }! a4 H4 F, {9 D" [% R8 o7 Y
  opener.form1.frecname.value=val;
3 E& Z# E+ G+ x5 `( e  self.close();
: K4 P! w0 f! W/ [$ U8 k% }}9 e2 _, e' v. @3 r( D# j
//-->
  c. S* ^! V$ z( z4 [</script>
% Q( r* p3 W  x- \0 r1 f  k% k<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">9 i  O# a; \+ C. H1 K* t
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
) S$ T8 m+ l5 ^8 H/ `<%
- c  |' V( N0 X$ p" W  cdatasource ds=new cdatasource();  //数据联结bean实例% S" P0 h: n1 n- e
  java.sql.connection conn=ds.getconnection();& _5 L2 s/ S% c2 k, D  w5 N
  java.sql.statement stmt=null;3 M. g/ ?: j3 ?' _5 E, b
  java.sql.resultset rs=null;
2 J+ N; q$ c! X$ W8 j  cdatacheck dc=new cdatacheck();
7 j# ~; m6 D& `, ^  ?0 h- E6 n: y%>1 E" m5 H5 M1 k. }, B  x/ X/ k
<%
. s# L. L! M6 ustring 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";
; k# B3 Y) \  w. q1 Lstmt=conn.createstatement();
, K0 M# @8 b! w) J) h; K$ ^rs=stmt.executequery(sqlu);( f  g2 x  o, @# @, b/ f, p- f
%>* Q  i3 ?3 C  J: b
<script language='javascript'>
8 q4 A1 Q1 I, L  Y3 Darr = new array();
( K% C2 q" q9 @3 L# M+ |<%  int temp=0;- ?1 |1 z( c! t
while(rs.next())  d! s* B) s- u2 N
{* W$ u: T- L! s
%>* q. U8 f5 }1 G; o( a6 N9 P
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
9 m  R, H- O$ o: c+ J" \<%
; Q  o6 j& F2 H% x% atemp = temp + 1;
; K% j9 [- o, c2 D& C- i! |) r% ?}
! m7 D! f2 V( U& `  Q: s6 d& n$ X%>7 j. w+ `. _6 Q9 F2 m0 j
temp=<%=temp%>;
2 x1 [, D$ o% D- F% jfunction changelocation(id){ 9 Y4 D+ v( |1 ]' i; {" i
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 5 K0 c+ I+ N! _0 ~6 G0 J, u9 ^0 T
var i = 0; 1 u+ T! T7 V3 Z+ J; k% c7 Y7 D
document.combo_box.city.options[0]=new option('-------','');
5 s& d+ ~9 ^7 J5 |for(i=0;i<temp;i++){
+ y) l* Y* ^) d5 Wif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] % [. T  j$ I  ]: ?
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 5 Z: G, R6 H, j: K& H: P; p
} " x5 t! y; P9 x
}
' n6 `+ a/ F1 I5 ?' J}
! i; L& `, E  e</script>3 d* q8 ~& e5 @1 S. X; ~9 O; j
3 \" _& G2 N3 T2 u1 c' f
<form name="combo_box">* P9 u" J& @5 h8 E- L8 `
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
' M7 }6 ?; k  C$ E  <tr height="24">0 n! j) p. R4 c5 q( G# X
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>. w- L, o/ b1 k  b  S3 S2 X) a
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
) }" f' N6 w4 V# O    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>6 G$ k2 l7 u' c  h: W' v: e/ r
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
/ D' r+ E! H4 C0 {  </tr>
) W1 t0 X2 D, z! O: y* }  ]! j  <tr> 7 ?0 _) d1 P! V% E: L9 T# w
    <td>
; T1 P% k4 @6 W% ?  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
5 S* [$ k' I  C( }; ^, E9 p  <option value="0">请选择部门 ---></option>$ {& u7 k9 Y6 [( U  X" D
<%$ t* w9 \$ d$ j" l! ]8 B
    string sqld="select * from tdept";/ k- d* n$ _$ ~- ^$ S5 h
stmt=conn.createstatement();
" s) c1 Y5 U6 zrs=stmt.executequery(sqld);; [# T0 r, T+ M' y% C: ~% ?  T. [
while(rs.next())$ u# [- E$ B! P1 u
{) I  t0 [: S* |% @1 N
%>( W5 I( S! v. R3 x& {, C
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>, o6 b! `& R, ~) g8 g
<%
. `* f" |9 D1 `0 W3 t( T}+ S* ?/ s/ w6 s7 I" n1 k
%> 4 `2 b9 H. N' f; b6 b' v' L
  </select>
- V) R1 X* F+ O4 F0 x, K</td>
, }7 z4 y$ |9 F4 ]% T    <td>
5 {' F; Q9 P7 ?2 u  <select multiple id=city style="width:150;height:200" class="bgc">9 ~" A3 D3 k$ u& |+ f; s5 b/ s: k
  </select>, x  K' H* ?, T3 ]" g
</td>0 P8 D  N4 P: L8 M( J
    <td nowrap align="center" class="bgc">: ?; w4 O& G6 d/ }  }% m4 I; `! U6 A: J
  <input type="button"  value="<<" class="buttons">
2 D& C1 H: i' _1 P* `- v& v  `$ v  <input type="button"  value=">>" class="buttons">  P4 X. t+ [2 Y+ J: [1 O
</td>3 F5 g* S- K& \$ k
    <td>( p; J' \) v. [
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">) t& f$ a; ^' |5 M4 h  B# c
  </select>
2 k+ D2 v6 r7 _( ?% S</td>
/ E% E8 }6 T, d& N) s- V. s, M  </tr>/ v4 A. E2 S% o: D% x0 q
    <tr class="bgc">
; O# E- M2 h6 v# x) h    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>: t! J, g3 n. M% r; R3 e
  </tr>
! c- c3 v* i# Z. e8 N</table>& x: c2 w- a, z3 s: J9 Y
</form>
+ n$ x& N5 X, R0 s8 a<script language="javascript">; z" c# K2 j' f( V" s' O# E
//人名移动
2 g. |7 b$ t0 }5 Ufunction move(fbox, tbox) {: N1 W4 ], E1 k2 K  q
var arrfbox = new array();) R! ]+ t, u, i7 U
var arrtbox = new array();9 R$ O; u) W# e; p6 @! x
var arrlookup = new array();: r6 s- z8 [% m( j- k  g
var i;
2 K/ I& A4 y+ F* \7 {for (i = 0; i < tbox.options.length; i++) {
6 {8 }6 o6 Y0 O2 U/ x4 c0 ]& \4 X% narrlookup[tbox.options.text] = tbox.options.value;. Y) r+ ~* E% W+ C
arrtbox = tbox.options.text;
8 m- K3 U: X+ i% t4 l}  `$ i7 a, x" w; X
var flength = 0;
! q) s1 \6 `0 l- c2 ?( xvar tlength = arrtbox.length;
/ t, @1 T5 [+ u$ qfor(i = 0; i < fbox.options.length; i++) {
' i& y. R; A& S0 k. S& [$ k2 R# Zarrlookup[fbox.options.text] = fbox.options.value;* M9 R# L( ~1 A6 a" ~, {: o
if (fbox.options.selected && fbox.options.value != "") {
4 m" y  v. q3 A" D" k$ }arrtbox[tlength] = fbox.options.text;
$ `& F# z/ J4 [tlength++;
! b7 q0 G+ F0 U4 e! m}
, D* x" ~1 t! J( ^6 T1 ?else {4 z( G( W/ [; Y! A* f: a
arrfbox[flength] = fbox.options.text;2 g, x/ q  I  a1 c
flength++;" o# x0 @* z! ^: H9 Y# t# f
   }3 B4 M1 q$ M3 S
}
7 z4 z5 A( q3 b. m0 Qarrfbox.sort();
( a  y" x/ U' G& {5 jarrtbox.sort();3 V- w) E( g; ^
' o' i$ Q. [. [2 i6 e
fbox.length = 0;) ^0 n, P3 w/ I# N& w0 ^/ P
tbox.length = 0;: K" ^, ^/ p+ m6 M" U" P9 y
var c;$ n, H/ c5 n1 V7 r* \
for(c = 0; c < arrfbox.length; c++) {0 `/ X' \" d) O5 x, u( d) M* }
var no = new option();- ]+ t; K. b5 z0 F
no.value = arrlookup[arrfbox[c]];: b6 h% D8 L/ x
no.text = arrfbox[c];3 Z+ a8 a  U" e  D
fbox[c] = no;
  m# n  R; m* ^- k- z}' }. w6 _8 b' x/ [  E( H
for(c = 0; c < arrtbox.length; c++) {
+ ~& w; M/ ?- Xvar no = new option();
( H2 X9 F8 F) _3 Hno.value = arrlookup[arrtbox[c]];5 _$ k. V2 O( V4 U; d6 J7 o
no.text = arrtbox[c];4 g3 N4 T/ k7 N& o; S
tbox[c] = no;- W' z4 x3 I( n3 U1 x+ H$ g
   }! Z' }8 `( Y, a$ W
}2 f4 l6 }# M! P, D$ ~
</script>4 M3 n/ A( e" k0 U# j& Y
</body>0 }' p  K9 B  b) }4 b

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