返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"* e' w  R7 M# X0 Q
         c pageencoding="gb2312"' V! Q+ J( \; D, H, H
%>% M& c  o- k; }
<style>
) o3 A% G) `& J/ l. \.f9{ font-size:9pt; }
! @' ~, q* I8 `2 E5 ?3 {.bgc{ background-color:#aecaf9; color: #0033ff }
. F% {! v3 H# `/ M& K7 ?, v.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
2 o/ D  u4 D1 Z. R  \  c  border-bottom: solid 1px #4e7dc1;  z5 y: E) y' A% Z. L6 m3 f1 `
  border-left: solid 1px #aecaf9;
+ ?& U6 A/ q6 `3 L$ C  border-right: solid 1px #5679bd;
8 i/ O( y$ m& |4 @( i# R) \  padding:1px;
% O1 u5 ?  o! a! c; w  margin:0px;}
6 M3 t: o9 @$ @% Z+ h</style>
3 r! ]; D5 n( z# \7 n! b<script language="javascript">. P# l% b( \+ Z" a9 q
<!--
/ l, b& \# d* _4 F+ L4 L4 c( cfunction rv(). m" z% W: f" Z8 x. v
{
* O$ m; q1 s; W6 o8 O  var val="";6 J3 R; `, t( a! T
  for(i=0;i<combo_box.list2.length;i++){
3 }8 ^$ ]' R8 I% b; V+ `) s* U) P   val+=","+combo_box.list2.value;
" e0 G0 x2 y- i4 g9 {  }3 {( r" A1 q1 v- G7 X3 M: P5 H7 s
  if(val.charat(0)==","){9 |2 k- ~/ R( n- b* o
   val=val.substr(1,val.length);
) v/ U% @) W# h  B  W# P- K" Z  }6 k6 o" E% e; w9 l
  opener.form1.frecname.value=val;
! y* f, u1 R/ z% T# H5 i& x  e  self.close();
2 J5 o$ \9 D% i( Z6 l5 [}
) }: H2 M1 n$ Z+ \% @, w# k//-->
/ O3 U7 `: y0 \0 j: {3 f</script>7 k" @1 S  X" ]: A. r# W
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
1 W9 X9 T& w9 R' L<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />' o, R( A2 X8 w& p- \: J/ e* k
<%! G- M6 ]* x; S: P
  cdatasource ds=new cdatasource();  //数据联结bean实例
. ?! T* u( g, z; h1 d; P3 {  @0 a  java.sql.connection conn=ds.getconnection();
+ P- {: Z% `! `7 B3 Z; J  java.sql.statement stmt=null;
: m; T% @# k  x8 z  java.sql.resultset rs=null;, S6 `; j3 u/ n
  cdatacheck dc=new cdatacheck();: e9 a  f. S: Y
%>
( T- b- M" Q: y/ O: A! P<%
  k; _: D1 U4 p5 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";+ h+ Q* j; @5 c6 D
stmt=conn.createstatement();
; e: Z4 B  W" G2 nrs=stmt.executequery(sqlu);
, O: F8 f& l$ P" u, i( B%>
6 v% d) F; O2 x<script language='javascript'>7 v: P+ E$ o, u. p, I
arr = new array();/ k$ N3 a5 H8 H7 V8 v
<%  int temp=0;
+ j* w, {& ]0 [8 Dwhile(rs.next())9 `" ?2 S8 ^! [* U- V- N' B
{
9 I7 s7 A5 v* G4 [% ~0 k2 E%>
* Y7 B! z2 _5 \arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
' s' X, y- I8 d. H<%1 p: [6 b8 N* C" C+ y$ Q
temp = temp + 1;
3 O9 ]2 q/ u1 D  }  x}3 F: k% a: I* y6 \; `9 L  Q" h
%>
7 w3 ]% ]  y+ p( k3 T  N' a8 Etemp=<%=temp%>;( F4 Z0 b/ z& ]9 e: c& C  P
function changelocation(id){
7 i2 A1 W" T6 }4 g9 wdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 ! R% N9 C: I; C0 ?: F% |
var i = 0; . ?+ S3 ]" E7 x
document.combo_box.city.options[0]=new option('-------','');
6 b4 D: O0 X+ z' kfor(i=0;i<temp;i++){
, z) _" Z- K* [) Pif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 2 }8 o9 m  w/ g6 s# F
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
+ B5 l: t5 h! l}   S- P: ?9 V  \/ T& [! q9 T# x( R4 Q
} $ T- `/ `+ z. r/ a/ Q  t& G* R
} , _  B0 D$ O- t+ i
</script>
) i' k* p* P* s4 W# x# ]3 A0 d( q6 I0 V
<form name="combo_box">8 ^1 |9 ?: Z9 g' i
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">8 Q% p5 y3 @! f; x3 J: G
  <tr height="24">
9 D* n; [7 J. ]2 T4 W5 U5 X    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
0 f$ i, ]" U& ]# S' x9 j    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>1 L' z: N1 u* ^# X
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>' w1 h. u6 C! ^0 G' P: `
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
. e* c& L9 G# z8 ~7 B* h  </tr>
  X* L! w1 i  }6 r. Q8 o+ X  <tr>
& f, D0 x( r: B9 K! G. Z    <td>2 `9 X8 z/ V9 X6 V. |# g
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">4 z- p+ d$ a% l. C) T- K
  <option value="0">请选择部门 ---></option>
% ]# H) u. N! {# G  x# p' ?3 l<%5 I/ q  u/ h5 O
    string sqld="select * from tdept";$ S) i# M& t7 E2 [  V9 f; m
