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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"3 A' k  L2 U$ x+ W- m
         c pageencoding="gb2312") A) `. {1 h6 [$ Q
%>3 s5 X' z* R& b- I
<style>6 c: ?! n8 s% e$ y1 A. X- t: ?% @
.f9{ font-size:9pt; }5 q  K$ B' y" r' c! g
.bgc{ background-color:#aecaf9; color: #0033ff }
5 E7 \( \6 {  U, v* J( V3 q.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
7 D$ @8 h: n' c; Q8 L) s# u8 r0 R  border-bottom: solid 1px #4e7dc1;' x5 l1 R4 U- o( }
  border-left: solid 1px #aecaf9;
  f9 ~' X0 f7 a# b2 h. g& d  border-right: solid 1px #5679bd;% [/ j, t* d7 B* e5 ?! d
  padding:1px;
! g7 B" p5 ~" u6 C) `6 m  margin:0px;}
, ~  r3 i1 x% }% S7 r! R! @, P</style>
' A. b# T8 c% X. ^) g! w- ]<script language="javascript">
- d6 W* Y6 p! }8 n( H<!--
; j/ O$ ?7 g& r: U( F% @! Jfunction rv()' {! E( F! q) U9 ?& Q
{/ ?, \1 D2 \/ j: f) B0 |! p" h% w2 @
  var val="";
; q8 ?, V- [1 L' Y) Z1 p  for(i=0;i<combo_box.list2.length;i++){: S4 g5 D* {, U& y
   val+=","+combo_box.list2.value;
3 F9 ]7 r/ }% c. R  }
9 O. J0 f  i  I6 e# t* S( ?  if(val.charat(0)==","){
3 [) o* {& ^4 T3 |+ o* G# z   val=val.substr(1,val.length);
5 g8 [4 O& L, _  }* q  c$ t, H8 R$ W2 b( E
  opener.form1.frecname.value=val;
1 S9 a7 o% Y5 o5 E/ C, X" E5 D  self.close();$ }+ @  e* H1 F! }
}6 S* |# ~$ F3 C) a! k% l( m
//-->7 j% ?3 G) S- x$ h
</script>
% A- W8 |0 l; S4 v  Z<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">* j( z* Y, z+ l( f# N& [" j
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />7 p/ q* q8 V1 T* G/ D( w
<%* @; E9 t2 R. h. Y- T
  cdatasource ds=new cdatasource();  //数据联结bean实例. `) u, E% O) d7 W0 a6 T
  java.sql.connection conn=ds.getconnection();8 A' F6 m7 M' q- K. |0 x
  java.sql.statement stmt=null;5 |# h- i- z+ [+ `5 ^
  java.sql.resultset rs=null;. W( a: g" ?4 K* Y/ V  A& b
  cdatacheck dc=new cdatacheck();
$ [6 {' Z4 L% K  s%>% o% c% c- a# o& F8 l$ C/ Y
<%! U4 k9 o# D1 U; M/ n3 p+ Y
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";
  j6 H  @  v) o+ X: a) [stmt=conn.createstatement();( H. E5 q* V$ y
rs=stmt.executequery(sqlu);
1 J/ c( o. X/ b; E% v1 K%>* W* W+ n$ A1 S
<script language='javascript'>
+ i6 X/ S( E! g! ?. z  l, @arr = new array();) i5 X  R2 J9 A- b! O  S" l1 g
<%  int temp=0;
9 Y* I6 F( v* \, n7 L3 wwhile(rs.next())! o8 Z6 {/ x6 o) K; q. X
{0 N0 [, e0 z& G6 @: ~1 f( `9 F
%>
* T' h1 q8 ?$ S# w* }arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
! t+ N- d, G' r" {2 }% }/ K( O<%2 m% H' n8 Z1 A& S. {
temp = temp + 1;
  Y6 A" Y: l3 ?8 l7 C% r/ D}
  ^0 i  v: e8 L& i1 _& \/ c%>" r% R5 J1 m( p1 e% |4 [* }
temp=<%=temp%>;, O% O$ b" H# w6 [( O; w( r
function changelocation(id){
$ @& g; r8 ?, i$ M  Ldocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 0 f& `' C; Y* ]- e* ?9 k5 }; [7 k
var i = 0;
( W* e1 ^3 @/ N) o4 I! H" Qdocument.combo_box.city.options[0]=new option('-------','');
3 A6 m- P( J6 w. c9 ^$ T% \4 p" Zfor(i=0;i<temp;i++){
# J1 J. I9 t2 e" W1 W' ~if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] % i* W/ M5 B% G: ^+ i3 F
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); ! }, \+ W/ O+ y' x* W) D' g, l9 ?
} 7 f$ F6 X% L- v& ?$ N0 P" U8 }
} 0 b3 Q' i" S5 M  `) D# r/ L8 q
} " M3 L. u0 Y$ M) J1 ^5 g
</script>$ k$ ]+ p" w' A% M
8 b5 T. L8 j5 @5 _, H
<form name="combo_box">
6 V/ D) U1 g' c& k! A<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">; z; y- O6 o: B  _  R7 x! u
  <tr height="24">8 m& R$ ~9 O9 Q+ @
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
- O. Y1 R( E) H" n    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
- I  r0 g* g  N/ W* e# W) [9 P    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
& g4 b) w$ Z* P/ B* r% e    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>  l, v, e* m' k/ B. C
  </tr>  M) t) K; Q$ W, i- Z; j
  <tr> 6 Y; t- a' }$ H" u
    <td>
* p5 s  G* L" `+ i( @4 Q: h! u5 r  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
  o$ n8 E4 _) ]6 _, l' R/ w  <option value="0">请选择部门 ---></option>
