返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"3 i: i6 J% R5 g3 `' b) \
         c pageencoding="gb2312"" ?* @% U9 d3 ~& L  A
%>/ Z% N" U$ S4 s& _$ y4 I, k; p2 i, {
<style>2 i( f! p: J- V0 y& V
.f9{ font-size:9pt; }' q' _- h$ U+ v' [. @0 [- v$ o
.bgc{ background-color:#aecaf9; color: #0033ff }$ ~1 ^, d3 d+ y& P
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;0 }: d2 `( c, M7 Q! ]
  border-bottom: solid 1px #4e7dc1;2 V& R* Z  i; z9 b' q8 l7 H) ~
  border-left: solid 1px #aecaf9;
/ _2 r+ \, i" q! }. q  border-right: solid 1px #5679bd;$ N5 S/ w$ F3 E% J
  padding:1px;
' P1 V& a8 ~# q9 F7 A  margin:0px;}. w* H  X! f. k0 J, ?- m
</style>
( e8 A* \+ X% l+ _  h( m. f<script language="javascript">
4 y" O9 K# @+ E5 q<!--
( c3 V* A* O4 ~/ Ifunction rv()* t. f: Q. G( U3 y2 y. q; @
{% a$ W5 d  {8 S7 s
  var val="";# ?( G" H/ }8 g3 W
  for(i=0;i<combo_box.list2.length;i++){, [* H. a% j) J9 }& v% x: M7 z8 u1 U
   val+=","+combo_box.list2.value;
/ S  M1 \5 B9 e2 U5 S  }
" o* b3 E- V( J; s6 f8 R" J1 k  if(val.charat(0)==","){  U0 o% I, {# r0 x
   val=val.substr(1,val.length);
& P  m8 ]. B5 _) g& S8 C" q  }
7 X$ Y2 Q$ l& j4 Y4 [! y7 Q" m& P, J  opener.form1.frecname.value=val;
* Y8 F( s. m. j# ~4 }  self.close();* s1 F% Y/ g2 [9 k, V
}
' T/ L7 g. P7 R! @' v//--># S  Z& W/ a% T; g
</script>
2 t+ f$ j) a  n) s3 a6 A$ p<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
) [" P8 O) D6 |4 j' p) r<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
; C) U6 L7 h" E: L& q7 B1 ~0 ]- U<%! c) V/ Y! Z: R' z
  cdatasource ds=new cdatasource();  //数据联结bean实例
$ m7 ^/ g1 O9 M- s' C  java.sql.connection conn=ds.getconnection();
/ _3 O3 l/ W8 X  a! X  java.sql.statement stmt=null;5 N' R8 u+ V, i* E5 U7 `
  java.sql.resultset rs=null;
( p  R# M. c! p0 D- @  cdatacheck dc=new cdatacheck();
) C% E: @, y( e# B- {%>/ s( ~% }& \$ n
<%$ C& |- \$ o0 c$ _9 s
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";
* T$ J6 N; w5 y4 estmt=conn.createstatement();
0 Y' r4 }1 U& ers=stmt.executequery(sqlu);
& S( J& \9 K6 B1 `% `! g%>
, O: i7 D* }" Y% m) Y3 U<script language='javascript'>) y- P4 I2 l* J2 A
arr = new array();
, Q( Z( i& v8 X! i: R7 T<%  int temp=0;4 G, d9 R0 D9 J% j! [
while(rs.next())
$ B# L* ?& }' |0 c{
' A* b9 V6 }$ ~" }9 f%>
! f- _+ C2 k0 S, q8 u5 yarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");' Y! W# [+ D8 D7 B' F  t* W# _
<%2 h* l" d; n4 J& i# Z4 \4 H, u
temp = temp + 1;
6 t2 F) ^7 e& r( V$ l}% Z4 ?/ J1 G5 b9 ^
%>
7 \  {& `0 T0 G5 A1 N' X8 @( I$ mtemp=<%=temp%>;; ~: J( w8 u. }' X% E
function changelocation(id){ ! E5 `, `$ M, |9 {7 L6 M7 h
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 ! ^4 r4 A" |. y; M
var i = 0; ' ~2 e2 I; G0 Q- E
document.combo_box.city.options[0]=new option('-------',''); 3 D% \+ L8 R, {7 k( _4 U& C. \
for(i=0;i<temp;i++){ 6 R7 e' X- D5 x' F
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
3 \" ?/ ]* u% ^. Zdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); + {% y7 ^! g; b7 O; V4 W
} # U1 _2 ]4 J3 p% V9 N/ {
}
2 f$ l& W# l6 s9 |9 S  G4 f6 S$ e} ! E4 B! [  ?7 D8 v- o
</script>
  e4 B2 k% W( ^  C3 R2 {
6 i+ b) m% u7 U: c<form name="combo_box">
1 p2 Q: l) y- G$ X0 F<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">. a. g% G/ ]5 y
  <tr height="24">9 \1 G" n7 l/ a1 u  i. O$ o, S
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
3 _( r- J* M. J9 R* E' A    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
2 o! F; c% g% M$ K6 D    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>. M3 ~# S) [& a8 z
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>! q" W- w% R$ w: x7 F
  </tr>
- T5 p8 d; ~7 D: u( z  <tr>
8 c5 O1 b& ~7 l) c    <td>- c4 S/ c( o! n
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
4 `( y* ~: I% {' G4 {  <option value="0">请选择部门 ---></option>
# F7 c  X" x8 f3 _* g<%. a& M* `, t( w0 c* G
    string sqld="select * from tdept";) c/ K* a6 g7 A6 z
stmt=conn.createstatement();
9 ^4 @5 x7 g, Crs=stmt.executequery(sqld);6 T( }& }* o/ |: D1 b4 ^  M
while(rs.next())2 `% r7 i  ]/ ]9 b8 h7 c4 @
{; `( J; p" z6 p' I
%>
' o7 Y8 I0 k/ g- T% Y- `- c  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
. q8 {4 f' `  C1 P' w, O% s, X<%  z  X. J: `, n; K, a
}
( j( w6 s8 n% |3 @, n( E%>
3 ?6 N- m- {: F! s7 E9 }  </select>
6 g! e( [& f% X2 v</td>+ P0 c1 U! t2 U) F: C( f$ `5 f! G: x
    <td>9 a6 g2 H7 P+ S  t' V
  <select multiple id=city style="width:150;height:200" class="bgc">
( a) @" P8 \- g' J# I4 `  </select>
* K8 |' U* w* @- v# D6 G8 M</td>6 [6 i% H3 M6 I( v) Z) c2 R
    <td nowrap align="center" class="bgc">" _4 j7 ^! p1 b$ w# F/ B" t- X7 V3 Q
  <input type="button"  value="<<" class="buttons">
; }8 \* H# V6 A# U) O4 o" k  <input type="button"  value=">>" class="buttons">
$ _! \: ~0 M5 S7 w; V: b; K3 `5 z</td>
2 X; a" [8 i2 \/ u    <td>
9 J2 k) e0 B4 p( ]- Y1 I& z) N% q  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
+ M4 J! O- y9 }! |3 A  </select>
( |' g5 y9 E3 F& \. E5 O. ]2 [</td>
& w4 F4 K" j  \  </tr>
9 |4 X. V  i7 K    <tr class="bgc"> , ~) v/ x" z, H- u6 p  a+ ^
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
1 h* c& X( A0 o0 S: X  </tr>7 ^$ X: @' N, r9 i9 C
</table>
$ ^5 c/ E) ]5 y) r" m* G5 T% ]</form>
  }3 T2 m! Y. }; V) M<script language="javascript">
; t: n; w2 M9 n0 u! e! v0 n//人名移动
' h5 \7 w: @- B% K' w/ ]function move(fbox, tbox) {
/ o1 X" i. c, ]var arrfbox = new array();
9 P8 H, c3 C6 D; T2 g* }5 dvar arrtbox = new array();6 t! B% H5 _6 @% W% h4 y; N$ y8 Z7 k
var arrlookup = new array();+ r) \8 n3 O8 p# B1 T
var i;
. C  V) ?2 W7 K5 c2 I5 z, dfor (i = 0; i < tbox.options.length; i++) {
2 n% I- E7 X: x4 e: F* Qarrlookup[tbox.options.text] = tbox.options.value;
4 G8 _% y3 n* Marrtbox = tbox.options.text;
# H7 v$ M! {1 X}8 g" i8 m3 N$ Q! K  }& `4 ]9 q- o; u0 h
var flength = 0;
6 H( z- u. }) s' rvar tlength = arrtbox.length;
" u; a9 C" ?7 I+ _) m, Efor(i = 0; i < fbox.options.length; i++) {: d8 N: T; y- q
arrlookup[fbox.options.text] = fbox.options.value;
3 a+ G+ S! e  ~/ D. T6 f# \if (fbox.options.selected && fbox.options.value != "") {
7 t) T4 ]  `5 k! C9 i( garrtbox[tlength] = fbox.options.text;
. t$ D, p/ |* Q- S& h# }% |& Ktlength++;
% q* D3 n* f5 ^6 {}) f( c5 m+ T$ _  J8 k& b5 D
else {
6 G. o4 ~& _  r3 [% K, \  farrfbox[flength] = fbox.options.text;
3 q5 A$ r7 ]0 R: T6 R0 \, a+ F1 @6 Aflength++;
$ H' n" X2 {0 u9 S   }4 {6 @2 E  Q; o2 F& W
}7 I  V4 n, l9 [' ~/ N0 c2 y- ~
arrfbox.sort();1 R9 X% b0 u7 v: m) |0 C9 Y0 }
arrtbox.sort();
7 J7 ]( b9 e5 [9 P  o& J9 g( f! X0 U3 m! Q( H8 N3 O3 R
fbox.length = 0;3 h1 m+ P1 v1 k
tbox.length = 0;% v: Y: I& @% B8 P% z- O2 K
var c;
( {& E; S/ s) ?9 D8 \for(c = 0; c < arrfbox.length; c++) {% K% V" `1 z; p: c
var no = new option();& ]% X: @5 ~' ^, V
no.value = arrlookup[arrfbox[c]];
3 \6 R0 a) R# J) U' \- M; k* pno.text = arrfbox[c];# l  q6 Y8 X5 A8 h, [7 g. T0 q
fbox[c] = no;
# Y& l0 W! H( H, [, H$ Y4 D}" [, Z' O- t, n" \( t. a3 A/ h8 i
for(c = 0; c < arrtbox.length; c++) {% S( h( N# u3 v2 U5 F: z6 {
var no = new option();  e- U) s8 q% z
no.value = arrlookup[arrtbox[c]];6 v, G; _& c: M) \
no.text = arrtbox[c];3 U; r( f! ^, z  s" ^  X# K. {
tbox[c] = no;
, C$ b2 Q9 G5 ?7 i- ~; h1 Z, m   }
# {- V# G4 {  U7 f* P/ W% O6 h}
& z/ b4 b& ~1 N  f' n</script>& w8 o# @7 H5 c1 R, C
</body>, O+ w" q$ x5 T( v/ b

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