Board logo

标题: jsp+javascript打造级连菜单 [打印本页]

作者: admin    时间: 2007-12-5 17:43     标题: jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
# Y1 T9 b3 P7 g  b         c pageencoding="gb2312"4 X4 X8 \$ G. |
%>1 d8 f( ^8 O) b$ U3 t( F
<style>
/ d; \: |0 o( ]2 G* @.f9{ font-size:9pt; }& w8 _9 N3 Y4 K& i- T/ l; F
.bgc{ background-color:#aecaf9; color: #0033ff }9 k0 |) @( _) T) w
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
. H/ D- ~' E8 e8 f4 J  border-bottom: solid 1px #4e7dc1;3 {2 w1 Q' ^' {# m: s
  border-left: solid 1px #aecaf9;/ s. j" P; |! @' s+ J
  border-right: solid 1px #5679bd;
) J9 I1 Q  ]; m' O# x& X3 s  padding:1px;
8 ^" S" `# Y. j' X% R( u  margin:0px;}
/ A% O6 t: R: s' P) u; C</style>( p) L7 _8 ?3 w9 ?! w
<script language="javascript">
+ i" S/ Z8 s) [; {; z0 }! n<!--" M3 u6 R8 D' ]8 K$ y6 C/ A
function rv()0 A" S& s7 u5 W% d9 K1 L5 a
{
- X5 s: X3 q3 E* r' p2 c  var val="";+ p* Z# y3 e9 R! i" J' e% X
  for(i=0;i<combo_box.list2.length;i++){( ~0 m) g6 j% l
   val+=","+combo_box.list2.value;' K  i. ?0 w: w/ o+ u5 z
  }
; t* b6 j( G" }& H, J9 v7 `' r  if(val.charat(0)==","){
, l: [- y  k$ ?3 f# O0 K- V) O! y   val=val.substr(1,val.length);
' A- P! N/ i! e, x5 r  a/ p5 `. E0 B  }
+ {9 ~* j, o4 X  opener.form1.frecname.value=val;
; H* t8 ]" d/ I8 P* \7 ]5 I% y  self.close();
! a1 @. }) {& c( M( A6 Z}
% @6 S/ m# y( V1 ~, h$ J5 ~, `) s//-->
+ `: r/ S8 e* j; r4 \</script>
3 ?0 A8 b! x5 c  u<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
' k! ]# x4 @: ^6 x. S7 J9 k<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
) g- l) V3 g+ ?9 i8 A<%
$ H, R, g1 P1 W- Z6 F  cdatasource ds=new cdatasource();  //数据联结bean实例
, }; \7 H0 \5 m  java.sql.connection conn=ds.getconnection();
: K" ^% p" U8 g, _  J  java.sql.statement stmt=null;  U4 n( A) I+ ~1 q& _: K7 N
  java.sql.resultset rs=null;
- r+ G0 ~: N0 a7 c: J/ z7 R0 g  cdatacheck dc=new cdatacheck();
. G( C6 u0 [6 `! Y%>  Z0 c4 m, N6 h0 D3 ]4 e# q6 P
<%
7 J, n7 x3 C- z" C4 _  Q  Y2 ystring 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";
9 G: |2 a& p" L2 A3 kstmt=conn.createstatement();
) r/ ^: a- F6 f; k& N  lrs=stmt.executequery(sqlu);
% {7 H5 P$ W, F8 E- L%>
, l5 {  [0 @1 M& p! A  n0 i% N<script language='javascript'>
, u" `; |" ?. O% f$ t/ ~' sarr = new array();4 F5 d3 l' D% L
<%  int temp=0;" G7 l7 s, K' |( d2 w& O9 ?
while(rs.next())$ ^' |' D9 E( L1 T+ m  j9 k
{# F8 I0 G! U1 s2 t
%>' V( W- s' d) W0 i
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
6 i- M7 B; H3 i& ~: M  Y9 c<%% v5 c6 U+ Q: `# j$ R
temp = temp + 1;
. f) Y: R1 @4 B}# c8 l# @8 a5 G! b) o: \9 h
%>
3 A# c' _/ {0 _1 o8 k0 J+ _temp=<%=temp%>;/ Y) O7 t% A& Z- z. i
function changelocation(id){
. O8 G& ?. Q: T' X! l* Hdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 # o; v. }, c8 V" |" M
var i = 0; + D6 G0 p" w$ g* h! w+ s
document.combo_box.city.options[0]=new option('-------','');
& |! T2 X3 E& D6 u$ L& ^for(i=0;i<temp;i++){
3 f, e7 e% Q4 |5 J' c! fif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
! j* U/ W2 F; u3 }" ?- adocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); " H- `: h7 \, |" v. ?% d( d1 ]; K- ]
}
% q: f* X% o4 u( X. I}
! k/ e# L* x% o/ o! g}
; o/ b( N  j3 a+ Z& a4 @, _</script>
; F5 q9 y+ `3 F
. Y! v8 _4 E' {3 m" v8 c$ M( v% \' S% l<form name="combo_box">+ p, N  v& T/ E+ Z1 s4 J% v3 B
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">  }! g: K1 c( D, F
  <tr height="24">
5 ~; Y$ C5 X; Z. f8 I8 E8 ]    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>2 m9 o8 r: H+ h2 @2 X) i
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
9 V6 d% p+ W# e    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
3 y( L0 I- d4 h6 _- o  V4 j    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
- l& {4 Z& w- g) g% c0 p  </tr>" Z# ?, A* ]3 T, f' H3 N& e1 c
  <tr> 4 D) m4 F4 s6 p
    <td>0 C, ?% \0 U5 c  G0 O) R' I
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
6 ]" T4 w+ z0 ?2 S9 C6 y) H  <option value="0">请选择部门 ---></option>6 n) R' E1 o1 ~0 c
<%
% l1 h  B8 [( @- \    string sqld="select * from tdept";
7 F( t9 A' T) `- B5 A+ astmt=conn.createstatement();
8 X5 _6 t/ z5 Lrs=stmt.executequery(sqld);
: u/ U1 t/ ~; ]; t# Twhile(rs.next())5 q# L: |, o( A# v- F0 l: v
{/ L$ Y) q! G* c
%>! S: [6 h9 R. p3 I1 d# R
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>+ ~2 w9 w6 n7 Q5 o3 S4 u0 d6 \
<%) a9 w  S1 m  V
}5 r' H! M7 V# ?$ K
%> 5 `% W3 g* ^6 \, N
  </select>1 z; A! Y0 o. M- [6 [3 y
</td>
, t9 h" D7 k  I( U    <td>' O( Z4 s( _  W
  <select multiple id=city style="width:150;height:200" class="bgc">) V+ m, y- l( `& P; {0 [' ^
  </select>7 p7 H; g" v" \* u) F
</td>
, B" M( B; j8 A! |    <td nowrap align="center" class="bgc">
! |* U6 a' e+ J  {, A: g  <input type="button"  value="<<" class="buttons">$ U7 ^( T  y! E
  <input type="button"  value=">>" class="buttons">
$ ~6 q/ d- I7 }5 q# H$ N</td>
. j! P5 e  U/ |9 |, _. @9 r% m    <td>
( m3 B4 m5 G/ _9 _5 O3 |- K  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
' S' }; f6 d# X% y& k: `. e4 F  </select>7 O8 l' Y, S7 n9 {2 D, ^% w
</td>5 W& n9 h' K, P+ m- ]5 [
  </tr>
: {5 R4 P2 w& N$ u' M  n  M+ Q, l" g    <tr class="bgc">
! f9 X& s: s1 s9 `" _4 K3 E    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
6 l7 X8 w# R( T6 p! p  </tr>
. G  b" Z  _- }</table>. y+ V2 ?# O! n: s( Z
</form>
( s- d# c2 _; v% O<script language="javascript">+ i/ w1 j; Y  [0 s; U
//人名移动% R/ R3 w3 `& Z3 T$ r/ h
function move(fbox, tbox) {, ~4 }- k9 i; m" @6 Y: ^9 I
var arrfbox = new array();
7 w( r) z+ n  t+ |) `5 qvar arrtbox = new array();
5 o; T& L0 [( zvar arrlookup = new array();
# ~4 v: [4 ]: s8 s' V5 Evar i;) _: u8 Q3 C6 H. ~* z
for (i = 0; i < tbox.options.length; i++) {. D8 u/ K4 ~7 p) X
arrlookup[tbox.options.text] = tbox.options.value;7 s7 @0 X3 g* ]
arrtbox = tbox.options.text;
3 B8 o# x; Z8 k  H, T}! y  [; N' h' v  i6 Z+ @" j; y
var flength = 0;! G. u0 ]* n" B+ N  ~6 d+ ]( {! Q
var tlength = arrtbox.length;; V* Y" s8 r0 Z5 J* C3 ^
for(i = 0; i < fbox.options.length; i++) {+ H8 w: L+ {* u5 E: E
arrlookup[fbox.options.text] = fbox.options.value;
8 g( K; v: D6 h5 R- Tif (fbox.options.selected && fbox.options.value != "") {* G. p- `. v- x% b, v4 l, k* u( }
arrtbox[tlength] = fbox.options.text;
9 j/ g( m3 O/ stlength++;. W& j. G0 G: v' \! W7 \
}
' F' D2 a# s' l6 _" N* ]else {4 c2 N1 C, L8 ?& e6 S
arrfbox[flength] = fbox.options.text;
" x3 f/ H8 g& |! E7 t$ lflength++;
8 q1 s7 T) k' c& m2 ~# f7 x' U   }( [% m6 D/ p. ^2 W
}1 E7 z; N, {, b. e
arrfbox.sort();) V8 A) V8 h" a
arrtbox.sort();
$ E9 @: J! S" W  J- k% n1 k
  E2 M# i% I# u6 e  Q' I2 Sfbox.length = 0;
' J4 f7 f/ @$ g. o5 {8 }' ^tbox.length = 0;$ C  e' z) M9 |7 k4 L; L
var c;
0 C7 o( u: V, W' Tfor(c = 0; c < arrfbox.length; c++) {& z& X  X6 Q$ Z2 L6 F1 H
var no = new option();/ f; Q) [, m1 r# }( G4 `4 s
no.value = arrlookup[arrfbox[c]];5 [2 x- V4 k6 Y; z! O
no.text = arrfbox[c];$ B( g7 u  |8 ^; m
fbox[c] = no;3 Y( z* ~9 a4 n6 z  E
}' p( `8 D' c% w9 L: U, j: F
for(c = 0; c < arrtbox.length; c++) {
7 h6 {( j5 ^+ P" N5 {' gvar no = new option();
" r7 [8 b: [; W( X& p! Ono.value = arrlookup[arrtbox[c]];
- a  O. A$ G  m/ Vno.text = arrtbox[c];
0 D0 C, m# Y, ~+ }9 ^tbox[c] = no;  O; U( ^' y& a7 b0 j. z
   }! R0 D/ E# ~' j- @
}( k! Z  ], ?& H+ ]
</script>6 f4 m0 o% e' S$ S" f# s
</body>6 V0 i, [- l* q  `: s





欢迎光临 捌玖网络工作室 (http://89w.org/) Powered by Discuz! 7.2