Board logo

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

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

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
+ U: k# [! A# Y6 X3 b         c pageencoding="gb2312"' Q1 x* R/ f* m5 a
%>1 z  j+ y( e  y% Y
<style>
9 W  R" J0 N6 B9 p7 e3 A.f9{ font-size:9pt; }. X- Z. \* Y+ x$ a& E+ m9 w
.bgc{ background-color:#aecaf9; color: #0033ff }: ?6 Y/ {  v8 Q$ ]% m/ g" |
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
3 v* C, q' s" u" x  border-bottom: solid 1px #4e7dc1;
5 ~/ B# p/ F- O  B" d; P$ B9 |7 h  border-left: solid 1px #aecaf9;
* w; R1 L6 {4 ^2 U% Q4 ~' E/ k! v  border-right: solid 1px #5679bd;
# k$ s) Q8 |: L8 ~2 o! b  padding:1px;
( U, e4 p& w) J8 U* Q) h7 X  margin:0px;}( p9 R6 S+ h3 w1 h; a
</style>
6 v3 G4 J! ^$ ^% e7 ~* V<script language="javascript">
8 M  ]6 v8 R! S8 F5 A+ H<!--  e: K: X) f+ ?6 G: x/ c6 M3 ^
function rv()6 U6 B& z5 s. _3 P
{
& x3 w9 ?! I: S. u8 L; I  var val="";4 Q: H3 b+ _% L: ]8 C
  for(i=0;i<combo_box.list2.length;i++){
/ [1 ?: x; Q7 q   val+=","+combo_box.list2.value;# Z7 _& z! s, u9 ~  I
  }4 A" n' f2 U: |# `
  if(val.charat(0)==","){% T: C$ D$ X7 E7 v; a
   val=val.substr(1,val.length);
( ]% u* j, \. D  I* R  }
/ l& H+ X  U# t# @/ O( F( E1 M8 T  opener.form1.frecname.value=val;
2 q$ K7 q* s/ @! Z  t' P" p+ E: ?  self.close();  O. N8 P6 v4 z" s
}
, l+ `7 ?3 p& ^$ S//-->  U2 m, B4 G8 C3 V
</script>, X) Y+ a4 t  ]( V4 @, m! V0 \
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">3 I0 P4 I6 M5 Y5 i3 a
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
# F2 S1 T- l. V2 i! ]<%5 [" C* i8 S) a4 [$ m. @
  cdatasource ds=new cdatasource();  //数据联结bean实例
7 m8 I9 m, G- x  java.sql.connection conn=ds.getconnection();
& D7 j2 R- y+ i4 U  M5 D  b- ~/ R& u  java.sql.statement stmt=null;: z, V  H8 G% B# Y: p: V+ a4 x
  java.sql.resultset rs=null;
% O3 n6 b# p, _$ O( U" ~; c6 z  cdatacheck dc=new cdatacheck();% F; q6 _: p0 f# ^- t$ D
%>
/ E0 Z5 m# m3 n! }4 `1 H; N<%+ W- `: @( s8 S2 [% g
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";
6 k; U6 z6 K0 r: e! Y, W# B) Fstmt=conn.createstatement();
7 y) `  u3 a1 u. s# Jrs=stmt.executequery(sqlu);
; Y; v  ]9 o, g- E%>( M( j7 u/ W% B$ u! M$ z
<script language='javascript'>
" D7 Y' ]* R: ~6 i* Aarr = new array();
$ {% s( x3 Q( ^1 v<%  int temp=0;2 l! I1 ]* d5 [% z
while(rs.next())
4 z( `$ J3 x2 o{" ~! M& d: i+ ]6 o5 @& A# l; x
%>
; I6 Y- l% _" ^/ k6 n2 k) D9 S" ^arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
5 w+ V& B& d0 ?( ^4 K8 e6 j<%
# F8 B; o5 R0 L( e6 ]1 T! A2 |* etemp = temp + 1;
2 i( I0 K4 M' C( j; f}
3 y" p; Y( D% @! [%>
/ u, y  K0 X* ptemp=<%=temp%>;
0 {. `' W. k7 M6 }- x5 L5 [function changelocation(id){ 1 t3 I# L0 b- q+ G
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
/ i# H" ]7 |. @8 lvar i = 0; 6 l" Z+ {3 s. q: J% c
document.combo_box.city.options[0]=new option('-------','');
  C) J. S7 ~' L( Xfor(i=0;i<temp;i++){
5 V6 h" e. l6 F, mif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] + q9 ^" V( y) G- Z0 G" X( t' x5 ?/ u+ a
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 2 y6 J1 D5 `5 [1 i5 Z$ h
}
& k- U8 S2 t7 p; x. @5 k} " P" Q5 E, |9 w5 g9 Q
} ( h' T  j; Z! g! H
</script>
& @1 O1 k8 J* z; K/ H; c9 i' c1 L9 Q8 K, R; o- U2 w- X6 r
<form name="combo_box">6 `/ T8 J* f2 `, D, |
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
) O8 y1 Z! o( N7 a/ c$ z  <tr height="24">, x; B3 _9 ~$ R4 ~4 L( R% R
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>7 o9 b" s7 f& L* D
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>8 p  p; v; P) I$ ^2 x4 h
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
. Y! R3 Y/ i! Y. K" T* w3 n    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
+ [4 d: P8 v% |% ?+ @$ N# Q. p  </tr>9 |/ x; U" X+ u5 x" [9 B6 b8 r
  <tr> ; V2 ?, j) b: C* S4 k, Q
    <td>: q: [8 [. n- {! ?* Z
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">- L% M9 L4 E% J/ |7 Y' Y+ U
  <option value="0">请选择部门 ---></option>+ t7 [3 e# B# ]  l% y- K
<%
! w7 u! Y7 J- m; t3 ]7 M    string sqld="select * from tdept";
8 Q; Q: Z$ o8 B5 T. M: N  D- P& H5 Tstmt=conn.createstatement();. ~1 z* m2 y& U( N. F
rs=stmt.executequery(sqld);
% F, x( ~  x1 G5 f9 N+ p& {while(rs.next())
2 {5 T5 K3 L4 G: w3 Y3 g1 v{  V/ L5 v  b3 w" I0 q
%>5 o5 h9 C& c2 i  ~) Y( `' i
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>1 N7 Z  Y6 j' A3 g5 V, E
<%
3 m) ^( e* i* ^0 O$ v$ {# X% O}* G" V  |" f& F  h) u
%>
, j# R1 l, [, b+ M  </select>
; L; e" ?2 g; [! z6 {, o</td>1 r, D0 W( o3 [3 I
    <td>
% t9 K$ H1 o; N1 E& _0 J  <select multiple id=city style="width:150;height:200" class="bgc">
: M: ]- i# n7 G$ Y! {# w  </select>
5 }/ o0 T% G' z4 w$ k</td>
/ g: O/ K- u# L* E" K$ z    <td nowrap align="center" class="bgc">
& C( _2 B( @' T  <input type="button"  value="<<" class="buttons">
0 ~5 p6 d- ^7 B% M, K7 v  <input type="button"  value=">>" class="buttons">5 \2 @7 t+ E+ }" c: G/ i
</td>: @: g2 m0 K, }0 V: d
    <td>% [8 K4 p! G9 B) U2 y
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
7 s1 v3 y/ {) I- r, _: u; K. M  </select>
) i; K! T# k0 f/ O/ }7 F0 B6 E</td>
; G0 f+ Z7 R5 `, `0 }; }+ _( `  </tr>
$ ]# ?, \/ g1 e2 b& @4 \2 v" {7 M/ J    <tr class="bgc">
; y2 r/ g$ v  Z' Y" @    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>2 ?3 Q  c" ]( G7 |5 [. v9 e
  </tr># m$ {  P' m6 _
</table>
& o+ J: t! R1 i7 I1 Y</form>, G) z. [. P8 v' x
<script language="javascript">
. q* G) T. L( }# H, c0 A7 h8 I6 l//人名移动9 K/ h% C8 x3 y$ \, Q/ g
function move(fbox, tbox) {/ \+ I9 O6 w- y% c: v; x6 v
var arrfbox = new array();8 ^8 N- e  q! _" T% O* D. w
var arrtbox = new array();) |$ n; v; F7 u8 h% t
var arrlookup = new array();: U- V% `0 W. b; b+ ^
var i;$ @& X7 u0 m1 T1 n) {& {! \
for (i = 0; i < tbox.options.length; i++) {
9 e" O6 {5 o. z! |arrlookup[tbox.options.text] = tbox.options.value;
5 P' P+ f: M8 w1 N* g9 s9 R$ Barrtbox = tbox.options.text;2 S! g$ O% B+ V6 D
}
4 R8 E+ G8 R; f+ R' `, M0 Bvar flength = 0;, k& M* C# P5 g- z9 p
var tlength = arrtbox.length;
6 H' M0 a5 _0 v* @for(i = 0; i < fbox.options.length; i++) {; @0 `; j6 }" y6 \: ~  U! U6 k
arrlookup[fbox.options.text] = fbox.options.value;
6 T+ Z- v; [* y7 f  b2 Sif (fbox.options.selected && fbox.options.value != "") {
9 M# f2 k% t7 c9 W1 ]0 J1 h. harrtbox[tlength] = fbox.options.text;3 I" ?) q& z+ k
tlength++;
6 j- T; V+ R6 f% m2 T, i}' T: ^% `+ ~) `7 u( Z" U  C
else {0 b! B4 f/ P# z2 Q9 a
arrfbox[flength] = fbox.options.text;
  B* R9 H9 P0 M0 }8 d: Fflength++;
1 U- C) C) k% n+ S$ t6 b$ M   }5 o. \! H: ]' F" k8 e
}
' M1 g  `+ z" {7 k& Parrfbox.sort();
2 _7 h! j+ f$ Q; zarrtbox.sort();
6 g( @" _8 \0 z2 f9 Z4 z
' Z% _( G" `% M- }& O9 t  Nfbox.length = 0;
! b$ F6 F& j4 h; W& z- R& f# |tbox.length = 0;
* m- R* A! o' w1 R5 ]& f+ yvar c;
2 B( i3 e: w) t4 R1 F; V* jfor(c = 0; c < arrfbox.length; c++) {7 F* M  t, n' s
var no = new option();8 U/ r6 D3 x! i$ J$ e3 d  ]7 E
no.value = arrlookup[arrfbox[c]];
; N) i# ?9 j9 a$ V- Fno.text = arrfbox[c];
7 y/ u) i: P$ y. G# ~7 Ifbox[c] = no;$ v+ @6 n* ^. L% B
}' p7 x" ^/ [2 K) w# g
for(c = 0; c < arrtbox.length; c++) {4 h* ^7 ?5 b2 a' o3 v
var no = new option();) Z( }# A5 z& q$ v) w4 k3 j7 [
no.value = arrlookup[arrtbox[c]];2 N7 \& M0 S1 D4 v* m2 }
no.text = arrtbox[c];
5 q( J  \1 n, E1 V7 u, v% Ltbox[c] = no;: C+ w( r0 }3 L: Y+ I/ `8 F+ G  r
   }
! l6 W6 p' E; c; U}
! b4 X; F( k. l</script>: ?& M1 H6 Y- Z/ C
</body>- p4 F2 C7 \, w" P4 u, W2 Q





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