返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"! Y0 L8 f2 N/ k; I
         c pageencoding="gb2312": L, L. G# Y- L3 t' x
%>. w# i( ]/ j* J( G
<style>6 C2 n: o* S! n2 G4 S8 C: K2 p
.f9{ font-size:9pt; }
# ^- v. |; x* N1 Z.bgc{ background-color:#aecaf9; color: #0033ff }
2 E4 h7 t4 Q  k# C( B5 k2 v.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
# j( I$ N( }) k! q, l) a7 R* A1 a" r5 S  border-bottom: solid 1px #4e7dc1;) ^( q* E9 y# J; R0 \
  border-left: solid 1px #aecaf9;
! l0 m9 {, b6 `- V; |  border-right: solid 1px #5679bd;5 N+ w; ?8 N( O0 y& ]! O
  padding:1px;
" z# F+ v/ `* o0 ?  margin:0px;}! L% @0 A$ \' L: [3 U2 b
</style>. k. m6 c, F) ]8 K5 T, {# x
<script language="javascript">. @4 S! {5 i2 D0 C2 c2 v+ ~
<!--
% Y, q! _1 n# B" `, S9 xfunction rv()  q+ `9 O. N3 }
{
% m$ D+ L& W1 N" r  var val="";  F& S+ N) g7 ~
  for(i=0;i<combo_box.list2.length;i++){
4 Q6 M. N; `8 O2 i/ z- G, j   val+=","+combo_box.list2.value;
: r1 z0 U: O0 I) w: {5 x  }
8 D6 A% L. ]) w1 Z" @/ N  if(val.charat(0)==","){
4 }5 \3 ~5 d+ y9 E% m# k7 L   val=val.substr(1,val.length);
$ l, J! M# H( n0 g" x  }
4 U; U% O+ ^- V8 b2 C7 ^; f  opener.form1.frecname.value=val;
2 |0 b; f; c) z$ d  self.close();
9 w' n0 m* b4 n8 |* _  P2 n* r}
! L  e9 Z2 c' k( {9 t  x//-->7 s' H2 S  W- ~- Y! y2 x! c
</script>
, c# m; D8 l$ I3 }0 r7 x<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
1 Z, m: e2 V! n& q$ z# `<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
. P( m/ _! P) ?( Q, X$ V& q<%
8 H" i+ [; \; ~' I) W; G  U% e  cdatasource ds=new cdatasource();  //数据联结bean实例3 G% @( t5 {* j, Y/ i, z5 N
  java.sql.connection conn=ds.getconnection();: s8 [' S: m0 `8 Y' Q! u
  java.sql.statement stmt=null;
$ u% n' [, h) s' ?' D  java.sql.resultset rs=null;
2 A# }! L( I7 Q" F, f( ^  cdatacheck dc=new cdatacheck();5 X& d, h  w' j8 z' P1 m
%>
4 |8 X" D  I) w3 m9 ~( J7 v, P0 y3 F<%& ^9 ^$ l# p0 H5 o% _
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";
) M% u: ?; G- P+ U3 d+ Lstmt=conn.createstatement();
, W8 |" r5 H) m6 I& H0 ?4 ors=stmt.executequery(sqlu);
4 F4 G0 F7 r& T- i3 L' I%>
* \5 e1 N4 @3 H$ D6 \! L<script language='javascript'>
2 {6 j+ J  S% _1 F4 q- R& }arr = new array();
! V1 k- y+ l7 g. |* g<%  int temp=0;1 K; y7 ~% A4 {1 @
while(rs.next())
, s6 b0 i* Y) O6 V/ v% Q; V{( m. `4 u& d- q( B# u! g
%>
( {: c% m. ]- zarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
9 w) G+ A. `, k+ U, {5 l% E<%* l9 n8 f2 B( ]0 A* s
temp = temp + 1;
& z/ ]# R, j9 R  X9 b}
. }& }& I; U3 s$ m" Z7 K- Q- y3 A%>3 q" V& F- a+ s" Q: o- p
temp=<%=temp%>;
! j) l7 \7 w/ M, n& Q( @function changelocation(id){
" D. z1 [5 T8 I2 P& xdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 & q1 P! Y5 P% ?$ }5 D( _
var i = 0; , K! J% s3 K5 K
document.combo_box.city.options[0]=new option('-------',''); 7 _2 C$ R3 b, _8 V. Y0 U9 u
for(i=0;i<temp;i++){
% e- H3 d9 ~; {' c7 n* I" S1 |if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
" q5 p) ]2 F' J5 Z- M7 S4 A  Ydocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
& J2 o. D$ {* ^* v# j1 s' j}
* I; H( D1 `9 C: t- j/ q}
7 c  E: l( U/ ^  Z& d* |  m} 7 W& O9 r' t: [* }
</script>
/ T5 ~1 s& }! e' `1 `+ x5 T- C# G& n2 k4 U# M2 T' q, r
<form name="combo_box">% Z$ m% w4 q4 Q5 _, u
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
! k5 w2 r8 ?2 j, o  <tr height="24">
6 d8 q. p5 ~3 {1 A    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>/ {' n& P+ b$ A# Y6 L  m
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
2 \9 l1 E# J3 i2 C    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>  G1 |3 S/ s. b
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
  R2 e6 X: m6 @& Z  g* }0 S  </tr>
. W" z/ Q8 y8 d+ j, V- i" K. Y5 G0 b  <tr> $ H) V* x" I$ O5 J2 I1 C! r# U
    <td>
4 [! Y; L! H, P% x  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
6 E' @( y; m2 E% M. f0 l  <option value="0">请选择部门 ---></option>2 K2 ~2 h0 N. K
<%
$ f! |2 y4 P# [$ E: _) P    string sqld="select * from tdept";
! F+ [# S% [* ]8 v& sstmt=conn.createstatement();
9 p2 }% d8 v" O7 C& |rs=stmt.executequery(sqld);
+ s( E+ j& A! v# r; f9 k$ j# A0 Cwhile(rs.next())
5 y$ s4 ]4 n% ~{& b6 I" \: i2 h$ n+ r2 ^
%>
: p, K) g9 Z( }3 B. J  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>7 }9 P- ?' j3 w
<%
# x" n' P$ L2 J- O% B}( ~" n" }$ l3 n9 @/ S
%>
- L' q$ S" k  w( ?+ {  </select>- ^- d& D8 D: ?1 V$ l6 u
</td>
- B: n9 M1 g, N3 x3 W' k% q7 s# K    <td>
5 X0 D9 Q6 L# K% o  <select multiple id=city style="width:150;height:200" class="bgc">) t; l/ f4 ^4 o
  </select>
* x4 @2 _3 b1 b1 m' }5 m</td>& ~% i8 K: H8 s0 }/ L$ X, [8 O% Q
    <td nowrap align="center" class="bgc">: L: E3 ?: D' j0 I5 O+ @* _
  <input type="button"  value="<<" class="buttons">- Q% g& O$ p' m* [
  <input type="button"  value=">>" class="buttons">0 R, q. W5 B6 c* N( \7 ]" f
</td>* H3 e! T' N( W- I" I8 @/ S# G
    <td>
9 v' p6 n- F8 Q8 a% P  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
$ z* J4 Y. l2 Z( j3 ?' s( [: s! ]  </select>7 t- ^4 H% u7 b/ q" A0 d
</td>
" `! u& J/ e9 f* }2 r4 ?  </tr>
. [' P# E  p) o4 D/ E    <tr class="bgc"> * }9 L- l( m' W# l7 n$ Q
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>$ ?% G  V- O. C# u; e# M2 ^
  </tr>! D" M2 O/ U+ |& _9 l+ \, k; V
</table>% q0 D5 L! K/ M( f8 w1 X
</form>
) ^* ^4 n/ @+ n% y2 O. T5 M<script language="javascript">0 ]1 P1 r% s5 C8 N2 a; _7 W$ {  z
//人名移动
- t% T; V* c" C8 _/ ]function move(fbox, tbox) {
" N% m2 M7 f3 M6 xvar arrfbox = new array();, f2 K; J- m  @
var arrtbox = new array();
" K! Z# g3 h$ Ivar arrlookup = new array();+ L2 Z  H- y2 u) K# t* l: M0 X7 z1 z
var i;
: R( A1 J8 _7 A: Lfor (i = 0; i < tbox.options.length; i++) {: r+ y- b0 y" V  f% }
arrlookup[tbox.options.text] = tbox.options.value;5 s) I; D/ z& V& J( D" ~
arrtbox = tbox.options.text;, j0 ?* t2 W" F4 h. J; o9 d
}
+ q* m5 n1 G9 ^# w2 p) Xvar flength = 0;
6 V  H# \6 Q! k. Vvar tlength = arrtbox.length;
( r1 _) _' h" }; Q7 F5 o% c) Qfor(i = 0; i < fbox.options.length; i++) {
0 S' x! X6 E! S5 karrlookup[fbox.options.text] = fbox.options.value;$ f) ~2 a3 y$ q! }8 X: O/ T
if (fbox.options.selected && fbox.options.value != "") {
$ p- L# \6 G! A' E, `5 `arrtbox[tlength] = fbox.options.text;
4 T& u* g) V' a, [  Ltlength++;
/ I- [- z6 ~6 @}
" O. e  W8 Z) [% y4 S4 Oelse {
6 y: y6 v; G- [1 T! W& varrfbox[flength] = fbox.options.text;
2 _( Y0 `! y/ fflength++;
- D- T6 O5 y) d; X2 g   }
, O9 C% ?7 j# G' \( X}& u$ e/ V7 ^1 ~9 f
arrfbox.sort();* W/ u% s8 {7 G4 o2 }& N; z- W2 c
arrtbox.sort();
+ A0 k, t/ `9 w& r7 q
& a. A2 W5 k7 ^% A$ Ifbox.length = 0;
. c1 g2 O: E6 A# j/ Ktbox.length = 0;! _  Q% ~, r& ~2 S! r/ q% n
var c;
9 ^" C% L" h5 Mfor(c = 0; c < arrfbox.length; c++) {5 C9 ], o/ Z) L/ w0 d* _8 S
var no = new option();
+ H6 i( F2 _& B4 L1 Ono.value = arrlookup[arrfbox[c]];8 O2 o6 L2 u" w3 `3 H; h8 I" G
no.text = arrfbox[c];
2 g. [4 c0 h4 K9 [fbox[c] = no;7 X! ~* B* P$ Z+ o+ L' c
}/ O0 g# F. o5 b6 B' _1 ]
for(c = 0; c < arrtbox.length; c++) {
: o4 R. }" h+ s7 p7 Avar no = new option();
4 O6 I  l- i  `no.value = arrlookup[arrtbox[c]];
, j; p/ ?* P5 N! P' tno.text = arrtbox[c];  J* \% N: A9 |; W7 I$ ]' A/ P
tbox[c] = no;
0 ^6 I+ Q8 q/ h   }
' e  Y, b- J# f$ y! Y4 }) C' G4 l}) {  k( K' b, L# `) X3 ]- u. _
</script>
9 r! F  d1 c3 J; r</body>
; N( A$ s( y$ a* r1 x

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