" R3 `7 @) q% a4 A! p( Y/ ~<%+ @! n% o$ v$ k" l( {6 [
    string sqld="select * from tdept";
5 u, |2 A) |# p' i, I: rstmt=conn.createstatement();4 E# j" A0 S0 }$ R* ?1 a2 \
rs=stmt.executequery(sqld);' \" [* x  [( D1 Y. B
while(rs.next())
! k1 s2 A2 t( h5 x: s{% z9 M3 O, H4 |: K
%>+ w/ b+ y! f1 J  S# D7 d) l
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
3 x9 P. ]: c! y' U7 T<%
9 }+ |0 |' b- K6 h}
4 K, a+ `3 s0 u- D%> , j% Z4 }% H$ _, {7 C, ]; Q
  </select>
' J2 ?% d" C! P  F</td>3 l4 c% Y7 v, s& m. U) N
    <td>1 A6 }( O$ @) f. p( x5 y6 C
  <select multiple id=city style="width:150;height:200" class="bgc">, @  a' |; w5 h0 f- P1 R
  </select>% c9 M5 y  s* b* T) P. Q
</td>
+ v: ~' g- O0 u& x% E    <td nowrap align="center" class="bgc">
- q" ~! F4 \5 L0 m* i1 _  <input type="button"  value="<<" class="buttons">! ]% i0 w" z$ ~; U0 U9 P$ f( s
  <input type="button"  value=">>" class="buttons">
( @4 _0 [( I) d, C% [</td>
! E/ T2 ], V* w& \; k2 @    <td>6 m" \& y' v  X2 P3 D
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
( x! c) v( R. v0 ^) }( I2 f  </select>
$ Y& X' p+ Q0 n8 H* W</td>3 G2 H  t2 W# a
  </tr>) V2 m) Z5 v) I& W2 u& h: Y# }2 p
    <tr class="bgc">
: D& U2 K- m; \    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>% w& l/ M' b+ _9 s- \1 L
  </tr># z( M# s0 k( x" z* y1 O: c
</table>" F. j5 r) s. B, @
</form>7 S/ I7 s1 T7 G2 l
<script language="javascript">) y$ o# }( C; A" |/ U; L: l
//人名移动
8 ~& _* ~9 o' ~( J; Tfunction move(fbox, tbox) {
4 i; H+ c1 Y0 k+ }var arrfbox = new array();5 M2 @  K8 y3 C# b' w0 W
var arrtbox = new array();
3 y5 v' i5 g  W# v6 y1 Mvar arrlookup = new array();: d- |8 [: ^7 T: m. J
var i;
. i9 c; S3 B8 ffor (i = 0; i < tbox.options.length; i++) {3 q, k0 H: m4 L  X1 ~
arrlookup[tbox.options.text] = tbox.options.value;. Y" }/ ]6 Z$ o1 }; R
arrtbox = tbox.options.text;
# U; W3 x1 _$ f  B2 f9 k# [}3 z3 s- B. k0 b' m+ s5 _0 r$ G
var flength = 0;
# M; E" P* ~# A' G1 Nvar tlength = arrtbox.length;
8 q5 E6 D3 t+ c0 c6 o! qfor(i = 0; i < fbox.options.length; i++) {
( F2 j2 E) v$ U2 xarrlookup[fbox.options.text] = fbox.options.value;
8 b2 j% A0 ?# A( wif (fbox.options.selected && fbox.options.value != "") {$ N  a# G) V" T; l
arrtbox[tlength] = fbox.options.text;- F" M+ T8 @( ]
tlength++;
( F2 K% }2 @2 @$ [& j}
1 |5 _/ r) g$ Q2 U  e  j" e3 Velse {
0 R0 b: L" O- D/ `arrfbox[flength] = fbox.options.text;
/ O$ ?  v! G& F6 lflength++;2 L! s  n% {* t1 `0 h
   }
- j- n) `" a% H% e  y# R0 ]}
7 M/ V4 k5 W. |/ k- Y# h4 parrfbox.sort();
# T+ ?9 J: Q. l% O9 U/ j- ]# _arrtbox.sort();
# X/ t. s$ p3 i8 j0 L
- c3 {  [3 O  S! P9 c% Ffbox.length = 0;
% J" ]0 s6 f0 ?7 c  {# z& wtbox.length = 0;
1 R* Y2 P& B. N: Q2 t- p# fvar c;5 N6 a1 b. l$ @3 O
for(c = 0; c < arrfbox.length; c++) {
/ Z1 e/ k  x5 fvar no = new option();
  q) P" ]3 e6 Y, d7 c  cno.value = arrlookup[arrfbox[c]];7 I/ f1 A2 j$ T3 C* ?) o4 W) X
no.text = arrfbox[c];
- w4 \3 K' J# o4 O- I6 _7 }  Cfbox[c] = no;, n5 v' U$ V* F1 o
}
9 k3 {" r) i& X8 P/ P4 R" |for(c = 0; c < arrtbox.length; c++) {6 l1 |$ u9 V- a' G8 n
var no = new option();
- p4 |7 S. Z$ @  R8 Bno.value = arrlookup[arrtbox[c]];
, P/ S8 {: N! ?  Uno.text = arrtbox[c];! c+ s0 ]! y( c
tbox[c] = no;$ @, ^' q$ }% \; {* {3 O+ G
   }
' f5 f, m0 A& ^$ |. ?1 W}/ }$ ^4 Z/ K& i
</script>
/ k7 R9 |) w* v, J2 y3 s+ T5 N</body>% L' G, \" C" D; W: _3 X( F

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