返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;") u6 L: R0 V, Z: z! B
         c pageencoding="gb2312"
0 c7 p. s, |2 P" E%>
+ {2 }1 P8 e, c. s; L<style>) l& F* c9 F3 W+ _8 y( Z2 C" B
.f9{ font-size:9pt; }
# ~; U* P& P" {1 t2 e2 i.bgc{ background-color:#aecaf9; color: #0033ff }+ T# V" A8 D0 c/ w7 `1 J. J: n& f
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;, \5 ^' M% {6 P" Z% d$ O8 |, O8 R+ I6 g
  border-bottom: solid 1px #4e7dc1;
" ~  ]4 n- Y, s  border-left: solid 1px #aecaf9;. e& G/ F, {8 c1 k+ y; M# ?
  border-right: solid 1px #5679bd;
% c" L; e- l) x: @! U  padding:1px;( x/ c9 A1 t/ _
  margin:0px;}
# o9 P0 @9 X. z- _9 z</style>' |# J  H7 J6 l4 H$ {- i; `
<script language="javascript">
7 I- {! {+ r! o# y( g  E<!--
* g1 R8 p2 K) X- T! S& W: afunction rv()
/ N* ?) |4 D+ S{9 Z/ G9 r! Y! H8 H8 V
  var val="";1 D5 l7 a2 u3 W) T9 w
  for(i=0;i<combo_box.list2.length;i++){. F! I- @/ @) e: J, W1 y
   val+=","+combo_box.list2.value;
