返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
/ C" Z3 @0 p# P! R, S* m         c pageencoding="gb2312"7 N6 |3 h0 a: s, z: A
%>% S7 `" U" ?9 T7 l) W) }0 b
<style>9 h1 T1 H: w5 T. }- H. a' J
.f9{ font-size:9pt; }
. ~' m& [5 S8 _# J% c3 V. n.bgc{ background-color:#aecaf9; color: #0033ff }8 w" x, V' B  O- e( L6 |) y
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
' {+ ?# b1 C- f- \# g* U' Y  border-bottom: solid 1px #4e7dc1;! N5 ^* Z% b8 V3 e" n  z  O
  border-left: solid 1px #aecaf9;
) f6 G% ~1 z+ Y& m: |! Z: _/ E  border-right: solid 1px #5679bd;
/ m. e% p2 ]# @+ Y3 O! g  padding:1px;8 ?1 [( A. G$ y- m/ o. W3 n
  margin:0px;}& M9 O+ H, F$ q5 N; V* B: R
</style>
; {6 S$ s3 y2 a: M6 f7 Q<script language="javascript">
' N7 I6 p1 ^) F" u/ [0 W& w( l<!--  z8 Z6 n+ `( L7 [0 ^
function rv()
) @5 F& B3 n& ]{
9 n) \3 e" J, H  L  B+ w9 L  var val="";
# Z' C+ g9 N; d: n  for(i=0;i<combo_box.list2.length;i++){" K. R+ d  G1 d' g1 N9 o
   val+=","+combo_box.list2.value;
& T" x1 t; j; I4 G- J  I* {  }4 A2 k* K- o" j$ _  I
  if(val.charat(0)==","){4 Y5 B! k3 C* Z" X. U  d/ B
   val=val.substr(1,val.length);2 X* Y6 e$ S3 T: w" v
  }
