获得本站免费赞助空间请点这里
返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"/ c5 M- M7 {) n6 e7 U
         c pageencoding="gb2312"$ p' B9 l6 f9 F- l3 h8 V& K  `7 {
%>
  D: K1 W# K$ t6 D, z<style>
8 Z! @8 R; u0 f* c' Y/ t1 |1 T.f9{ font-size:9pt; }
, p6 ^2 V: X0 w: S.bgc{ background-color:#aecaf9; color: #0033ff }9 R6 n1 [/ J7 @$ Q; L; k
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;$ K- X$ x2 x0 a7 x+ ?) \  V/ D5 X
  border-bottom: solid 1px #4e7dc1;, E7 p; K+ Q) C4 m8 ?: ~" w! m# Y, Z
  border-left: solid 1px #aecaf9;
' B0 H8 ]1 e1 k7 v; G9 k3 D/ n2 B  border-right: solid 1px #5679bd;
1 F- t1 h# }8 f# F  padding:1px;$ _5 C' Z( e8 v
  margin:0px;}
! z" o+ e. L, i# r" L</style>
% t; E. d% h  e2 e0 \) h<script language="javascript">
6 T6 x+ E/ p4 e( ]! }. U. [<!--1 l* \& K; W' a# y4 H4 Z3 N
function rv()9 H5 I9 J) x" o
{
0 w4 K/ |' F; F0 R$ F  var val="";
1 o& `9 s- l# V# k; j  for(i=0;i<combo_box.list2.length;i++){
/ h" ]" W2 l' T( N: Z' i, V   val+=","+combo_box.list2.value;
1 s; J$ W3 I% k! E6 H! G  }6 g9 _, d6 c1 u( @/ [2 p' Z
  if(val.charat(0)==","){
7 s( p: a8 V4 ~9 g2 p   val=val.substr(1,val.length);- U. j; q( H# N8 q
  }! m7 T+ m3 M9 c& k, ^; i, G
  opener.form1.frecname.value=val;
1 r& f7 h# @" F. L: J* }  self.close();
, {. V' {4 H) L}
# J- Y. y/ T* u3 @0 t  Q//-->
1 S, Q: K$ p5 Z</script>' _0 }2 E4 ]- y- A( w
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">3 w( t* l8 L4 S9 V7 _# r
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
( m! K! P0 J8 X. U3 m6 P<%& k& L! W8 V& W
  cdatasource ds=new cdatasource();  //数据联结bean实例
7 ^1 S, @; K! J+ ~  java.sql.connection conn=ds.getconnection();
# G, R1 R4 }7 {  java.sql.statement stmt=null;/ G. W& ^+ u8 D! R; x
  java.sql.resultset rs=null;. F# X3 m$ H3 @# m
  cdatacheck dc=new cdatacheck();4 `' K/ [1 s' o$ I) e' `% \! P: u
%>! N+ I) F8 H/ u/ d
<%' ^: r* ?2 y) B. P' X
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";
) D1 a8 M* q/ ystmt=conn.createstatement();
! Q+ U, [# x$ K; J: O1 q  Wrs=stmt.executequery(sqlu);
/ D7 q8 W, @+ J, D  S, G%>& @4 Z4 [# v- F+ y
<script language='javascript'>
9 ^2 g( b+ @3 E# I+ ^# Oarr = new array();6 o0 r% L0 N- `! F4 E2 o
<%  int temp=0;1 w1 Z7 L7 \- l" }3 b
while(rs.next())8 L) M& m  c7 m2 q- r
{
% ?3 t9 u7 s2 \* }/ A8 m%>  l4 J1 I$ r  b+ m
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
$ p: S' p- r. W* m6 N/ z<%
$ B: E' l8 K( @+ Jtemp = temp + 1;
) S/ V$ O9 w/ i/ K' U( H}
  b5 v0 ~8 p! P( R% P5 g1 t5 B%>4 }3 D4 }2 o; t6 X0 a7 U
temp=<%=temp%>;! M& p! z% I& k
function changelocation(id){ & W* U7 {5 ^2 ]1 j; J. V/ ~
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 9 T  p2 o, d2 R1 ]+ G
var i = 0; & N' S7 Z. y5 c+ `$ B
document.combo_box.city.options[0]=new option('-------','');
" W7 d5 M9 v, I, B2 {9 C% y; T" hfor(i=0;i<temp;i++){
' O, A5 u1 M. V, u2 |7 Aif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 7 h# q" d8 O" t# b5 _, E! B4 ?
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); - x3 E6 R6 s7 h
} ; d& `; {, P( }0 k0 C4 |
}
, d! m% _. {* R$ i5 E0 P/ N( V" E* I}
, `4 N- J2 W4 i# \3 T! i</script>
$ t+ I; L4 x( u1 J4 ]
1 K+ _8 ]- N7 s) o<form name="combo_box">  R/ j" u# L( ^5 n
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59"># \0 e& i$ d7 X5 V: g3 r  j
  <tr height="24">* F6 C/ m. Z% z, u, \* U
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
+ {, K4 }7 u1 t* R1 H3 Y    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>6 \- |- V0 e6 x) ^4 b
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
% S6 w# D& ?) o2 h" m& r4 E8 O    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
) u8 Q4 G1 ]5 N  </tr>* W- @$ ~% L+ S& F7 p+ a- e
  <tr> 9 B5 @$ k& e7 o4 m. h" Z$ D
    <td>
