返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
' M3 h! s1 d' |         c pageencoding="gb2312"; n+ v+ v. }, z/ X  x4 Y
%>$ T% H" |( m  L$ d3 ?) t0 Z
<style>" r# y9 Z* h  y) R) V4 o. D- S
.f9{ font-size:9pt; }
7 E' Q$ w& A9 @" R" y+ `9 P9 n.bgc{ background-color:#aecaf9; color: #0033ff }
2 e- i# q" ]$ q1 o% q- k% G.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;" Y/ x# f. Q. \9 W& e
  border-bottom: solid 1px #4e7dc1;
" s8 R! y8 w% z. M  border-left: solid 1px #aecaf9;
- b6 N7 a. E/ K" a  border-right: solid 1px #5679bd;& Q& b: L/ {3 }$ R* t; L
  padding:1px;
" p6 h6 X5 `, B1 A. Y0 `2 C" @) Y  margin:0px;}
7 _  N5 _0 L6 l" Z. Z; T% j: o</style>: m6 B3 X7 I/ B/ @* |; j
<script language="javascript">0 q8 @2 q4 ^& Z3 e
<!--- W" c3 y( X. a3 ^
function rv()/ B; ?  G4 {, N) p4 V1 |* q& M( z) M( ~
{
0 c8 r' X/ a. [! x2 P2 v: s- s  var val="";
, a) t1 x9 ]  H* }  m  r( Q( o  for(i=0;i<combo_box.list2.length;i++){5 Q5 ?, G2 X4 N" b% I- c8 r7 \
   val+=","+combo_box.list2.value;6 g4 n1 K1 k- @
  }
+ F0 _, l6 z/ ^$ b" }8 u  if(val.charat(0)==","){, R  R% ?8 H3 b% o4 c) O9 C* o0 }& @
   val=val.substr(1,val.length);
& K& G: g- ]& P, `9 C5 O+ s  }; u% J' v& J5 U; i/ u& \
  opener.form1.frecname.value=val;" N& l- n3 Y0 L( U- Q
  self.close();
7 {" M2 h' T7 G; [; l0 \}
/ I5 ?  P* F  [//-->
: c+ c6 B( p- x! t1 e9 F</script>, C& V1 x! [; Q: W
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">5 L2 B# `9 Z. L6 `1 V
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
3 o" ^' p6 f# s<%
1 a% L3 V* _/ \6 t1 |+ Y! L  cdatasource ds=new cdatasource();  //数据联结bean实例
6 S# ?- p6 Y8 O6 ?  java.sql.connection conn=ds.getconnection();
! |% x- V. F) R# e. [" k  java.sql.statement stmt=null;8 R% S- l3 Z$ [) h7 Y5 z
  java.sql.resultset rs=null;
, G: {5 }$ _. A4 l6 C2 w  cdatacheck dc=new cdatacheck();
9 ?/ J0 W; H0 ?! \  U%>
, }" O$ y* t8 {. S; H/ U  {<%! U% H: d  h- c, Y# f( {& k
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";
& ]/ f- D% L% B. r" Astmt=conn.createstatement();
. M0 B& ~8 ~; X( F2 X3 Urs=stmt.executequery(sqlu);: e( w) Q4 \) ]" D& I* j! S+ C/ ~' d
%>+ g: G* n2 R9 e% `7 ]
<script language='javascript'>4 h9 T. `8 g/ {  n9 q, @% X7 G
arr = new array();9 o7 P  v) @! ?7 `9 \8 d
<%  int temp=0;7 V3 U6 N# J7 O" {6 w$ Z
while(rs.next())1 a3 N5 r; }% }6 q/ ]0 [6 o5 u
{
# L8 |" r" r# Z& {0 U4 ~- @%>1 |& E; p; n+ I# y- `* w
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
) f! t6 @' G( p# r6 l! X0 c<%
$ w/ d! u& e- R. p+ F3 etemp = temp + 1;/ Y9 X! I5 G; L/ b0 o
}4 n% O: ]5 H9 Z  }# z, a
%>; U! s1 U) d. s. y: U
temp=<%=temp%>;
2 x1 r! v- E4 P( `: r% m! {function changelocation(id){
* D2 g1 `# {" v7 T" `; Kdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 $ b. F" g8 h9 o& K7 {$ U4 N
var i = 0;
# Y. o# L3 Y4 Sdocument.combo_box.city.options[0]=new option('-------','');
# {. y* x: D) L  n' pfor(i=0;i<temp;i++){
* d; N, U- P9 e, V3 z: Dif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] . S* i7 L+ Z# }% m8 v% S0 J; c
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 0 K, x6 \+ \0 U7 c7 B
} ( n1 ]: f+ R  h
}
; E: L, ?/ x1 |; m} ( d1 N$ H# a# w' S. R3 a
</script>3 o/ u2 \3 ~+ Y9 F& p
* I' g+ T( z% E( Z
<form name="combo_box">3 _+ \, u( E+ X
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
7 J) l0 x$ ~" P  <tr height="24">) ^! B! |$ i1 Z* `& H9 Z8 Y6 b+ [
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>. o, R  `5 L5 Z( g5 o/ l! ?* t  M9 @
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
+ A% w/ z8 T& q% @6 I# q    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>( T% S% _) ]; W7 z/ {
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>  Q$ {2 p$ {7 [" ^: g# _2 A8 Z
  </tr>
! u2 M. z! Q2 m5 C1 ~- `  <tr> : B4 z; S6 y' \8 r( t! `2 }6 k
    <td>) L8 o7 \' E% a1 K- n8 T3 ^
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">0 A1 Y$ m- G" B
  <option value="0">请选择部门 ---></option>
