返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"5 ]0 B5 U4 r8 D1 |
         c pageencoding="gb2312"0 b3 r7 K+ r, g7 ]* G
%>
3 \& j5 N/ l3 b! H! A* v<style>. ~: z+ w. K( Q) j. [2 Q
.f9{ font-size:9pt; }* @" e- W3 G& e
.bgc{ background-color:#aecaf9; color: #0033ff }8 p3 `+ V, d9 g% Z0 p: v# X
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
6 p+ [! _; i2 M9 e7 v  border-bottom: solid 1px #4e7dc1;  x$ e0 J( Z4 f
  border-left: solid 1px #aecaf9;
( D& T9 P1 `7 Q$ G/ O$ [  border-right: solid 1px #5679bd;
8 w. e+ U3 d  T6 l  padding:1px;+ \# _1 ?+ }5 g) D3 b  B
  margin:0px;}/ L3 P; p5 @# w1 ^" `
</style>
: ?: s1 n& K) y  ]4 o) _% W' Y<script language="javascript">$ `3 K8 A: F6 X$ |( }
<!--3 {+ W" |) V$ v' l  W. H# ~- h
function rv()* r) @2 Q' Z2 b2 D9 T9 [8 ~
{4 e7 X3 ^0 R6 L0 J; Y7 a
  var val="";2 F7 [9 Z, h: M1 h1 B3 [& ^
  for(i=0;i<combo_box.list2.length;i++){" j# k5 q1 A8 g6 d
   val+=","+combo_box.list2.value;
% v5 R$ K7 e9 V+ T: [# f( k  }
! p+ f! n- Y7 k; j: C  if(val.charat(0)==","){
' W0 t2 n8 y5 q9 M. S   val=val.substr(1,val.length);. n8 p4 N7 ?7 V5 P! Z! r
  }
# J6 F0 o7 p" L5 j1 u0 c' T8 o4 s  opener.form1.frecname.value=val;
0 r2 _) m* N& \" u/ @- n+ t8 S- ]  self.close();* G# c, k( E5 N* B7 _0 R$ z! _
}
8 y. T) w. c2 Q//-->
7 p6 P$ P3 B6 u</script>
+ ?9 D8 u* y' r  l& g<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">* \4 S) y2 \* D
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />" l2 p8 g( y% [/ O
<%
: |0 f9 O0 |* l  cdatasource ds=new cdatasource();  //数据联结bean实例% ]# p+ \+ i! I& L8 o( U( B
  java.sql.connection conn=ds.getconnection();0 U% t+ E5 v/ p* P: ?& p. j
  java.sql.statement stmt=null;
# t! T4 v. `+ F0 c  E  T/ ?5 L  java.sql.resultset rs=null;$ k& e' E0 P- z( ]; i3 M4 A
  cdatacheck dc=new cdatacheck();& ?0 c+ h# n% E
%>" o% X) j, Z9 @( H
<%
* d/ w+ d0 r; [& }0 \* 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";
# ?; i3 V$ A- x  O1 l, ?  y* q7 qstmt=conn.createstatement();& m# w- h' y9 V+ o/ D
rs=stmt.executequery(sqlu);
1 U0 J6 o  z. t" `4 R%>
# p: n6 S! F5 F1 T1 @2 C<script language='javascript'>
9 {; B: _4 n7 Z: \/ t9 t3 rarr = new array();
8 Y& {) `8 b0 E7 }8 r7 N<%  int temp=0;/ N4 F; @! t3 a9 S
while(rs.next())
5 [" l6 r7 s8 |0 E8 ^! [{# ~" F- ?2 ]4 E3 [0 s/ _$ V+ r* ]
%>
5 @" m. o2 y2 \) z6 `arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
" M9 ]2 ?) Q! J' w0 ]7 }<%
+ O3 |  S, s& wtemp = temp + 1;
& y, [8 g/ t) I" K" e" |}
3 B  g, ?/ a7 ?# k0 Z- c1 |( q%>" E  \7 _% D) f" _
temp=<%=temp%>;! h6 ^- M) _1 V# N
function changelocation(id){
; q2 J1 y! G7 gdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
6 [. J2 _. z7 `1 r; j  T/ ivar i = 0; 3 Z5 A: I2 ]/ i
document.combo_box.city.options[0]=new option('-------','');
/ ~) H2 M- a( @for(i=0;i<temp;i++){ 1 {% ~8 I% y, M9 H
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
3 m0 G" e! S) c# ldocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
6 e( Y% b8 ]% s  ]5 e1 L: w} * h8 `0 w1 p+ r0 [( c! ^
}
5 {  ]* \; m# x4 `, j2 `5 ^, t9 X}
' t; W: g% B1 i# Y</script>
8 ?: h& W* }. J9 T
8 Z) i9 Y. e: c! C4 \<form name="combo_box">& X! m0 b9 A  J1 R9 S8 [) y/ g3 b8 N  g
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">- v% y3 t/ J7 P
  <tr height="24">
4 e' o, O0 q9 Z1 i! @& e    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
$ V# m6 F9 ^1 C% \3 k    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
/ P" p! y6 B' t$ V+ J6 \    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td># P% {- w; f# A: M8 l9 J
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
* S4 I9 r+ c% ]6 g  </tr>9 f* Z& i% F3 u
  <tr>
( z4 M3 g) o% c  a4 t' [/ t    <td>" ^- m1 b' X5 T* d/ o
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
' u: j' I) l! T) X7 t* P* W  <option value="0">请选择部门 ---></option>1 {- U1 d" I' d3 s
<%/ X* c5 ?# x7 j9 k+ L
    string sqld="select * from tdept";
7 P; b. \5 h7 c6 |: bstmt=conn.createstatement();
. u* K" [$ u* |# m& w* Drs=stmt.executequery(sqld);
# J: ~( r. S7 ^# fwhile(rs.next())$ @) u+ y, e. ^+ J& p- c1 [
{4 M) T# p) K; A$ {
%>
- }$ F; q$ F1 U) ~" J- q" i' x/ s9 _  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>4 f# c& r5 m+ A
<%
2 Y% ^9 T5 }6 i) e# j}
2 ^7 r. `% D1 \; p! U%>
/ k5 P2 d; W" A8 W! `  k# R  </select>
( l2 [/ I6 D. \' f9 C</td>
2 M, D4 D' ?- g/ i    <td>
# p0 T; u5 ]3 q) Z, w* N, G  <select multiple id=city style="width:150;height:200" class="bgc">% t6 O+ b/ Y1 L0 e/ C/ {
  </select>
. o: c" G5 \. A9 P9 ?$ N5 @# v</td>
& y  H# X4 x! c! D% _* {& e: B    <td nowrap align="center" class="bgc">4 c" e, y' a% z: x5 u0 \
  <input type="button"  value="<<" class="buttons">
7 w+ j& |: J$ @* i  Q1 g" W2 l  <input type="button"  value=">>" class="buttons">4 X+ P) f! Z/ {/ a
</td>
  \2 L; e: F1 z( T) M; s- v    <td>0 {% K) ~' O. G0 T# S2 I  Z. P
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
; t7 w0 s5 U) G  </select>8 Q2 e! J" q1 R: K
</td>
5 Z# D! I7 P) M) v( P# w  </tr>) {/ D, i! G; P1 N
    <tr class="bgc">
4 `6 I  F3 F( O' {$ a    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>+ b  e  m7 ?1 W) B( u
  </tr>+ P, \% M0 q, M% n
</table>
9 G( s" ^) E% y) w& C) f( }! ~</form>! z6 j0 G, P; E+ J7 M2 v1 ^( b
<script language="javascript">7 x' ^, ^: k9 v$ L4 a
//人名移动
7 \: s: a0 K( N( }, {* o1 Lfunction move(fbox, tbox) {6 u8 o9 J1 \- v3 ]9 X# m2 n
var arrfbox = new array();
. J, Z: \$ o. O7 T# xvar arrtbox = new array();3 U% q1 U, k$ o/ R& z9 M
var arrlookup = new array();
5 n$ \0 q9 j; g. u: h' ~8 Dvar i;
: x! m. g$ {, t; y5 T2 Xfor (i = 0; i < tbox.options.length; i++) {! q) ~+ _+ w" P' @* M/ r7 E3 a0 g
arrlookup[tbox.options.text] = tbox.options.value;
4 n: i) [4 s2 m6 h( Z, Garrtbox = tbox.options.text;
3 t( K) N' F$ ~3 r}
- P- p( ~, _# [$ n7 u2 Fvar flength = 0;
! v& n7 [4 l- H2 g, t# qvar tlength = arrtbox.length;1 a6 R0 n/ X* E- L* c! @: T* X
for(i = 0; i < fbox.options.length; i++) {4 ^7 o8 x1 o, N; l5 M; |+ N
arrlookup[fbox.options.text] = fbox.options.value;
/ d0 A1 w2 ?5 d7 |if (fbox.options.selected && fbox.options.value != "") {6 i6 y( J" h$ O9 C; e" O; u
arrtbox[tlength] = fbox.options.text;2 A( c+ ?0 n4 U# ^8 h; k# K& j
tlength++;" ?0 V3 J/ ]* M4 ]
}$ Q2 x3 |9 {9 H% V$ R
else {$ f$ N- Q, W" L5 d
arrfbox[flength] = fbox.options.text;
+ |& y8 c" Y2 Bflength++;' W1 J/ e4 p' M( t
   }+ G+ n: h" o9 x! h' V: q+ v- U' D
}
# N  O6 F* o, n3 U; |; earrfbox.sort();
: L8 `. R0 u! f- f8 V  k4 z; H, s9 Sarrtbox.sort();
/ d; _  v6 i8 M4 k+ s( y* {" F* W
7 `) u2 ^1 F5 `* xfbox.length = 0;! K. ~5 F: k  {. n( `# X) J1 t
tbox.length = 0;4 z" Q$ X: `& K/ S7 O. z; V. I3 F
var c;
2 V( a2 n; n1 _for(c = 0; c < arrfbox.length; c++) {
) Z8 X; k+ y0 [1 @! a8 Zvar no = new option();
3 e- j/ w& K5 J$ H3 G5 C, zno.value = arrlookup[arrfbox[c]];
2 Y" F' T+ C. L6 E3 x; K# K9 O, rno.text = arrfbox[c];8 s" R4 T; f8 b
fbox[c] = no;
9 h: `1 V- a6 W. I: Q6 z- `) `% r}5 [. I* a4 \) j. ~; X
for(c = 0; c < arrtbox.length; c++) {
! D4 }7 d6 l% z6 e3 O6 ]6 U. Yvar no = new option();
4 G' r& d8 Z6 Sno.value = arrlookup[arrtbox[c]];
8 e6 z- d2 h+ N8 uno.text = arrtbox[c];
+ g1 @; {- z9 i% Q& stbox[c] = no;$ B! j7 @- d1 L
   }6 ^! z% r, m+ e& W, ?: \$ i
}$ n, q. ?* k/ p& v' o# \
</script>
- @0 R" ?4 Y6 i) o4 v. n</body>
0 i/ U9 r/ G3 Q7 e& z7 h- M. e

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