返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"9 x% D  g* G6 L7 N- }9 n. H
         c pageencoding="gb2312"
3 W5 \# ?: u6 q/ y6 f- x) x%>
. I* R3 s! b& _; G6 w2 c<style>
- ^. ?/ G  r7 S2 |5 |% v.f9{ font-size:9pt; }
& c+ F  I5 s/ T9 Z/ l  W.bgc{ background-color:#aecaf9; color: #0033ff }
+ d- b$ [" I$ y/ K.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
/ [- j5 I5 R0 _9 Z2 a  border-bottom: solid 1px #4e7dc1;
, u% n, B+ L6 g1 z4 L- H% }# g  border-left: solid 1px #aecaf9;
$ x+ X/ G# L2 `/ E$ R: J! h! H# h0 t  border-right: solid 1px #5679bd;, P' l& Q' f& ^* A
  padding:1px;
2 P' Q: p7 Y2 {3 ^& ?2 b+ k  margin:0px;}# ]2 ~7 ]. K$ o. o& b; ]
</style>. n7 {6 Q8 _5 I
<script language="javascript">
+ n9 Y. C! S3 S8 _1 |<!--
4 N  a9 r$ y, M7 x8 {function rv()8 m0 v# s/ l4 |, u4 S$ T* ~
{
0 E' q  i& e: r  ~8 A; H  var val="";1 ~+ a$ ~9 }+ ^/ i1 Q
  for(i=0;i<combo_box.list2.length;i++){
# f- q7 B+ u! u4 S7 J   val+=","+combo_box.list2.value;( w" [$ a/ O8 N( [
  }
9 ^6 L1 d# e. Q2 A6 k& y  if(val.charat(0)==","){: Y7 f) N% @; |! @4 t
   val=val.substr(1,val.length);
: G" Y1 J6 \0 c% U# ]1 B  }
7 x) E3 S8 n! y0 C" d: X1 r  opener.form1.frecname.value=val;, I2 X' U( T. u' k) l
  self.close();
6 y: k0 \( |9 Q}
: u: ]3 m+ |7 B: P//-->
' {5 ~: x2 `: K5 l</script>
1 z: q% A& H9 K, v) n% i<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">- A7 v; l, d( f+ v
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />, @) W8 T, D% ^. J
<%
4 Z1 ]- G3 L# u# Y  cdatasource ds=new cdatasource();  //数据联结bean实例/ k) T- m. M0 _2 ?# z( K
  java.sql.connection conn=ds.getconnection();) Y. Z! c7 t( K  h4 N# b( C! ~
  java.sql.statement stmt=null;! y/ T$ b& ?4 A/ S2 `
  java.sql.resultset rs=null;( V# L+ O' U& w: ^9 T* `
  cdatacheck dc=new cdatacheck();- y& d" L3 }0 H- I/ O
%>
% [7 J( _* ^5 T2 h<%
' v. A% `+ _- M" g) H9 \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";8 Z6 {( S& _$ t5 S
stmt=conn.createstatement();1 }: K9 T" v( q) S$ k
rs=stmt.executequery(sqlu);% ^+ C# X" S6 l+ c0 }
%>
4 i  P) o7 X' l# t; c' L<script language='javascript'>+ t/ C: k- r6 q4 \
arr = new array();
5 f0 q8 A' P5 |/ _; i( v<%  int temp=0;
9 O* i9 C; n. S0 r% o) V% I! Uwhile(rs.next())
6 S5 P5 V; @4 H' _! \4 o{
: j0 f8 C! F3 R% ?1 |%>0 R: A2 P. w/ A; f4 d7 V
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");( V7 T  a6 N- e. O
<%
8 v1 N: O- [  X% C$ D: Ytemp = temp + 1;
( s% `/ R. M8 o1 x}
% D* E- f7 q' e1 E) n8 O%>
$ ~* I4 I0 Y, P. U/ A+ {5 l3 f$ Rtemp=<%=temp%>;
: E& r$ |  N' z( j# rfunction changelocation(id){ ) b+ D8 D( i! E6 u% Z: X/ }: Z
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 - P1 W+ l7 S1 r6 d/ _7 I
var i = 0; ! ]% Y6 |/ E' Y$ O+ r( i9 U' R
document.combo_box.city.options[0]=new option('-------',''); ) Z; `3 o' r  k  A2 E
for(i=0;i<temp;i++){ 3 q( r% j. F: s9 S6 M; `
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
# V* |: a4 @+ j, i7 ndocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
- K4 _7 g4 B8 ^9 g}
& s6 }% I% k4 ]$ A/ v} ; H& e" Z( }% f; r) g9 E
}
6 B5 Q, w# U: R  o8 v3 M. x' c</script>
% I7 p. P* [: N5 K! q6 Y2 E" C
: I- s# D5 O+ e; v" a6 u5 S" J<form name="combo_box">
8 F0 O; L$ X, S) d<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">/ u& b- p8 u+ |1 s  \" I# M: {, n# J
  <tr height="24">
+ X) d' l& F* W' X; K  A    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
8 g& b/ B$ H- p1 i; k' J    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>5 }; `/ D6 n  K* G. U4 p$ L4 U# U+ L
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
8 v' B" K* H$ i  x    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
9 m! m" v1 x+ c5 t$ F- }  </tr>1 U: S3 P9 a5 i) y/ P3 n' y
  <tr>
- y) d& r: y! A    <td>4 P& c; g0 t& a& Q' F# r
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">. G/ q" m2 E# x" F. i
  <option value="0">请选择部门 ---></option>
+ L1 R5 K9 |  y# z<%6 P' O* P3 x$ w# T
    string sqld="select * from tdept";- h! Z4 }( Y4 D1 N2 d
stmt=conn.createstatement();0 e1 ^, T3 x. ~% x) M
rs=stmt.executequery(sqld);
9 {" d) U2 S& A3 cwhile(rs.next())0 |8 l; k, {* `# C% x
{
( }# ^( D* B" y0 x+ K4 v, u%>
$ y8 j3 [$ D/ k. k4 I9 ?- }  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>2 ~- Q% |2 l8 g& L9 G, L: J' `/ b! ^) Z
<%
. Y8 ~3 ^* a2 q9 a# }4 Z}
# X" s  ^* Y7 I0 ~& V%>
9 D4 f0 Q  _" N5 q8 Q' [  </select>, |; f) s& D3 g) ]% @: ^% S
</td>
6 |3 g* D0 p6 M% R; \* j8 G    <td>, n& ?* m+ z. L, P9 Q8 ]/ F+ a0 W
  <select multiple id=city style="width:150;height:200" class="bgc">/ |  C; {  G8 }$ M" w
  </select>
1 g4 n3 {! W3 n</td>& Y! G- P& n* y# \) o! N
    <td nowrap align="center" class="bgc">" V" @' J0 \0 v* \+ ~
  <input type="button"  value="<<" class="buttons">' G2 P0 v- U, U% `4 S/ N9 d
  <input type="button"  value=">>" class="buttons">6 R; ^" t( y& M  F" n
</td>6 i1 g4 q  u) w- C
    <td>% U* W3 N( Y' M! C5 \
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
; Y) v4 @) Z& ^4 p1 N8 W# j9 T2 C; s  </select>
! z3 u* ]0 R& B  v3 j9 C</td>' o' z+ G- _  n6 X5 S' L
  </tr>
3 Z9 T+ j+ N4 W, V3 v; l# x    <tr class="bgc">
8 x6 P. J/ P% K- @6 Q4 _" T. i( B    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
7 {& ^# t* a- E8 U& I  </tr>
/ y( I0 u6 H3 {  ]4 s, D* O. I</table>
, S3 R1 `2 Y9 Z( V</form>& R. t. L; u, e8 @8 I+ _5 q
<script language="javascript">
1 l% s6 g7 v6 {) E9 v% C//人名移动
: u4 j: O- z3 w; ]8 [function move(fbox, tbox) {9 h1 t2 @+ E% j2 \4 o, `9 {& c+ O
var arrfbox = new array();
8 N5 S0 V. ^8 b7 p! |" d  j' b) uvar arrtbox = new array();# d- h: M6 Z- J3 D8 }
var arrlookup = new array();
' ~2 f" S  p6 @/ F% Gvar i;# y/ a6 v6 v, F) @! Z: ^, @1 X# X
for (i = 0; i < tbox.options.length; i++) {
7 x2 z+ _8 J* barrlookup[tbox.options.text] = tbox.options.value;
- P5 D8 B; u& M3 P* H8 Larrtbox = tbox.options.text;
( [8 W* @- W7 Q5 y9 K" {6 t% h}7 J) I7 y% v! D2 ~. F/ E( T
var flength = 0;8 |* _$ Z: [  q. W0 j( B
var tlength = arrtbox.length;" m% O& `8 [! P' p5 I* r* C6 m* [
for(i = 0; i < fbox.options.length; i++) {, E- ?% A! l7 G6 P1 r
arrlookup[fbox.options.text] = fbox.options.value;8 K9 }( R$ ]: Z4 r5 o! ?
if (fbox.options.selected && fbox.options.value != "") {8 _& Z) p6 @$ |5 q) n- b3 G+ U
arrtbox[tlength] = fbox.options.text;) u# I: V1 F/ R2 p
tlength++;* u, o6 }1 j; N! |" E) @& M
}
" F8 b7 F  x0 j' j% ielse {
  D) z8 c/ t) t$ }arrfbox[flength] = fbox.options.text;" }  A: [; U- C' e3 n
flength++;- ^7 D9 \2 D& v" h8 I" g. A8 b
   }
2 Y1 Z% K) |# T7 s1 q}
$ K% f& d6 N( Carrfbox.sort();/ X% W# v. m& U
arrtbox.sort();
! k9 i" N% s: C( p. D! R3 ]% j* @% r* @% K% A
fbox.length = 0;
1 z( ^5 J- N5 f& ^  dtbox.length = 0;
2 N) t6 [* h( \6 f. O  c, ~3 n9 C- S4 Vvar c;; A/ `) s9 Q/ w  R; S
for(c = 0; c < arrfbox.length; c++) {
0 @/ F' Q' H: j# Ovar no = new option();
5 Q  I! g3 u; I2 @. |4 v4 k/ d* Tno.value = arrlookup[arrfbox[c]];
% g- W9 {1 ~2 K2 {) Bno.text = arrfbox[c];+ Y" m# T, E2 e& K
fbox[c] = no;
; {# O- g  L" E0 K  |9 L1 H' w}5 V2 d1 L+ l) Q( G4 h$ \
for(c = 0; c < arrtbox.length; c++) {
- b( ?* D& }8 j7 Bvar no = new option();
  x1 G2 C: T+ @. Ino.value = arrlookup[arrtbox[c]];
' P/ f9 u& \. hno.text = arrtbox[c];
7 D" N  z. L+ `1 ntbox[c] = no;  M- D+ }& x. B5 w2 T
   }
* c* |. {6 m2 g9 Z# d8 z$ x; R5 R2 f}  m# e0 V* O8 f. }
</script>4 h5 }# |% |4 D  O5 W
</body>
' u% |6 g# P! A8 I( D. o

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