Board logo

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

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

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"5 t; R3 t6 x% B: l/ c+ w
         c pageencoding="gb2312"$ w' }; u8 Y1 M, D5 T; p
%>6 X) U" }) V' u/ a
<style>
  H- Z/ z/ I3 v6 n" j.f9{ font-size:9pt; }
+ T/ b  d% x1 |* C% {9 e' ]8 C.bgc{ background-color:#aecaf9; color: #0033ff }
5 |5 d' P: q3 w; u& N2 g/ F, @.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;9 I1 f, j. ^1 v1 m; t, E. \
  border-bottom: solid 1px #4e7dc1;
6 ^1 ^5 d" f0 p& h, ]1 y3 z) W  border-left: solid 1px #aecaf9;
' v8 O. p7 n( g, g7 P/ ^  border-right: solid 1px #5679bd;- o3 q4 O" l3 o
  padding:1px;
: P1 p, T& G7 k( e0 a  margin:0px;}1 k* c! \2 ^  G1 Y$ K; O4 a
</style>
: z; j7 _" \: L7 s) q" H- t: j, P<script language="javascript">
/ q+ f: ^1 X! e. C: i<!--
! H9 ^- K( p/ R( k5 g' ]' Lfunction rv()
5 w7 ~% f; g1 _  R{* p) u4 e2 @5 z- m$ h% C6 l3 J
  var val="";( W& x$ E! m, `3 Z4 g$ o' ]' w
  for(i=0;i<combo_box.list2.length;i++){* E0 {( j& B4 K5 }( M* \
   val+=","+combo_box.list2.value;+ c; A. c& B5 y4 s0 [& t
  }; O. G3 P. ~# f) p! I9 B/ q
  if(val.charat(0)==","){2 M& N; l9 b# r7 ?5 x' @) o& U
   val=val.substr(1,val.length);, S; W9 b0 V/ F0 Q% v/ B3 W0 e
  }
7 D5 x! b4 q: _( F2 m- A  opener.form1.frecname.value=val;, V- W/ Z' a$ z2 g: c6 F. b
  self.close();
/ D+ }" Y1 i  r5 l}" q8 j5 Z. j, Z: }, h* n: A
//-->
  R/ y$ i/ _/ k- C</script>. H" ^- |, _6 P$ D( A  e8 M
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">( }' q7 [& e" ]& e) h# u% T
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />- D9 ~+ e5 F, L! C- m
<%
/ }/ }8 c: x3 |, N# N4 ?9 f7 a  cdatasource ds=new cdatasource();  //数据联结bean实例
- n  H& [2 h. n9 p) d8 L! L  java.sql.connection conn=ds.getconnection();% l4 m* H8 Z; l5 C. `
  java.sql.statement stmt=null;
: W7 l8 ^5 C, s8 _6 ^5 x# b6 K" q0 Z  java.sql.resultset rs=null;, L' Y: `4 l8 w& n) Q
  cdatacheck dc=new cdatacheck();/ D: h: {6 X$ L& K# V1 [
%>2 L0 q$ ?: x5 }5 o- X! h
<%; s( D2 b: F7 M1 t. O1 x: C* O
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, w) w+ d4 `1 Q- |stmt=conn.createstatement();
3 _4 I6 X9 a  M5 e' B! d. ers=stmt.executequery(sqlu);2 z% Z4 o! c8 ~, ?2 t" g; l
%>
7 N2 ~9 l) X, S! K. @" i<script language='javascript'>- j! N; n" [: |# V! [; x% \
arr = new array();( V+ {% O2 U# {: z1 r/ V
<%  int temp=0;
; {9 F; P: z5 ]& G% \5 |/ n1 R# xwhile(rs.next()). I; [, }  Y, `6 |# F2 J
{" \8 l, I1 N2 O
%>
" F# L- k2 e, t6 Q; B" rarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");* y& i) }+ B* R2 v9 a
<%
5 u3 N- d1 E( g% z3 C! Ytemp = temp + 1;
# c8 N" X* M( a! |+ m6 @2 O}
- t( a: |$ G. V: R6 k%>
/ [1 ^5 j" b- I; R$ s3 Ntemp=<%=temp%>;& ]* G' ]# [4 \5 K2 f9 M2 W3 o
function changelocation(id){ 2 v7 O- y  o( a4 T! T  d: |
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
. C  {' ~( r, Q3 H, Jvar i = 0;
7 e$ Z& B* i- o/ v0 |. Rdocument.combo_box.city.options[0]=new option('-------',''); 0 T) y  G) T( v* M* B; @; ~
for(i=0;i<temp;i++){
0 c$ n) C( V5 Rif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
& B) D, v4 w7 ?$ |6 Mdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 4 C6 N$ k6 Z: U
}
6 c5 X5 T' G, g5 G( ]5 Y}
( x! Y7 E) I6 D}
9 s% t3 k% o: y0 H; s/ r4 k: K</script>. I! D, f$ E3 ?' o& [
6 }+ Y7 H  a: l6 m0 g$ V( S3 v$ v0 [
<form name="combo_box">
* q- n* \0 p; T6 ?1 U<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
1 ?8 d3 x( e% r+ ^5 ?" e0 A4 g! ^# I: o  <tr height="24">/ B% S7 P; p4 q# U1 R5 Y4 W& w0 i
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
' J/ w1 q! G' H+ J+ q% v8 V' b    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>! d9 O, u: B( e6 v/ z4 x: X
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
5 V& n5 S- I" _2 ]4 K2 E4 O' J    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
- [+ Y+ {) Q2 ^$ r# d  </tr>
; [, r" @! J  y6 ?  <tr>
1 ?& j. J# h  e& \+ t/ i' _# z9 W    <td># C! h* X  p2 E3 L% q
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
, L0 O3 {( [9 G1 u/ j  <option value="0">请选择部门 ---></option>
' S$ [2 f/ d  p1 v; u<%9 O5 ^1 t: B: V4 C
    string sqld="select * from tdept";. g8 K+ u. C  K4 E" P( h9 I6 g: p2 [
stmt=conn.createstatement();+ |9 J2 h# H4 X5 Q& V* B
rs=stmt.executequery(sqld);
/ V2 @' n4 [) M9 K7 X$ z2 `while(rs.next())7 ]. t* t8 ^$ z' [
{7 T  J; J  V' V
%>* Y2 H9 P" Q+ X) J) O8 B
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
  X7 w# l0 o% X4 v& N" w% J$ v<%
4 J) r( K% z! T+ D}% h1 ~  f7 `( p: P1 R
%>
+ q/ a5 ]4 F7 K0 H" W& g4 o# c/ f  </select>* W" |7 p2 b$ E8 a
</td>
- J. p. t' z1 C8 e9 b7 O! U    <td>( y# u4 A% X4 t7 {  v7 E
  <select multiple id=city style="width:150;height:200" class="bgc">: C, Z& I+ m' K) l3 z; m
  </select>
  J& v: L/ E# Q. o6 J0 n</td>
7 }2 ^1 Y' `+ B% W4 [    <td nowrap align="center" class="bgc">0 v( D- X% E4 o7 U% C- R
  <input type="button"  value="<<" class="buttons">
0 B- k6 |2 A  a; b8 t# d  <input type="button"  value=">>" class="buttons">. n# N' A: y( T  T
</td>! s7 C( w9 U3 o9 ^4 Q! I
    <td>
. g" p4 {! S  F  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
( P2 F: s7 [# `, z0 Q1 _* K  </select>
9 T6 W$ i+ X( v1 q</td>
  B0 d4 v6 R$ l1 S* G+ V  </tr># j3 a4 u" u/ K9 X  e6 t
    <tr class="bgc"> 6 m3 k( V' H1 r9 `
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>/ H' I; S; G4 a: _7 I
  </tr>
8 O) Z3 A' D$ p3 F8 t</table>
2 l( e9 |# P3 n4 B</form>
" A( ~9 r( Q1 O, [1 n9 m<script language="javascript">' k+ c# g. x- Q. [" P0 {
//人名移动
" i' e6 u; b5 y% efunction move(fbox, tbox) {
7 l. C+ C# Z7 _$ T, [. nvar arrfbox = new array();. Z0 S+ H, M* I' i8 ~' }) b
var arrtbox = new array();& b% k) ~) C  J) j: j3 M& r- A
var arrlookup = new array();
8 i# a! _3 }& X! d% G* }var i;
8 n" ?2 ^$ _2 qfor (i = 0; i < tbox.options.length; i++) {
' c; i8 B5 t) f6 P& Harrlookup[tbox.options.text] = tbox.options.value;
8 |* k; r3 K( u) ?( Y0 Sarrtbox = tbox.options.text;" O" J! b( B6 [
}
$ l" i- o# v  \( Lvar flength = 0;$ R& B% e0 Y+ w2 b2 {& E
var tlength = arrtbox.length;: R5 B* W# l- N( u  ~1 q
for(i = 0; i < fbox.options.length; i++) {
8 a% L7 @/ u$ r  E5 A6 `: H$ |& W* T$ [arrlookup[fbox.options.text] = fbox.options.value;0 R- {& N% E8 C( H4 Q2 T+ i
if (fbox.options.selected && fbox.options.value != "") {; t3 _. E  c& F( e* b; Z. `
arrtbox[tlength] = fbox.options.text;7 e, L0 Y9 {: @* ]
tlength++;
' ^) K* K2 o6 K, ]}' S- E5 x) _/ M' K$ f* a. R3 c
else {0 ~; V* a5 j6 ~0 V5 w) t  T/ W* J% |
arrfbox[flength] = fbox.options.text;/ r) J* c  C  z& U$ y
flength++;7 s3 B6 o/ c2 K, G  \0 s7 l3 L
   }8 D+ s( r) g# q8 `+ h" m
}% E( ?, @* |8 }
arrfbox.sort();
7 }2 k' P! n1 J: j6 M" d/ ^* xarrtbox.sort();8 d; l$ B, ?5 v) G
& u; O- s) T3 n/ h( G% R
fbox.length = 0;9 I8 m$ p# K8 j3 q* o; x- O
tbox.length = 0;, ]& }4 O' s! j& t8 G
var c;
* r; T7 F* f0 Y& r0 w. o4 a, bfor(c = 0; c < arrfbox.length; c++) {
/ z+ _  Z7 ~) hvar no = new option();
( f* f7 Z$ n9 [1 Dno.value = arrlookup[arrfbox[c]];/ ?) H- x( a0 R
no.text = arrfbox[c];! I; q0 V& w" n
fbox[c] = no;
  W2 o  e. {/ g, ]; r0 p8 k}
. p3 W3 X7 \4 o. X) z( A* V" D' `for(c = 0; c < arrtbox.length; c++) {7 J  ]  a1 L! [% l9 d3 _9 b9 S
var no = new option();
; _( V2 A3 G' ^5 t; f3 \no.value = arrlookup[arrtbox[c]];
7 o- x* @, D4 ]! u4 C/ C& Kno.text = arrtbox[c];( q8 v$ z. w9 i9 s7 M
tbox[c] = no;7 o# N! t) d1 S+ H! G
   }5 L# J" T9 @. |% S6 d7 R5 O4 C
}3 `; p5 c+ s& X- {+ M- ?
</script>
1 `2 f1 _% n! }$ A. M3 P  U8 F* X</body>% I5 k, y2 |: p2 T





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