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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
8 `$ \7 z& P; {2 I         c pageencoding="gb2312"
$ U1 f" H3 f* v: S. G%>
8 J3 k2 U7 {9 C, j<style>
% K8 K& S  _1 J$ r/ }' C% ?  c, A.f9{ font-size:9pt; }
$ I1 P8 S" n2 P# `6 P.bgc{ background-color:#aecaf9; color: #0033ff }/ N- S: t  b: Z$ X* P9 o# m
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;+ ?" r& ]2 I7 y- K2 i& X
  border-bottom: solid 1px #4e7dc1;  J! h7 K$ M% y4 x
  border-left: solid 1px #aecaf9;, e9 S) t1 }8 N  r+ G. G$ {$ c
  border-right: solid 1px #5679bd;, D6 D. X! t6 W; Y+ r
  padding:1px;  q/ J( m: E% p0 g0 A& q" ]; H
  margin:0px;}
; V. ^0 X7 f* Q( ], J: x$ J</style>9 v3 K" ~2 r' Y5 O) u4 q3 K
<script language="javascript">
1 p2 b- J5 Y/ H- B7 P<!--' W. V* p, P8 ?1 K- ~0 \- U
function rv()
+ }" ?1 {1 H  v6 R& y{
+ u5 f6 ^- Z1 v1 V  var val="";
) L* _  v7 j8 V) o' _  for(i=0;i<combo_box.list2.length;i++){* j1 g+ {% s6 z" q
   val+=","+combo_box.list2.value;) r: X% l* N6 |  ?1 c
  }* p* E" G# M3 E, h6 O
  if(val.charat(0)==","){
, X6 E* D2 R& u5 |4 K$ A   val=val.substr(1,val.length);
% V) f0 G1 D  I% O  z6 _  }( N% E# x) P# D  k
  opener.form1.frecname.value=val;
7 p& u( t$ ^. L: b  self.close();
. E% y4 e3 K, n; }6 |% U& f$ e, k}
( ?+ M) v) x# u1 r( \//-->
+ v5 L! \+ n+ z; ?7 b</script>+ x- L/ L/ l8 ^) X
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">$ _8 X! ~2 G/ ~, L4 {" l1 K5 u% s
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />% ]- T+ Z$ A2 M; j3 P
<%) d$ K0 i( {7 D  n; U9 E( n; u9 S
  cdatasource ds=new cdatasource();  //数据联结bean实例% W8 _: h8 l. u
  java.sql.connection conn=ds.getconnection();2 S" X& q9 V  h7 r6 `0 c
  java.sql.statement stmt=null;& y( v6 }) @1 V8 W7 Q
  java.sql.resultset rs=null;# j/ \  s* ?. N' v% R4 S
  cdatacheck dc=new cdatacheck();
, {( `8 B+ [5 c% H5 I%>9 U2 f. U! j/ c2 N4 o1 @2 O
<%  `  M: E3 w4 e# y( e/ o2 f
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";
% c: Q: b" ~: Hstmt=conn.createstatement();
, T  u  e$ G6 c  n$ Ars=stmt.executequery(sqlu);
: S) g& w2 ]2 A0 y1 W0 ]%>
5 I) A5 U5 _* E( }1 N& j5 `<script language='javascript'># o8 U5 `' {1 s# h- F
arr = new array();
7 i0 c. `& j8 k<%  int temp=0;' o1 r3 a: o7 U' F8 b* _
while(rs.next())& C' e: j4 r& I/ U* d
{7 U/ g) H$ X6 ?: P- l
%>
, `' d  E0 [' y2 tarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");) b, e4 L. Q) {! w
<%/ Y  d7 J) I1 D0 N
temp = temp + 1;5 i4 m2 Y9 R/ B. q' d; G1 c
}
! x, f6 f) @2 Z* m2 I+ {6 f%>5 R  \& F8 v* w+ K
temp=<%=temp%>;
4 Q# g7 N9 N0 e2 Q0 [- }( \8 Tfunction changelocation(id){
9 `' c: Y' Y% r: u4 v% D5 Bdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 . h; W5 Q( b& Y+ S
var i = 0; 2 n. D9 [1 m0 h: C  ]
document.combo_box.city.options[0]=new option('-------','');   |! k% z0 c2 d- g3 v3 ^  I
for(i=0;i<temp;i++){
/ G- V5 y5 \, H# dif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
7 w7 T4 @( K" T8 a7 S6 Pdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
' v2 Q+ l9 w% S}
, _, e" ~4 x& |* J" U$ X}
- j! c. S$ F) a4 k# b5 _} ; e0 H" G" g# z8 n4 ~4 o, f6 ]: y
</script># [. k$ s1 l1 }7 U; L: p
% L: d, X: ?  B. J# ~: D. [
<form name="combo_box">
& S" B+ Z$ P+ D, ~, i<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
0 u- U) @& U/ V3 v  <tr height="24">
% z0 l3 B8 [$ E! t% V    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>7 ^9 M1 b0 A( d; d2 O' a+ b
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
# U' K0 _: i7 h, h1 s% \! Q, ]    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
+ Z5 |; x4 x, {9 t    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>/ v7 k" c' S/ o& t! C
  </tr>: T; n+ L4 Y4 E  J
  <tr> ; Z. }2 T% Q- o
    <td>% F% B4 K. T6 w* s7 S2 \
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">" P. N5 B8 R2 [& g
  <option value="0">请选择部门 ---></option>& c3 w( U( V$ e: a7 n
<%4 K% m$ _, f" `1 H8 {7 k* J& @6 e& N5 X
    string sqld="select * from tdept";4 I* K+ a/ ^- Q2 D
stmt=conn.createstatement();
8 y* Q: g9 y! X5 i$ h2 S# j+ ors=stmt.executequery(sqld);: U" g1 |9 \5 b
while(rs.next())7 a# i! \4 d; k; Y: b4 w% Y: k
{, \& v1 f8 E& @* d2 `
%>$ o3 }1 O6 c: L
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>( j: m1 W( R; a& w$ B$ f
<%* b" |0 ?" O6 o
}4 Z- C( U" o) b6 `# [7 a
%>
% ~. s& n6 S) h5 q+ x  </select>1 G3 x% {9 t" U5 W% M9 `) D8 J
</td>1 I  N/ a; I- s4 y# z: x$ h2 X
    <td>
% o3 _4 A1 e: I* P& X4 R  <select multiple id=city style="width:150;height:200" class="bgc">
6 I3 `" H6 A7 h" B% u& t8 r  </select>
- R0 Z0 ~7 O- r/ v</td>
9 w1 ]  A0 T8 f8 w2 i! a    <td nowrap align="center" class="bgc">% |9 O3 ~: \' v' ^% ~; k: t) I! S
  <input type="button"  value="<<" class="buttons">. }- V% x# i- f# }
  <input type="button"  value=">>" class="buttons">
% H, ~- b1 D( U</td>, G3 z+ j" x0 K5 K0 j5 f5 p
    <td>
. ^& i: b( O% w3 X  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">, l/ _  r& H) m9 U. F  ]  n- O
  </select>
# J  @; [$ P$ [/ T0 R; D5 [2 D" Z& P</td>
& z) s$ F6 v& I  C' }( q( L  </tr>6 r7 Z2 s$ r. K0 Z7 r# v5 h9 o3 b
    <tr class="bgc">
! ~( v5 D4 ?$ w" \- F; k2 Q5 Q1 g    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>4 L+ |" f9 p' H& ?
  </tr>
' c. l+ u! ]) z: T  \</table>6 L2 a( P* l6 E0 H, N
</form>
  M, G- e& b$ ?+ |  `<script language="javascript">6 j- m& \. h) M. T& w7 w8 ?# }* t
//人名移动, F* g/ J. t* B6 p1 G
function move(fbox, tbox) {5 d$ |0 |# N" c+ T$ ?
var arrfbox = new array();  f" l; g: I1 }) a6 Q! d
var arrtbox = new array();
4 h" W* n- l  Y) y+ z: E3 lvar arrlookup = new array();
# T9 x% N% O+ z: C/ Pvar i;
$ Z5 s9 w! r; {! D$ C+ Efor (i = 0; i < tbox.options.length; i++) {: {. F% U# g$ ~" x9 M. _; w9 i% d
arrlookup[tbox.options.text] = tbox.options.value;% L, C1 _+ [6 ?+ @& c; ]; e
arrtbox = tbox.options.text;) Q( _& z  {) T
}
8 J; ^" u+ ]6 N% Pvar flength = 0;
3 Q( B1 w5 [+ {+ Wvar tlength = arrtbox.length;
  `1 E0 ?1 N( ]* Sfor(i = 0; i < fbox.options.length; i++) {
0 y& E( V( P9 h, v4 V/ R* H. l& narrlookup[fbox.options.text] = fbox.options.value;
( C. ], f5 J: t, @' i7 sif (fbox.options.selected && fbox.options.value != "") {7 X2 y. q9 D2 J5 f  c& }, r3 H
arrtbox[tlength] = fbox.options.text;
2 [; @$ \# g2 n, [1 wtlength++;$ W& s+ {6 h* X& e7 S
}
' C8 v, D( s" D0 ^& X7 ?else {
7 z  u& @: w* z4 Varrfbox[flength] = fbox.options.text;
: Q' C2 M0 C0 c5 p5 oflength++;7 Q* z% [' |4 \3 T9 {: D& j  y& E
   }
& m# o0 y) i8 F' f}
4 D$ |- u& u' ]9 S7 Y* B$ {1 K9 karrfbox.sort();
' d; s+ o* o$ D' e- E& g; oarrtbox.sort();
% r0 ~5 [3 V2 L) S  e& h. j$ z8 T8 d. ^7 ]9 q  ?
fbox.length = 0;- b) g7 k" {- j9 b- [# i' q5 D
tbox.length = 0;6 l: @1 I& d6 P) z% f7 \
var c;
3 P/ @5 G0 m6 h% l" X; Nfor(c = 0; c < arrfbox.length; c++) {
: l# c7 X5 s  }$ y( @4 \var no = new option();
' D3 n3 ]' I( U- O# Cno.value = arrlookup[arrfbox[c]];6 b4 M0 A) e; D3 u! Y: @: [
no.text = arrfbox[c];
: ]; g" u3 ~: O) I0 [fbox[c] = no;3 p) K. g7 Y# O! |1 l
}( U$ i5 W% b- Y. I' G2 X* A
for(c = 0; c < arrtbox.length; c++) {
7 h. s" q3 _6 Z7 J0 fvar no = new option();8 @& Z( R9 p% h/ a. l& T9 ~
no.value = arrlookup[arrtbox[c]];
% T8 j& J- v- m- |+ d# vno.text = arrtbox[c];3 C# t7 F! N2 O9 p
tbox[c] = no;
8 l  D) k; y1 i/ ^+ O   }; H) T) N8 X, w0 S" i; B9 q, L
}
9 B+ `$ x0 l; V) O0 u, W</script>" G; |, ?* C' G- B
</body># c0 {4 m! |7 w% L' u

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