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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"& E  X& e7 O/ E
         c pageencoding="gb2312"* c5 o/ G8 P" p9 O8 }4 J
%>
0 w! k# q6 b+ [. v6 z<style>+ V& R0 V/ X6 u0 W+ ?' P! y8 Z
.f9{ font-size:9pt; }" S. q3 Q& T, M8 W& o' b3 r" f' ~
.bgc{ background-color:#aecaf9; color: #0033ff }+ K6 m3 M/ {/ w5 {8 N4 d7 R
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
; @+ n. g5 {+ P4 L2 ~/ `! l& X  border-bottom: solid 1px #4e7dc1;
9 ]3 n; @$ M: w; X  border-left: solid 1px #aecaf9;5 r* j$ A5 a( V: |* W: U
  border-right: solid 1px #5679bd;4 g" u& g8 m5 h0 ]3 E3 \
  padding:1px;
4 l* J$ s" g  @- ?  margin:0px;}
/ G0 x& {# R! N! ^4 _</style># v$ G5 z8 a6 _
<script language="javascript">3 O" a4 D# C- p- ^% {5 ]8 F
<!--
! w: b* A! }& l* G, x7 p$ K' T  |function rv(), ]0 @' p1 P9 ^; i8 R' W
{
* h3 m/ I) F1 G% T* w3 @  var val="";" @; h; [/ ?# H+ A
  for(i=0;i<combo_box.list2.length;i++){- |; s* e3 q3 i8 y+ n+ i% Q
   val+=","+combo_box.list2.value;2 p9 i6 a0 M  I7 J% u) Q& k# H
  }! l, O/ U2 S4 @( C
  if(val.charat(0)==","){
- F) P# c; Y5 V  q4 G   val=val.substr(1,val.length);
. V# \8 o/ j& r' L& Q0 c! j  }# A0 d$ k1 y8 _- A# x
  opener.form1.frecname.value=val;
8 p& }/ v, |' O8 f5 s2 L  self.close();
9 n1 V* M: n0 y: @}
2 s& U: Z; _. y% S9 W! E) g//-->! ^! T) q2 o; Z; ?. c- Y
</script>) x. g$ X- T7 g" C0 l
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
% k& o$ q8 L2 e: D<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />0 R( i* n5 ?, m( J
<%% q; D* Z6 U1 U7 Z
  cdatasource ds=new cdatasource();  //数据联结bean实例
. H! A; Y4 B& n( m! ]  java.sql.connection conn=ds.getconnection();# g7 H  I; _! h* Z* y& o
  java.sql.statement stmt=null;
, @0 f7 j; s- g- Q  java.sql.resultset rs=null;+ }- @2 p0 r. V, _( z: d6 Z; M
  cdatacheck dc=new cdatacheck();
1 [2 b* A9 w# ?6 s%>1 _) _$ w/ h' L) `: `
<%
! }7 F5 K( K/ S/ fstring 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";
. A1 B, L9 p/ `& B! r8 S  R3 \stmt=conn.createstatement();
; U7 [$ F, _' J$ r+ q+ \rs=stmt.executequery(sqlu);
# j, a5 p$ q; m%>
. w- W8 M. z* M1 p' E<script language='javascript'>
- R  w5 M# I" V' {% marr = new array();
% D8 I- }5 N8 r3 V<%  int temp=0;) R+ N1 j3 [! a- S7 [( M' f
while(rs.next())- y" I- f, J2 s- H; t1 F8 u- B3 p1 e
{
- @; B' d, [/ F+ i%>( F" k6 Q9 G% `- w1 z
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");9 |; R+ v9 c2 z/ [; O/ x8 c
<%9 K$ `- l4 u0 r
temp = temp + 1;# R" l; U6 q0 q
}' z/ z" z- I' Y+ V+ ^3 f
%>7 B: z% W' P5 f( b6 W8 F" [
temp=<%=temp%>;5 j* `* r. m( V9 w
function changelocation(id){ " Y( ?4 ]3 a8 Y! @, x- h
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 ! B; H8 F; n& k# y4 K
var i = 0;
) u( A; w  h( kdocument.combo_box.city.options[0]=new option('-------','');
6 W1 u3 w$ I3 B* b3 ?for(i=0;i<temp;i++){
! a3 m0 ~! h* O+ Cif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 2 e2 a, Y+ y( I, ~2 B# }, e
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 2 _8 ]! T! O* N) m- T* E
} $ ^0 k! E2 d8 L6 E3 C
}
( a5 ], `" l# o: j1 [( n}
3 i8 z/ S) i% b2 r  \</script>0 S  S+ B4 G% q6 H0 |
  L- A  V! k! \% d) q8 z. I
<form name="combo_box">
; d3 x6 m* a' g- H% I<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">" l: P- h3 U# R8 D
  <tr height="24">
9 z  O! @! p6 K    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>4 h9 x4 f& S  g' ]$ V( N! P
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>$ d$ o  @) o/ n; L( M& T
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>, E2 {; G# R) w& l2 ~, s2 y, r
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
% Q  |3 `# P! m: ~7 l/ D  </tr>
0 v/ ~+ k: _% f8 n  <tr> : s/ ^/ `9 r6 _) A; K- C! p9 k! Y
    <td>
( g3 K- x$ X" Y, C2 \, b2 {  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
# z3 o7 g& `, m! h7 U) q* c  <option value="0">请选择部门 ---></option>
# {# X8 q, Y) B9 U* T/ A# ~<%
  N5 Z: x  X0 ^0 V; F9 ~    string sqld="select * from tdept";$ t' n- Z: c2 r. \4 w
stmt=conn.createstatement();. D1 K" Z" x4 y! G
rs=stmt.executequery(sqld);% p) @. Q9 ?6 x* N1 S* w
while(rs.next()): |) J, i2 M$ M0 [
{
9 `! {$ b9 q, \  e%>
4 }* b" R+ P+ u" O$ }  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
& k: y: P: N3 H4 D8 z<%
8 E$ c4 ?; u' s! n- q. D}( t; ^& d/ S/ a
%>
* W, A2 z: g1 I) A9 a  </select>) \) c2 k7 c- A/ _* g8 a6 b- R5 P. G
</td>
& m4 O) _: u$ q/ \% [0 o2 {    <td>
3 x3 D- P1 W; ~; c  <select multiple id=city style="width:150;height:200" class="bgc">
  D$ X7 s* Y& Q; x  \' \8 Q  ~4 l  </select>
0 `8 \6 a- S, K* P</td>
9 u2 g3 |# \6 Y6 Y0 Z7 T    <td nowrap align="center" class="bgc">, E& P# V+ k: e/ t8 a* F; {4 w
  <input type="button"  value="<<" class="buttons">/ x3 w- m$ U5 j5 _1 A, k
  <input type="button"  value=">>" class="buttons">
- s* T  E/ c! n, _( X6 z</td>; r! B1 g, B- o) K0 H2 n- y5 s# g
    <td>
! v# k+ f  _0 Z: g% a; d, q( H8 o  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
3 a  c9 M' M+ p4 O, n- I5 O  </select>
; D' m  |, R3 K+ j* C, X</td>
' w5 y$ |& x9 q* ]1 v; h, u  </tr>) ?& ~+ ~$ }4 n8 z5 _
    <tr class="bgc"> % Q1 m+ F5 z5 }8 Q$ g1 \4 W9 O
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>8 v' U# C& Q: W
  </tr>) v% t( ~" K7 R, a+ |- r* R
</table>
" f2 u( I7 o: S! q: ^2 m- J</form>) E# d/ u' W: j! Z3 H2 x- s6 N; e7 G
<script language="javascript">$ ~9 Q# \2 Z( f
//人名移动3 R# b. P% }  z  x! `! l& k
function move(fbox, tbox) {7 b" N* O+ G: a! K" \. ~9 j7 H0 K
var arrfbox = new array();0 p* ?( s8 ~4 s+ z% ^
var arrtbox = new array();
/ Y! h% P& p* [var arrlookup = new array();
& ~$ j) n) p6 }8 a8 xvar i;5 ]* s, b) H7 k+ n0 o4 E2 w, A
for (i = 0; i < tbox.options.length; i++) {
! v- @' B# P/ d; Larrlookup[tbox.options.text] = tbox.options.value;( Q1 T0 u3 l' @1 ~" J) V9 f
arrtbox = tbox.options.text;, D" l! k; j5 I$ p8 ]
}" X; s0 U1 c. z4 j6 a# U5 Q) B
var flength = 0;
, H/ f/ e$ I: |1 {) E2 Q  P6 r# avar tlength = arrtbox.length;
" B2 G/ t8 K8 n: m! cfor(i = 0; i < fbox.options.length; i++) {
- n$ E2 O3 s: u) _3 N% ^. R% yarrlookup[fbox.options.text] = fbox.options.value;
3 N  f  X7 g7 q1 @' wif (fbox.options.selected && fbox.options.value != "") {! L! V2 R, E( F1 r
arrtbox[tlength] = fbox.options.text;
* {7 P7 {# `$ e( xtlength++;
, r' @1 N5 z* \9 F- D) g, `+ ^& `) g}
1 h3 N: I" {: R, N* H" qelse {6 l+ {/ v4 G9 v; k1 `4 c: f
arrfbox[flength] = fbox.options.text;
% K! [) J% ^% L" g/ T* O. Fflength++;0 B; `5 ^3 f# Y+ P: e
   }
1 P5 {/ [) B7 F) v3 {8 z( A}
5 @& v  u: V  A! Q5 |1 |+ k- darrfbox.sort();
; R4 E, `5 O6 C' T: N: Uarrtbox.sort();, K+ ~* G6 u" v# G

  ~6 C0 A  c' W* b( qfbox.length = 0;  p) T( I( g9 w/ N( Q$ z" j
tbox.length = 0;+ s; R8 ?' W  B6 ?( y$ w4 C) F- |) B
var c;  ?+ D$ s5 }! v1 c
for(c = 0; c < arrfbox.length; c++) {/ M! a2 ?. ]8 B/ b' V
var no = new option();4 C/ @) g4 J, X9 E! x
no.value = arrlookup[arrfbox[c]];
( Y& Z2 }' W' S, Ino.text = arrfbox[c];/ V6 k! ~7 K" {  @+ a9 ?
fbox[c] = no;1 u, f* W# _+ J( u0 G" H
}
) I7 N8 N( d: ~) l" C1 Gfor(c = 0; c < arrtbox.length; c++) {" K" f- E( H9 q( x& Y1 t& \/ W
var no = new option();3 F6 }% m4 Y: T% Z4 R/ r% M
no.value = arrlookup[arrtbox[c]];/ o, _3 v' F% ]! G) t2 _  `" ~. M
no.text = arrtbox[c];
* @/ e$ P+ q! Z5 Q* m1 ^" {" Ftbox[c] = no;6 n4 z: C7 E. q% i9 R5 g
   }
0 v% g$ L2 s" {0 ~0 B0 a# W# g}6 Z3 ?" m& B. n' a
</script>
) l' d, U' c" ]6 _9 o</body>7 v$ l+ L& c) A6 ?

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