1 B6 M% Y9 i4 `5 K/ b  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">+ R$ O8 G4 [( G1 p2 W
  <option value="0">请选择部门 ---></option>4 J( o( a) x7 \" O
<%& ]3 J7 H  |4 r+ w( V
    string sqld="select * from tdept";7 l+ Q* G* m+ u3 n8 [# |- a8 P
stmt=conn.createstatement();5 M, M  L$ c- M) C" P! y7 c3 R
rs=stmt.executequery(sqld);: b0 c" e; e1 n. k
while(rs.next())
3 J$ S( W" f* ?9 w) y" p# S9 Y{
' Z9 d3 `, m  Y! m+ O/ D; H%>* ^2 H% r0 ~  s: y, k
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
& ^* P6 h  j+ u% X  U/ l<%
" A$ H4 S4 |0 c3 Y) G4 k' H}
, a# p' N' t! G( f% `% x%> + |6 V, v0 \" S* x0 y7 i$ d$ E
  </select>4 x( c, \( `: p# q; A; |
</td>
# p6 V; ?$ @2 l0 p    <td>; m* Z2 W) v, ^1 K. {
  <select multiple id=city style="width:150;height:200" class="bgc">
$ g, p0 e5 X, N( C6 B" e/ T  </select>" O: A* J6 t! g
</td>; x* x4 R8 D' j& x' N0 X% g
    <td nowrap align="center" class="bgc">0 b2 P, i$ g1 x$ {
  <input type="button"  value="<<" class="buttons">
- t; m; S/ ?& O  <input type="button"  value=">>" class="buttons">
+ e5 e% A- v4 r. F1 r4 h0 W</td>4 u6 L7 @# T: z1 A! s  I3 j$ ~
    <td>
0 H6 L9 b# q6 ^- Q% Q  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
" f* T0 T# _/ O- s1 W3 C+ R  </select>
" @. A9 A- M) P4 v+ M</td>- p0 B4 S$ y) U8 U  t5 f* ~5 l
  </tr>
' K3 S. H  P, L+ M( E    <tr class="bgc"> # @0 V! e/ o& Y9 ]5 Z$ }' q
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>) \" }- v  E' u' S" l3 s" G
  </tr>; l, }, b3 n" l. T" c3 G
</table>& ^! N& f  ~8 |$ u( C
</form>
+ I2 w; o* X' [7 N<script language="javascript">  v2 Z- |4 ?9 d( F3 |! t
//人名移动, Y/ ^1 O- v9 W$ A; I2 _
function move(fbox, tbox) {" F/ @/ K/ \- S* R: ]! ?5 a
var arrfbox = new array();9 B* j3 h" M. }" q
var arrtbox = new array();
+ b+ n/ t" c* p  Dvar arrlookup = new array();
* }) c0 r3 M  K! _; o- Nvar i;
, p( E: B- n0 h/ {0 ]& y6 Hfor (i = 0; i < tbox.options.length; i++) {: y1 K1 e! o* m' Y$ }0 Q
arrlookup[tbox.options.text] = tbox.options.value;$ e* G, \0 a. ?1 h
arrtbox = tbox.options.text;: y2 F" H% k% F; B
}5 y% B+ V, R- Q% R; t0 g
var flength = 0;
4 |: r  F8 K: m6 R" A! |var tlength = arrtbox.length;  B5 M7 |, x' x
for(i = 0; i < fbox.options.length; i++) {
+ S$ `5 ?4 I% C  C& s+ P& U8 R8 karrlookup[fbox.options.text] = fbox.options.value;8 j. |& `* g7 r6 I9 x* n
if (fbox.options.selected && fbox.options.value != "") {' @3 w2 j0 Z5 i; w& _, \8 ^3 ^
arrtbox[tlength] = fbox.options.text;
- n3 j; G: u0 b4 V  M9 {. @- ]tlength++;2 e1 n3 a! y0 I/ z, V
}$ G& ^. m: o# t; _$ F( z- K
else {
5 M- C$ l. ]# z9 x3 warrfbox[flength] = fbox.options.text;
$ C% d- D7 ?/ m4 T2 \+ l: eflength++;6 B5 c8 Q+ k* r$ P8 r8 m
   }" }6 j4 A. w# w! G! Q0 M* u
}( @' d8 m8 c4 }( o4 Q
arrfbox.sort();6 |  S0 L9 r: H* P+ L
arrtbox.sort();
# G- b; s+ v4 G1 O  B
) `- G5 t( D! T& z4 x" ?* mfbox.length = 0;
" D6 N+ P% _, j7 S$ Ntbox.length = 0;/ L4 ^( D( F9 W* ^
var c;  G, l' m. Q8 k5 g/ U7 W& N
for(c = 0; c < arrfbox.length; c++) {
" T3 I6 g. g8 Qvar no = new option();
2 b0 D" K% n4 Z! V; N- Nno.value = arrlookup[arrfbox[c]];
5 V. S8 i9 d: u& m1 h/ Jno.text = arrfbox[c];7 y( s4 x! t& K0 d% X# B6 U  _
fbox[c] = no;
2 s7 I" n* P' S}
3 P: D, h& b3 A. Ffor(c = 0; c < arrtbox.length; c++) {' Y% K! k2 R3 w5 i! Z
var no = new option();
6 j, T3 p, y+ j* N- U- Lno.value = arrlookup[arrtbox[c]];- {3 P: U4 o3 s6 t
no.text = arrtbox[c];! ^4 t' [2 p3 c- C7 u; O4 I
tbox[c] = no;; E- m7 L2 @, q, `& L0 d
   }1 `7 q9 t; K4 \& b1 `, L1 X
}
% e0 G) h8 Q" @6 t% r9 Z' b7 F' ]</script>9 ?2 H  h. n0 v# p/ Q3 N1 }/ k
</body>
) |+ E4 c4 F6 t2 o9 @! g( U

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