返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
6 w! u- V. L! R, [" p5 q' F* Y         c pageencoding="gb2312"
* l3 \* k! z; y% q9 l* D%>
* ^) O$ I6 l/ d<style>
. S' V) C9 x" \  u# I9 l  W) C; K/ l% v.f9{ font-size:9pt; }" m5 A: o& w( W: e
.bgc{ background-color:#aecaf9; color: #0033ff }
0 B, W* q/ l2 q0 R  U5 u9 E( e.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;% b  r) O3 C" Q% }- ]/ G  D
  border-bottom: solid 1px #4e7dc1;
6 t& g& H4 k9 w% ~  border-left: solid 1px #aecaf9;' J; V4 F5 B, \. m9 ?( y- |. Y! B
  border-right: solid 1px #5679bd;
% B- M* O. {4 o  padding:1px;) z5 o" u( T1 w6 O  A& Y- ]
  margin:0px;}: @' G5 i6 C- M# a# C5 n* _( S8 o* o
</style>; K' t3 `5 K" h1 N$ x2 u0 e; z
<script language="javascript">" `2 Q* }, N" Y+ }# n! x
<!--
4 W' b* X' M7 H6 q2 k# b2 g3 wfunction rv()1 B; d  K4 j- T  o8 [
{
& F& B' e' u/ R- H1 l  var val="";
8 p8 w$ T$ B  L- e  for(i=0;i<combo_box.list2.length;i++){
! {; H6 F5 V1 O; u   val+=","+combo_box.list2.value;# X% G; R- @4 l+ y' F6 i* ?
  }9 ]) G( [' S% v, b
  if(val.charat(0)==","){
2 z7 C/ W4 h6 w/ j& K   val=val.substr(1,val.length);4 T$ j1 `9 p: F8 m# J
  }
  |* G5 H  k, a% {6 s4 B  opener.form1.frecname.value=val;
* Y7 p+ M  @& `: u, h9 g  Y, q+ q3 _8 ?  self.close();6 B! u4 I  X2 T( p) z6 Z) s2 h& n, a3 D
}2 G5 v. Z8 F! [  c3 n# |
//-->4 T1 D0 w: Z! Z1 \# e" |+ \4 d6 ]
</script>
/ Z* K8 m( M7 i! |: A<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">' J/ d1 a! O2 e8 {# A' V- r9 t) x
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
6 I) ]  e/ ^. ?6 }<%
& @: s1 N' x) S; z; K  cdatasource ds=new cdatasource();  //数据联结bean实例
  W  X, M; |3 d: g! y+ M( \/ {  java.sql.connection conn=ds.getconnection();
) [1 B9 _2 N7 m& m3 J4 o" k" m8 o  java.sql.statement stmt=null;
% Z( @! f5 s8 R0 n; N6 k  java.sql.resultset rs=null;
- L# _7 G1 W5 _: v: N7 U# o  cdatacheck dc=new cdatacheck();- c4 B( V, m- v+ z( q& j  T* J. V
%>9 ^, {0 `7 z! R. r, L3 p
<%
7 Y0 N, U$ h1 s6 G, E  _/ t7 nstring 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";
8 i- ^3 S" x" x# i& ystmt=conn.createstatement();
! k: H' Z) x( E7 M6 v/ irs=stmt.executequery(sqlu);
, w0 I3 d6 Q  w" H: Q5 a. n' |, B%>( D) J3 F$ @5 Y! W  F9 I
<script language='javascript'>
8 |1 c1 _/ j+ k7 G( Farr = new array();
7 |5 H0 J* q4 U# }6 X7 u<%  int temp=0;
, e4 I( M* }6 s4 X  b: g- l) Iwhile(rs.next()); z" j$ {% n1 q' b4 Q( ?. X9 i
{
/ G: s* R' |( c) E; p) A9 T& o* F%># F$ s6 y" d, s) a5 W- C
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");, G# {9 z* V7 |8 u, w
<%
$ G: ~8 d- F% V# stemp = temp + 1;
/ v4 e; g0 R6 W! M3 ^- N}; U" n6 W7 q+ M) E6 `0 Z5 |+ e
%>% M6 {. t' o" R1 A
temp=<%=temp%>;# ~- C' m6 n! W) Y. z, q0 ?" H
function changelocation(id){ 2 s6 V. K' x3 `; V* N. {3 ^
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
; T/ v( c/ B  G6 Q. G( ^var i = 0; + H* R" }4 u. J: f; [
document.combo_box.city.options[0]=new option('-------',''); ; j  r: D; i6 S
for(i=0;i<temp;i++){
9 c( z9 l4 n2 H4 P9 b  D8 m" tif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] : w2 }8 Z- L: z, N* n
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
2 ^, K0 p. K$ y: k5 Z2 b$ ~: C" Q}
) z& t1 w5 i$ b9 |$ z} 4 R: R; p3 V& O, t' @) G: `' Q
} 5 \2 g* T3 C  N. @
</script>; n. `( A3 q! S3 |  \- E
, L' E& k7 D$ ?! ~, ~
<form name="combo_box">
8 P/ m- k+ A* Q3 J3 U8 V! g<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
! c1 h, S8 K$ d5 ]4 f$ `  <tr height="24">$ k1 O+ l* g2 L7 N( K
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
# p5 U( Z4 X7 O' Q* P  `4 T& B3 X    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
5 T4 L8 n' H8 t( [% d% D9 }    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
2 Z, r, U! T, J: u/ V    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>6 h, C- \9 k# `1 l+ j! \
  </tr>; b* i- t! V/ [7 X5 \# @' k- X5 x
  <tr> % S4 O: n) C' n8 y7 \" T
    <td>
  e% A. [# J. N7 d9 u% r  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
! O1 }9 L, \7 t3 c3 F  <option value="0">请选择部门 ---></option>
. O% k" p1 r, X/ d<%
$ C9 _. K* P/ k    string sqld="select * from tdept";
$ E; g  F5 X" D7 d1 ?stmt=conn.createstatement();& R9 a7 ^' Q6 b# n, }
rs=stmt.executequery(sqld);
6 I; z) T; e1 `' wwhile(rs.next()), G% n3 Q- B& y9 n# I6 U2 j
{
3 D& a0 G" n! u' l# T5 k%>
+ _, L- P- m" @4 V  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
7 {! T% v9 d. @) S7 \4 l: Z& V<%
5 Y* a8 }* g0 P: T5 X& D0 e}
" x+ Y9 @! g9 |, V% I9 d- X%>
+ X% s; o0 T6 u, Y  _  </select>
( X1 Q+ H# I! B) |& z</td>
. ~8 D$ e( r$ [; B    <td>( M$ t0 A# C* k5 M7 _( q5 q) E
  <select multiple id=city style="width:150;height:200" class="bgc">
: I. M) P# v. M) v5 S) V  </select>
6 t( [3 Q) c+ T3 V</td>. b* h0 S! \) m7 E
    <td nowrap align="center" class="bgc">
- a* K' k. u0 Y& |  W  G& n  <input type="button"  value="<<" class="buttons">
/ N/ n) D7 s. k  <input type="button"  value=">>" class="buttons">$ A9 k3 c& o( w: _: X9 [
</td>
3 g+ p3 g4 r) Q& ?- l6 P# V    <td>& U7 i; f- T+ A3 R; x& v$ A# s, |
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
0 n% G- Z: f$ L, ]+ y' H3 S' ~0 g  </select>
/ E, q+ d6 o' X2 E! |9 R</td>. g5 C2 Z. {# n: P# t
  </tr>
' z+ V" C1 N6 b7 C- e) O  \7 V. ]    <tr class="bgc">
5 b3 `# j9 S! v9 E, F    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>1 }1 \/ [) H/ I: {: w& z! a
  </tr>6 d8 |" q# Q+ }+ p  }2 g7 g
</table>9 r1 ]. B6 f  r: b. F( g! X! h9 a
</form>1 ?9 E; c" r5 j. q6 w4 J" ^
<script language="javascript">% b6 x' B$ D! u# ]( E0 m& T
//人名移动
2 X  T/ \, B, x( Y$ Zfunction move(fbox, tbox) {7 g0 \  q4 ~5 h% w
var arrfbox = new array();
) J+ Y) ?7 x* m: M% Jvar arrtbox = new array();8 d1 b$ n7 J+ M( E" u$ h' w
var arrlookup = new array();& a! L# G; a0 p0 C4 [7 ?. P- i6 R
var i;
0 A1 B7 j# A' k  W( X4 N2 ?' Vfor (i = 0; i < tbox.options.length; i++) {
. \7 T1 [( Z  j7 u( g2 q0 y5 Harrlookup[tbox.options.text] = tbox.options.value;9 s2 m( m3 D( z+ q# I2 ^
arrtbox = tbox.options.text;. ^* C8 K% G/ m( c/ V
}" y2 D4 o, W( M1 N) j$ [
var flength = 0;1 j: ]1 q9 r' N+ i  n. T
var tlength = arrtbox.length;
* w% @+ C: ^: c% |1 }for(i = 0; i < fbox.options.length; i++) {( P  i3 S' i6 C6 d) f8 g: D: U
arrlookup[fbox.options.text] = fbox.options.value;
5 j3 Y7 O0 [- I; O" aif (fbox.options.selected && fbox.options.value != "") {+ M4 l- p& Z5 E! [2 I
arrtbox[tlength] = fbox.options.text;1 u( v# p: c; N6 [2 X% Q
tlength++;; ~8 o/ E. m! W! x
}( S) V$ ~  g- n- v! M
else {5 G# v3 X' m" M" \( V
arrfbox[flength] = fbox.options.text;) p0 p5 O0 l0 Z3 }- O3 p( d1 {
flength++;6 U0 V; r: a1 a. A) E" B
   }
6 N( j$ ^9 ^; |! r2 Y  W( t2 n}5 z, h- f9 N% i- _; ?  u
arrfbox.sort();
7 p* W5 f. ~) narrtbox.sort();8 Z" L  a! B. p9 G5 G
. X+ B. Y0 [- {1 H+ w
fbox.length = 0;
& a2 O- |0 }1 ktbox.length = 0;
4 Y0 _) R7 M/ Q% S: i7 svar c;) k% k' D6 r! N. {- u
for(c = 0; c < arrfbox.length; c++) {' g7 |0 B$ G* n2 q
var no = new option();/ @2 M& p3 @) S
no.value = arrlookup[arrfbox[c]];
' E3 p4 C6 j, {& e; Rno.text = arrfbox[c];0 m( H# s) ~( J9 M9 N0 S. L
fbox[c] = no;2 j+ N' p, Z, a" e% O/ c
}
. h3 h! c' N4 ^! C- c8 t2 ~/ Ifor(c = 0; c < arrtbox.length; c++) {1 i& T* h2 L+ F" l& T
var no = new option();/ H2 T' h5 {8 ^. B0 m3 X
no.value = arrlookup[arrtbox[c]];; Z1 R6 Z) v6 @, l( x& L
no.text = arrtbox[c];1 H/ w+ p: R- E0 g8 y
tbox[c] = no;
, N& E/ e3 D% j# P   }* C$ O+ X# u/ \3 q8 T4 i- M* h
}! r1 M  `' X0 e0 v2 s3 A: g
</script>) H2 E: A7 P( ]  `. Y3 t! J' I
</body>
- Z( Q! Y+ w- M( }8 u

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