stmt=conn.createstatement();
& R0 J( S  E& \7 lrs=stmt.executequery(sqld);
% K; |8 g$ M! fwhile(rs.next())
3 A7 ^# z7 ^& Q5 |- a# J' |' V{0 B8 [& v9 L& E8 O% z
%>
8 [% t( ?( {' `3 e6 K  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>) R. X/ F3 K, S" {8 _
<%
' p( |, \$ C9 D: v7 l% w}5 y" t1 D7 Z8 X: p+ I
%> 1 e! k. o4 j9 ]( ^
  </select>
. M( i% |6 J- O, t1 l0 {( D</td>$ N/ `1 w+ p; i
    <td>! P$ n5 r3 J3 Q3 J0 K( c) s, h
  <select multiple id=city style="width:150;height:200" class="bgc">, g6 z/ x' W3 g' T0 w- l- t
  </select>
: P1 c; ~" [" b</td># l( F( ^4 ]: N% s
    <td nowrap align="center" class="bgc">
5 a" b! X" ]" Z! a/ c  <input type="button"  value="<<" class="buttons">, k) o! I7 g: m" E4 n
  <input type="button"  value=">>" class="buttons"># A7 M4 Y8 S  I* Y0 e1 |
</td>
) H6 ?# H1 e  k& R# c1 ^+ e    <td>
: S. S( G7 J7 s$ j: |& J  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">, d/ [0 A- v- X3 B  i
  </select>% a* T6 j  a+ q* M, i. z, \" p4 N
</td>% J4 T, U& u0 t% A4 r) h! ~1 V
  </tr>: q( c$ R8 l; f7 D7 R0 d9 I, C) O8 \
    <tr class="bgc">
2 F: Y6 b3 O4 D0 N    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>0 C% j, y. w" ~& M
  </tr>/ M, i# H3 \8 k+ F# x# f- d
</table>
  v4 x/ f1 a% f( i: j  m  |0 x2 ?</form>0 j" P* }4 l' b& S
<script language="javascript">2 l; m$ |" E  ^; |: d: Z
//人名移动
  _; W- ^- Q4 p/ ffunction move(fbox, tbox) {
$ X" v, A1 x) y4 M( g: k/ m/ H5 Qvar arrfbox = new array();' M4 @$ C1 b% \& N' f4 b+ j. J0 ~
var arrtbox = new array();
' ^" B, D/ y$ d9 j! C1 @8 wvar arrlookup = new array();
9 t. `, D& {: T0 `var i;* o9 R5 F  d7 M( @
for (i = 0; i < tbox.options.length; i++) {
7 n: k6 @/ b% ?# o1 Parrlookup[tbox.options.text] = tbox.options.value;
9 d- J8 T" F* marrtbox = tbox.options.text;% x3 n% ~1 e: g* R! G5 c
}+ R9 v7 A5 P* |: `
var flength = 0;6 Y" O6 H+ M6 \! h( c1 v4 y
var tlength = arrtbox.length;
3 i  ?; ]9 o& @# S8 I4 W* a& mfor(i = 0; i < fbox.options.length; i++) {
- Q3 J' Q$ n4 ]- Q. _* r! parrlookup[fbox.options.text] = fbox.options.value;3 [# o, t8 h' L/ D: j; d, C. R
if (fbox.options.selected && fbox.options.value != "") {0 t3 B( g2 S  ?$ h; x
arrtbox[tlength] = fbox.options.text;/ {  ~# X4 M9 \
tlength++;
/ p* Y* a( F; ]8 j+ U}- G, a( ]# a# j! F4 O9 ^9 s
else {/ d; n/ @" Q/ n" f: W9 S% `  Y  h& C
arrfbox[flength] = fbox.options.text;
, d+ r8 J0 T' |: w1 V& E6 ~4 M4 Nflength++;; s) h  }2 `# P0 w) C/ C7 [1 C4 g
   }0 u$ z  K* q9 N" h. s6 P
}
7 v& x# g/ I: ]" ]arrfbox.sort();  J7 W/ k  Y; ^: a+ P
arrtbox.sort();
1 Y& ~, a( _, S$ v( h) p) J1 [7 G8 J' Q9 o, `  l2 L
fbox.length = 0;) `  s/ l2 f3 @+ ]0 ^. I
tbox.length = 0;$ |2 l2 P& A4 r9 @6 S' T6 G4 L7 l
var c;8 z9 t* n, K/ n  e
for(c = 0; c < arrfbox.length; c++) {
4 G+ M- X( u% v2 z, S. cvar no = new option();5 @& u: D8 C4 z5 K, J2 [* g
no.value = arrlookup[arrfbox[c]];8 p# {& z7 i6 E) ?
no.text = arrfbox[c];; q! K0 C: [0 \" n0 h( n0 W
fbox[c] = no;+ d, R1 a0 R# e" J5 o0 u/ i
}
" ]' o* F4 C3 D# J$ f# A0 Hfor(c = 0; c < arrtbox.length; c++) {! k  ^8 W1 g$ h% P2 p9 u( V9 ?" x! u
var no = new option();" h- o4 C5 G+ d5 T: \. U$ m: W
no.value = arrlookup[arrtbox[c]];1 ^, P# l4 W9 T8 X8 F) D
no.text = arrtbox[c];2 p+ h! j' C  v" K0 S, [
tbox[c] = no;
* v5 u; j7 s8 p   }/ e' H  \# l9 i  ]! @
}5 H  K3 V' d$ c" F
</script>, X8 q$ U/ p% Q
</body>
) u% ^* N+ F: X( B/ G& K2 G

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