* ]4 ?  `' T- @2 ^  opener.form1.frecname.value=val;
# ]" A; C' Z+ S  self.close();
; I4 p2 @5 F* l}/ {+ d8 ]; J' l9 s$ S8 N5 ~0 R
//-->9 b' j' A5 ]% x# o4 h
</script>
$ v- }1 Z9 r* K( P/ Z; b$ @<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
. h% d6 W  J* [5 |0 s<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />) N9 ?& i/ B6 {
<%% O7 b( a" C: r1 U4 B
  cdatasource ds=new cdatasource();  //数据联结bean实例  @" u+ x( z* R1 T/ Z
  java.sql.connection conn=ds.getconnection();0 |' N, Q. j+ z7 d0 ~$ B! M
  java.sql.statement stmt=null;
, R+ M8 }/ q* B7 d  U: t5 {  java.sql.resultset rs=null;
" V6 R- U: u3 t1 Q  cdatacheck dc=new cdatacheck();
: P  D1 I! c0 r% ~$ S7 D. b%>
0 e3 m- L1 g( Q1 V$ T0 Z<%
' b+ X% l& O) p$ C4 y; l, g( S3 Bstring 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";
, Z" [# W/ p6 \" c) s! D" q: g. Ystmt=conn.createstatement();
/ V; F$ J9 \; C' Jrs=stmt.executequery(sqlu);
7 M. [4 T' G) f: a- B; r; H%>
. o% E; ^0 q+ J- O! J* z  t<script language='javascript'>
9 s4 V1 Y: c. q+ C* q5 A. `arr = new array();
9 a; }3 U2 }' ^2 Q0 h7 c' A& p<%  int temp=0;
- P( S) ^- B% A, j$ K7 c  b+ _while(rs.next())5 }8 [8 V0 l( y' B
{
2 k. |3 ]# O5 g* x9 w%>. Z! H+ T+ ?* Y! `7 A
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
, b; `$ v- q8 f% M<%- k. W& i4 V0 j5 P
temp = temp + 1;
1 }8 T: s- M4 Z# ~: g4 ^  e}' [) ^* x1 m8 N' l- z
%>2 ?7 {+ o0 r4 E( W! J& V; x8 g
temp=<%=temp%>;
; ~1 U6 y2 t. @5 M5 p$ Gfunction changelocation(id){ 6 f, W4 m+ E1 ]! t3 U
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
2 ^& ]  m( e' j) T/ y" u/ `var i = 0; * X% q; ^% |: ^, a9 |  d1 g( [
document.combo_box.city.options[0]=new option('-------',''); ( A: }8 r" V# X' `  O
for(i=0;i<temp;i++){ : @2 j; A8 @! x/ A" ^
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
% X6 }' T0 X# j; p6 h; ydocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
! G" ^; z5 C2 @" }} . @7 l- v% f- ]$ B- g! w$ T1 V
} 7 t1 J+ X4 M- [& `5 ]
}
6 R- F, C5 Z9 f/ T! z</script>! f. h. W! g* N; k5 r7 [* ^
# M4 _8 x+ y% {+ V9 Z
<form name="combo_box">
% p% `+ B; P- o<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
1 g2 g3 G: c6 X' z  <tr height="24">$ U7 x6 _, q" p& f+ [$ Y( w+ k
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>- N, z9 y( \4 v6 X6 ?
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
% s( @1 w3 \/ g, R1 F& @( C    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
) X7 j9 [- C8 P0 m& D2 w    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
" Z2 D# `: G# j& t  </tr>; B* ?+ j1 A  r: _9 U3 ~
  <tr>
0 u6 p# d2 k5 I2 q4 E  t    <td>
9 J. Q3 n% f8 g, Y  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">! G: K+ r2 T' O  E
  <option value="0">请选择部门 ---></option>, |# X' i0 ^  X/ s; c, B* u) n
<%( d( Q' i- d7 @' H+ O
    string sqld="select * from tdept";
8 }- a! q4 H6 ^stmt=conn.createstatement();: U9 m% c/ e2 Q6 F+ c( @; ^
rs=stmt.executequery(sqld);# b. f+ J7 F) v+ q! |2 b% Q
while(rs.next())
  Q  P( T  \: c: o- p! F1 Q' _4 U{
" B- ?$ o+ ?; ]  t' v%>+ C) z  M1 n+ ^- c- A
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
7 j5 T7 M% d# p; e9 |0 w; {<%
: |  p" l' ^$ @5 [" ^}
- f; V5 [& Q+ `9 ?%> 8 d" I1 [' O" \: D
  </select># ~5 s- s$ w0 ~/ |
</td>7 v! u- a9 y7 M: a3 a
    <td>
& z' g" c$ L- q! u! @  <select multiple id=city style="width:150;height:200" class="bgc">1 ]( C1 \2 j6 U" D9 U5 f
  </select>; h( T5 l9 o$ \7 ]6 p+ i
</td>
5 T- p: L( }- M6 q8 S- `7 W    <td nowrap align="center" class="bgc">
. o' g) r8 K/ D9 x0 L1 c$ r  <input type="button"  value="<<" class="buttons">
* x* l  Z. {" C+ ]; S  <input type="button"  value=">>" class="buttons">0 U' E) |' {4 h7 w& A" G# ^
</td>2 L  l$ M% }& o, q0 V1 u' u4 ]
    <td>9 ^" ^0 w0 a) o* ?
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
5 K9 Q, Q( D0 D. y2 s2 e  </select>
  @5 P3 v, |, Q9 q  j</td>, E: u. N' K+ q  [2 Z0 T2 \
  </tr># I) L* o+ @0 U1 o
    <tr class="bgc">
. J8 a9 A5 j% N( t' Q, m4 `    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
* W  Z6 O+ D/ v! C8 E5 ?  </tr>% e7 |0 q5 J; P* I! O
</table>
: ]* B0 ]! D2 {5 P</form>! l# x, E- E, L& I( Y
<script language="javascript">. f' _1 ?* {" F! T0 E$ K- A3 j
//人名移动" x& h+ H( E  ]7 T4 I
function move(fbox, tbox) {
+ ]; x7 w! [, g% r) [- Uvar arrfbox = new array();9 Y, f5 b, F% S8 q8 l
var arrtbox = new array();$ R2 p: M( b9 [) d9 }+ A4 ~8 ?. a
var arrlookup = new array();
7 z. E! U4 ~9 Rvar i;
- n4 T/ t' m# Gfor (i = 0; i < tbox.options.length; i++) {% q( g8 j& p3 U( D" @1 U3 {
arrlookup[tbox.options.text] = tbox.options.value;
* g( N+ x' L* P; W$ M6 zarrtbox = tbox.options.text;8 M# v! l) D- p/ T
}2 C7 n+ T9 O- U, ^1 |5 X
var flength = 0;
) ]7 Z, ?8 K/ t5 Uvar tlength = arrtbox.length;9 D" N. O9 [; Q  Q' f, t+ ~2 L
for(i = 0; i < fbox.options.length; i++) {+ z# X# N1 @4 W0 \2 P
arrlookup[fbox.options.text] = fbox.options.value;
6 ^! i1 N1 W* w5 B  ~( Q: Qif (fbox.options.selected && fbox.options.value != "") {; o! z2 z$ [1 R) W" }
arrtbox[tlength] = fbox.options.text;- O6 \' K& J7 d
tlength++;
# v/ u2 O6 N; x( Y* [7 w2 P( v}# W4 d8 P( c; z* `
else {3 }9 P0 q$ A& k
arrfbox[flength] = fbox.options.text;
4 R) y0 U0 T, }% F/ H- @8 C6 Jflength++;+ n! N: t2 J7 U2 {, J* @; D9 Q1 K
   }
* ~0 ^, d  b; ]3 b}
' [2 p& V2 r; \# x, U+ R0 Z$ L& W" Varrfbox.sort();4 s; i  F/ B8 X, Y* c
arrtbox.sort();
* Z" {4 U/ c/ w7 `  o
5 u& e4 Y1 ~! M6 ifbox.length = 0;( y5 {" K3 Z1 [  l* l8 }( s# d$ d5 G
tbox.length = 0;
+ a) @. a) Q* q8 H" N  Ivar c;% X% t( U: U3 K! U
for(c = 0; c < arrfbox.length; c++) {$ a! [( q8 ~' a" j
var no = new option();
3 F& `" l' i' }' M0 Dno.value = arrlookup[arrfbox[c]];
2 i* `5 t3 S- `2 H2 C4 L; ^) Eno.text = arrfbox[c];
6 w1 A! @+ P. V; r9 q' I9 d8 Lfbox[c] = no;
$ t0 N5 e  U) U, y: r/ S}
" G, Z4 v; l. i8 E5 X/ `2 afor(c = 0; c < arrtbox.length; c++) {
' O, q$ y4 X9 ?9 b3 Rvar no = new option();
  ~6 P- _4 f0 a5 g* H. B/ Z& ano.value = arrlookup[arrtbox[c]];
3 {& d; a0 [* v9 V* R! [0 y  ino.text = arrtbox[c];9 F7 a7 U$ d' n/ U4 g4 {3 ]3 X
tbox[c] = no;
) K: e. ?/ r# p' \0 _! u9 V   }
# v* u( ?$ E5 Q}- z$ R/ {( u; b" j' M( G- Z
</script>
, O- v7 k% b- R</body>
' [' r+ \  A  y- P

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