返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"( e6 f( z8 K3 L6 [
         c pageencoding="gb2312"7 Z) f3 M# g  A7 k3 d& c
%>
) e4 I; h* ?" {# @( P7 x, m) S" `<style>
4 |$ g9 \( R" O/ J/ I.f9{ font-size:9pt; }- `& F* d0 A8 e0 Z5 v
.bgc{ background-color:#aecaf9; color: #0033ff }
3 d  q3 c' f, t  c9 z  f- N.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;+ B9 T1 t: l3 W2 {
  border-bottom: solid 1px #4e7dc1;; R' p, v. k: Y- d0 x  d; g
  border-left: solid 1px #aecaf9;
  x+ ~$ ]* i/ X8 ?3 ^  border-right: solid 1px #5679bd;7 }  i, P, r) G
  padding:1px;
% W# b, y' |1 R* M! r) `7 v  margin:0px;}
# A8 i8 _# {3 C</style>0 z* P; g& g. ^" v; }- r* X6 Y" w
<script language="javascript">
" G6 F6 H- R2 `& K! Y<!--# a  O* q" A2 z' v6 A
function rv(): r. s7 Q4 f+ G1 t+ M; T: n# l0 j2 C
{
$ F+ D* [- S7 ^: q  var val="";
" g' F7 d. P' ^3 R  g6 T  for(i=0;i<combo_box.list2.length;i++){& v5 B1 K5 s* M+ V; o9 n
   val+=","+combo_box.list2.value;
9 R( y7 B2 Q: F( @* z  }
% `$ S" Q& t4 I4 \1 t5 [) g- C6 e  if(val.charat(0)==","){( l) n( |- d! c- X
   val=val.substr(1,val.length);
. v& X4 O* c' |7 a+ Q  }
" A9 ^1 K3 [9 e  opener.form1.frecname.value=val;
' F$ z7 W- h- r+ J; j  self.close();2 K5 \, B/ f" c
}, _3 D) n; {, b- D0 W- B& z7 V
//-->
( K  X! ^' ?0 T1 K5 o$ c</script>% p4 ~7 a" h9 o. l; |
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">; Z- ~, p8 c+ B4 u
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />4 @. z% r* u% b+ o- r; n+ X# D
<%
1 U; A9 g$ u8 r& \7 v6 [2 V; R  cdatasource ds=new cdatasource();  //数据联结bean实例- W% k+ g( I& E! @
  java.sql.connection conn=ds.getconnection();
7 s" c! N5 G7 ^9 D1 r8 v9 K  java.sql.statement stmt=null;
2 g$ J. ?7 w/ O- h7 h  java.sql.resultset rs=null;
/ |+ F% ]# Z2 ]4 n  cdatacheck dc=new cdatacheck();/ u- q( d# F% `, a. g
%>1 A1 x- D* W& b: A  _6 Z
<%
+ C" H/ `& ]0 L% jstring 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";
4 M: P5 E) p0 U" D! L8 V% l! dstmt=conn.createstatement();+ g3 Y2 h  w1 d, J/ s- U( r1 y; E
rs=stmt.executequery(sqlu);/ @9 ]% s) Y7 y( j4 Y; U. Z
%>6 ~* u+ R5 d8 d7 D& X, Z
<script language='javascript'>8 G% V  a0 y9 }$ U. x* G7 Q5 T
arr = new array();
0 L7 N2 V( u& L7 s; t7 u<%  int temp=0;
5 t3 A( Q  o- \( B* Kwhile(rs.next())
$ c9 T* s$ W: s: {7 A{" Y) Z6 F+ U2 [
%>7 u9 B( [+ `9 b& n( b% R: I
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");2 c7 s( ?/ `& C$ Y  e5 y
<%
) F+ d+ z1 I  O, e. gtemp = temp + 1;
( t$ Z3 f# O' M}
- b- r' {0 G  S" p! y%>8 }9 Q/ w2 C8 n- j4 h! f
temp=<%=temp%>;
0 \- Q6 G  v$ Gfunction changelocation(id){ ' Y/ X5 U8 r! G/ P% L8 A
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 8 X% B! U* P. b5 J
var i = 0; # W7 }- _( L9 d( h0 J8 p$ h
document.combo_box.city.options[0]=new option('-------',''); + F1 {! L9 ^( N) S$ `
for(i=0;i<temp;i++){
2 E, L, G3 L6 w4 q+ v% a" G5 dif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
- S4 Z' g4 j+ Q8 V2 C: b8 O. Edocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
: ]" O% Y! c7 G% o$ U1 d} 6 `) S) O, l# [! H
}
: M" e' j. R3 s* v, \: ~} 3 t/ i% g) Z, p( A
</script>
, d: O! g% P/ s1 m( a/ \. Q
* l) c6 m4 S2 J: G# J2 C" I2 R<form name="combo_box">
, c1 g* E. z) e8 b4 _<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">9 G8 l0 Q; a+ V0 B/ w
  <tr height="24">' X  `2 @- M' m; E7 K
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>, r$ L. A6 @+ V+ e+ O0 X4 v
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
9 k+ Q* F' K" G. R    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>8 A$ O( X' u# p$ W7 l" ~, W; [
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
# l$ Y! ^" a/ z2 |  </tr>
( M* M( [$ [, |9 d  <tr> / U7 Q  y8 c& F+ O$ u! ^% t# u: ]# V5 O
    <td>
& i& @0 z! i. P" C* r  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
! |6 `" ?# F- F3 D% P  <option value="0">请选择部门 ---></option>; I* q. v6 j, i, ~
<%
3 p# F8 Z5 `# }. A5 i    string sqld="select * from tdept";
1 z7 z. {3 N# r$ ^% r0 M5 \- |stmt=conn.createstatement();
. q/ s* t- U; I/ Ors=stmt.executequery(sqld);  r& y6 P" e2 |; [  k% R( R
while(rs.next())* K/ t. v8 X! y* f* o
{
7 d2 U+ O" N# q0 D' C8 D1 E) E: h%>
" L  s! K) W; v! V2 [  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>" h: J6 f9 Q: ^8 \
<%2 p$ D( o4 J7 a  p
}
3 [* J7 v& n" Z+ m%>
7 t' k: N8 n1 b) R9 K  </select>
) g7 f, h0 v) D2 M2 z" N( z  R</td>
% M7 S* k4 T3 q5 o) S* Y5 y    <td>- G# S' l5 k  z
  <select multiple id=city style="width:150;height:200" class="bgc">% X& N/ T/ P; S" v. ^6 Q8 C
  </select>5 S3 t- I* j+ ^& T$ q/ v' S3 H
</td>
2 d$ _; V7 e$ O    <td nowrap align="center" class="bgc">0 \; ^: w  q! e3 `9 m
  <input type="button"  value="<<" class="buttons">
1 [2 Z, Q; Z4 u% {  <input type="button"  value=">>" class="buttons">
3 v$ S9 _' b" }% G</td>
( M# o6 L/ d8 G/ Z' u    <td>
: n- m8 J& c' c9 ^) `1 G: v  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
7 b/ J" N; H- t, S8 P" Z  </select>3 f# u) Y& T- z, \$ E! W6 a* Y' K
</td>9 T) T' z- Q: h& q2 c
  </tr>0 X; ^  O* i, s+ C
    <tr class="bgc">
1 W* S0 [6 L  k/ u    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
. Z9 A  k2 s# K" U  </tr>7 j+ B" a. ^6 m, l9 Y% p
</table>5 R; |0 ?6 _# Z  n
</form>
; }' m; Z6 R  Q3 P: M3 b: u2 M. T<script language="javascript">& z2 Z5 d( s$ @( d+ u) w
//人名移动6 e& ~3 J# v  V
function move(fbox, tbox) {0 ?3 G: j+ p9 v4 z# _
var arrfbox = new array();
1 ^3 \" n- l: ~var arrtbox = new array();; q% D! V! W' p3 M* M! j
var arrlookup = new array();- _+ M( o1 B7 G
var i;
; a, P  `! k7 v6 i1 x# r; mfor (i = 0; i < tbox.options.length; i++) {
. y) _* G0 [* ~  D+ varrlookup[tbox.options.text] = tbox.options.value;
8 e# Q. K2 }' Harrtbox = tbox.options.text;
! E0 Y9 x0 B1 c( m* m}1 G1 D9 ]4 S4 N  c
var flength = 0;4 P/ j. p6 J! S* x# }, F$ }' }
var tlength = arrtbox.length;- V% i. X- N8 h! [& n7 D
for(i = 0; i < fbox.options.length; i++) {7 U' F4 J3 I, x: a3 d! [0 ?
arrlookup[fbox.options.text] = fbox.options.value;9 e0 W) m' I+ n- C1 \' G
if (fbox.options.selected && fbox.options.value != "") {
  W& e, E$ c: s& }8 R1 q) {6 Darrtbox[tlength] = fbox.options.text;! X' q$ a( `6 p% Z7 Y  V* f
tlength++;# I# E$ u% h& @6 D& v3 O
}
* Y6 d. C& p1 ielse {
% U/ M. L2 R5 e$ R, }- garrfbox[flength] = fbox.options.text;( ]5 w, C7 J8 E- b: R  n
flength++;! Q0 ^0 G. y5 D4 W# }3 e
   }: ~5 F* M& N. I- c8 c: V5 \
}  M. |$ t. s- N9 `$ V6 @. G+ }
arrfbox.sort();6 X! Z9 M, B- ?8 B: E
arrtbox.sort();# W  V4 K8 w& ?6 s

% `$ K7 O! o! f1 e% |1 J5 N& dfbox.length = 0;
1 h5 J, y* N6 Ytbox.length = 0;: ?- `# x9 o# G8 r4 b! s% A) `
var c;
* }+ N+ C  W9 I7 afor(c = 0; c < arrfbox.length; c++) {
7 j! Q8 [/ o) N  S* ovar no = new option();, o7 E# k! K0 |5 }1 D0 ]
no.value = arrlookup[arrfbox[c]];8 N8 C; _: k/ u4 @# n
no.text = arrfbox[c];
, z* k2 {- L0 x, F3 Z  c. I7 Hfbox[c] = no;
: k( ?' P! ]& `/ ^}
( r+ j5 N2 o, p) W! j) D* Afor(c = 0; c < arrtbox.length; c++) {) R) q5 a6 I1 y+ `3 U. n
var no = new option();/ ^; N1 Q" X9 H# A9 Z- H( p
no.value = arrlookup[arrtbox[c]];
8 w) ]4 j" n( ]7 u+ [; T( _7 m' Pno.text = arrtbox[c];6 U6 Z& x  v/ X
tbox[c] = no;
) N0 d5 L4 u2 T# p4 N   }( [: J' W+ s3 E
}
3 y) X2 x2 d2 ?% g' L/ T</script>( \% v1 y- y5 q& N! N, w* o
</body>+ _- V  s. e' T1 r; E

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