4 p/ p* B$ C& A0 ]/ H/ O  }9 z/ j" a3 u6 G7 ?( i
  if(val.charat(0)==","){7 I. g+ s! `3 i) Y& h
   val=val.substr(1,val.length);
  C1 y7 L  w% M" j$ N  }8 m! n; e4 \6 I1 d
  opener.form1.frecname.value=val;
) l7 J$ O% r. K9 j/ p- y1 }  self.close();
: }, M" z  t* `  D: z5 c}
8 X& n1 D8 `$ y. X% U//-->
( P+ u. L5 t+ W- s) i</script>
. U+ I/ a7 _7 x: d* g<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">+ t6 c& v; a5 ?$ B) @, ~
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />1 F) w/ R% Q% M/ b: m1 O- O
<%3 E- V$ f" @& }# B& R  A& G- u1 J5 c
  cdatasource ds=new cdatasource();  //数据联结bean实例* S8 @: J& P4 Q0 C
  java.sql.connection conn=ds.getconnection();- j# l; k1 S  h! @! f& h9 V
  java.sql.statement stmt=null;
; }% z# d# I# ^: t% n  java.sql.resultset rs=null;' R8 f! {' k* _" {3 U, w( D, V7 H
  cdatacheck dc=new cdatacheck();3 w' p  T9 h; L$ v' b
%>
- ^3 R0 [8 L& j3 [8 T6 Y6 W<%
: ?% X7 M6 ?( J2 |7 T; B  e7 Ostring 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";
; z3 w. w1 s4 @/ v9 qstmt=conn.createstatement();& L; a* J( v: a* C+ F# Y
rs=stmt.executequery(sqlu);7 G. w0 R3 L8 Z' z1 D/ Y
%>+ p1 f# O' h) W# F  S
<script language='javascript'>" D. C; h. D) W. G2 Y$ R
arr = new array();" K& k# K  w/ b& J: t5 U2 o4 s2 b
<%  int temp=0;
9 \  p+ n5 d' q/ c1 N" u- rwhile(rs.next())
0 n5 f6 L, }1 w' A9 a{
3 m8 I: V1 t8 V% J( \  V1 V%>
# L( D6 q! s! }7 \arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
% d/ w# x; e9 U+ y8 q. s<%9 v& [; A( O3 o) t1 e7 i6 g
temp = temp + 1;4 b8 l; P$ H. w. c$ L& B
}
+ l, [; ?: ~: `' \5 @# P. m7 M%>
5 K, P% u) _  V/ ytemp=<%=temp%>;
. x: ~6 k& ?- _$ }function changelocation(id){ 0 b; N8 O+ A" }* @3 H5 q1 R( D
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
* M% I" |8 b  a  Ovar i = 0; - Q- k2 [6 O, \: c4 P+ r( o
document.combo_box.city.options[0]=new option('-------','');
) s$ {/ z4 ]" X: Ffor(i=0;i<temp;i++){
4 X0 _: r( f* D% o" P, [# K# l* Dif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] . V7 w- s5 y( m3 `
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); / {  b  F0 a( q2 T
} # ^$ Q! W  y) b9 |
} 8 v' ]% r+ p5 f, F
}
! t5 ^/ ]" c1 Q' o1 a+ r</script>
4 d+ [" q+ C! W/ k! O7 j* X6 b% n( H5 G
<form name="combo_box">. {3 w2 k5 [) k5 D* `) ]. S: M
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">% u% K7 L; n+ D; j
  <tr height="24">4 Q" A" z3 \8 e& o$ {
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>6 g7 b+ `( ?$ g) o8 [4 @
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
5 G2 f" J+ ^# W" c* R7 v    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
+ M: Q/ l8 l# a1 s6 T6 |    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>( U5 j3 v% O  Q
  </tr>1 {& o% l$ p  u" e
  <tr> - ~/ U3 e- _% S+ X1 w7 E
    <td>
. u3 ~8 D( M2 K9 \& {- [7 B( T/ K  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
" }7 V3 J: v2 F# b  <option value="0">请选择部门 ---></option>7 e4 o+ a$ I% v% ^' |0 o
<%
1 y  W+ @4 r+ b! j    string sqld="select * from tdept";
) g9 |/ m, Q+ ~; F+ vstmt=conn.createstatement();3 e/ F+ B( X4 f. v, @! A! m: v. u
rs=stmt.executequery(sqld);
; O) b$ Y" U; u- C% w7 r1 n9 x, E) O% ^while(rs.next())
# W6 n1 ?1 d3 m/ c. m/ z{
, s# Y" ~1 e0 I  y%>5 V" s3 v1 Z% O; Q& k# }" _
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
" K* H# f5 C6 O<%
' Z+ v8 \& C3 p& J- q}5 j7 `* e1 a& `! o6 z
%> % w7 |6 J$ e9 d+ \+ J% C
  </select>9 G6 q: j: R9 d0 O# ^% a. i
</td>
) g9 H- p5 _, F9 M8 o& U+ x    <td>
8 W; M# L2 y/ ]6 s% Z/ p2 H4 i  <select multiple id=city style="width:150;height:200" class="bgc">
/ ?9 d, C) E) t* a3 }( ~4 K  </select>
! _8 q" X4 t0 G4 ]" d" t</td>0 R" q- L) I$ [1 k
    <td nowrap align="center" class="bgc">
, \' |6 {- p+ ^! |0 P% J  <input type="button"  value="<<" class="buttons">
( F' F7 m9 `) ^) P  Q$ w7 C  <input type="button"  value=">>" class="buttons">5 _0 Y- e# l: _( B0 X' e$ w8 d
</td>) t5 O/ L. ^! [
    <td>% N/ ^" [  v! ]
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">  h, H# _) V# P' {
  </select>
8 C8 w' m9 w% w% U</td>
6 W: X) y/ W, K0 @- Q- k  |0 C9 F  </tr>
8 s& p. a: _* b    <tr class="bgc"> ' I2 |1 i0 D* i5 ?
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
/ A4 j& `" K$ B# d, y7 j  </tr>
& A0 g' w1 F+ w7 S</table>1 ?! u0 n% ^9 y/ r# u7 l
</form>5 k- T9 B( y" ]0 J* v& w
<script language="javascript">
9 I) j( }2 E3 N4 L" J//人名移动
8 u9 [- Y% s' @4 ^) l! }% cfunction move(fbox, tbox) {
+ L- ~' d+ n& X+ ?/ {  \var arrfbox = new array();8 G9 w0 S& f( E% l) O, v% T
var arrtbox = new array();
  n* H6 v1 @1 n& Rvar arrlookup = new array();
% [5 |+ Z0 _: y2 E3 lvar i;. Z+ I. `) y0 R$ H0 Y
for (i = 0; i < tbox.options.length; i++) {. S- j' S9 l3 W  W
arrlookup[tbox.options.text] = tbox.options.value;: T7 ~+ J) [$ B# i# f9 A0 a* ]
arrtbox = tbox.options.text;
* r! Z7 n- b  G}/ [7 E: o' C" S
var flength = 0;
0 T$ X1 m0 k+ [8 U/ r6 i) nvar tlength = arrtbox.length;. ]9 |4 N  o2 N. b, D2 o9 A
for(i = 0; i < fbox.options.length; i++) {
+ K, x# V( L* V5 F  a* Q9 uarrlookup[fbox.options.text] = fbox.options.value;
6 {5 A: o) y' J( i/ sif (fbox.options.selected && fbox.options.value != "") {+ ~9 O7 t% F6 c3 ~7 v( _
arrtbox[tlength] = fbox.options.text;) R) Y0 u& W7 g* |* @5 }
tlength++;' U4 m8 Q" c$ [0 R4 N- ?6 [/ d
}1 p3 ~) F. \1 O
else {) X2 W$ C, t0 y0 M
arrfbox[flength] = fbox.options.text;+ _/ t* y1 N) `) I7 q
flength++;
5 {! u0 {: u; O# V7 X) C. g   }
1 A! o3 {. s, t2 B  e, T7 r}# C* h% h6 e; Z" ~, f6 c- N2 D
arrfbox.sort();
; N3 k7 d9 J2 q1 ~% {  z1 \arrtbox.sort();  |6 `! B; m; D/ d& A# _7 T1 N' X
: N- K; F+ _/ A  o; Y" M* w. G7 V
fbox.length = 0;# a9 k, Y3 e9 V' }2 ~: O4 O* b% |
tbox.length = 0;
2 l! H0 Q1 f% y7 svar c;4 i1 j. I7 _+ C5 @* r7 z
for(c = 0; c < arrfbox.length; c++) {
  N  ~9 Y; q8 l0 ]/ t! [4 Ovar no = new option();
9 i( i6 `$ t  jno.value = arrlookup[arrfbox[c]];
5 }0 I& |/ {! t- i  k6 I( k+ zno.text = arrfbox[c];1 I) L7 D+ S! v. r6 u
fbox[c] = no;5 y$ l$ i. U4 }% [) T4 z
}+ Z+ `) h, `8 T9 c5 i: d% \1 L" x/ M
for(c = 0; c < arrtbox.length; c++) {) N. y  V1 i3 h9 q2 p/ w) ]
var no = new option();
3 s- Z0 |$ {# W$ }, K) lno.value = arrlookup[arrtbox[c]];
) w0 }- g7 b. Hno.text = arrtbox[c];
3 A8 \6 y; f$ O9 w' h, e1 A' Mtbox[c] = no;
4 b4 D. V) \! X4 z! V& m   }
9 p) Y) O% S* `  n4 X. O& g}. Q6 J- g' f& q3 ?2 A4 E$ t
</script>' O  Y7 n# K( z. X5 o/ j; W
</body>
1 o# `* O/ T2 D# i

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