, A- S; G6 K7 B/ n<%
/ P- Z# @5 G6 x4 d0 `- b( Z2 U    string sqld="select * from tdept";, ^3 p6 e8 G0 V- `4 ?8 j
stmt=conn.createstatement();
3 r. v* A% q$ u+ a4 L) Ors=stmt.executequery(sqld);
5 F+ |5 v" q+ s: [, pwhile(rs.next())3 U! J% n5 R4 ~% S
{
% ^$ ?$ i# \+ W. q%>
  @6 z% ?6 W# C3 j  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
, Y) @+ f; M5 E8 x( f6 d<%
% r# p/ n+ W7 h& o. @: {, H; \! b}
, @9 U2 P0 k. N; p%>
8 \7 c4 `) X/ M8 T6 I  </select>
1 f+ ^* Y% {9 M</td>0 X( f1 ]8 v3 X) g# g3 B) d
    <td>% q( d7 P, @/ a& S
  <select multiple id=city style="width:150;height:200" class="bgc">
( h* X4 c2 |! ~& W, A, k4 H4 L( Z  </select>! ?3 I# I" T3 C, p+ T" R
</td>* u4 p" _- A6 m% P7 h$ o/ S" ^3 ?  H
    <td nowrap align="center" class="bgc">
( g* z4 g- o$ _) d6 Z/ N+ z( }9 {) w9 X  <input type="button"  value="<<" class="buttons">3 c2 _' n3 W# G( Q6 Z
  <input type="button"  value=">>" class="buttons">
6 V# I' d1 A* K3 Y, M$ T</td>
5 ~5 B3 o  y4 u' M, T    <td>
, j: t9 n( J* I4 d$ t. ^  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
8 ~2 U( m  `+ b( x4 h7 q+ T  </select>
4 c8 L( ^5 Y! h) }/ K, q+ q+ `</td>
8 c2 t% J9 D1 ?( w- Y  </tr>! A: Q! J+ T* ~/ Z+ s$ L
    <tr class="bgc"> ) }! p) U; j8 E& S3 N8 F0 b
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
/ u$ z. _. D9 x$ f. m. ?9 i  </tr>
8 n7 z+ v; ~  V( G, X. K</table>+ @6 S6 x$ v3 [( K
</form>, c7 p- m0 `" u8 p$ q
<script language="javascript">
$ z- o( D( f. s# B$ r7 Q7 O//人名移动+ s0 c% }8 U" m3 T
function move(fbox, tbox) {2 W$ P6 h6 a; R: u% t; ^
var arrfbox = new array();* G, Z0 P, J  H' n
var arrtbox = new array();
! m5 j7 q  a2 J& M( ?, avar arrlookup = new array();
: l6 h  X. }& o$ F: {var i;% W. |* x* a' L% j
for (i = 0; i < tbox.options.length; i++) {
% k& Z" {8 O, [- v3 f, J$ Larrlookup[tbox.options.text] = tbox.options.value;/ b0 n" `% {5 I" @4 J6 f* i
arrtbox = tbox.options.text;* P& R# g6 I' [& I) ~
}
3 f* ^! H7 |" x3 y2 tvar flength = 0;
& t3 j/ {* \+ n8 Q! x) H3 F: jvar tlength = arrtbox.length;  Q2 I5 r# s. \) x
for(i = 0; i < fbox.options.length; i++) {
. A8 S1 j! H. Y, m! Darrlookup[fbox.options.text] = fbox.options.value;6 M7 g  I2 t: B; Y: W
if (fbox.options.selected && fbox.options.value != "") {7 t  ]5 h" I# ^
arrtbox[tlength] = fbox.options.text;  w3 e$ O. v$ F: d( }2 l9 v
tlength++;7 o: p2 v  a) w, H8 T  H2 Z) L4 v
}$ a# O$ I; j" C
else {
# g$ Q: Q/ H! a/ karrfbox[flength] = fbox.options.text;
4 Q( o/ q6 v9 v8 D% t2 ?* tflength++;. H2 S$ J8 ?: o. a
   }/ X7 R4 o0 D7 ~4 u% x9 E
}3 b7 K, a8 [5 V6 L' @5 z/ |: p" F6 ]
arrfbox.sort();
& i0 E: I. L  U  t. w* A$ Xarrtbox.sort();
+ O+ f. {9 i1 ^' _5 H1 i$ A
8 J+ `1 `: D/ gfbox.length = 0;
* x7 x$ D. f  u, Ytbox.length = 0;1 j2 a- ~1 P' k" C
var c;: O" K& p) R9 |2 `  ^
for(c = 0; c < arrfbox.length; c++) {7 Q: A  P5 w( b1 Z
var no = new option();
5 w& r, c' `( Pno.value = arrlookup[arrfbox[c]];; C1 A) G" l7 x% P
no.text = arrfbox[c];5 U7 u9 t9 ?) T3 \* G  b" o
fbox[c] = no;
; j* m- m0 ?: T( I}
( X# l, x' B" p+ K1 f1 Wfor(c = 0; c < arrtbox.length; c++) {7 i2 w! \0 L3 J3 `; {
var no = new option();: P2 {$ l, n" Q
no.value = arrlookup[arrtbox[c]];( c6 }2 {, X# g% a1 i$ \$ j
no.text = arrtbox[c];
( r7 @+ z/ P3 i+ c) Y2 Ktbox[c] = no;
3 a% s2 {) T+ ^   }
1 f8 M9 k+ O# T* A& n, i}
  w0 u9 ]& Y% W. X  ^4 s</script>& S) E2 u; T3 A1 W8 ]8 M/ ]
</body>
" E5 G3 p; j9 u: J

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