返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
+ Z) B8 R, M4 I% [6 Q         c pageencoding="gb2312". _) R6 K' X1 f
%>+ z& j5 F' V' h
<style>
/ J+ q, L' g3 k! u4 b.f9{ font-size:9pt; }
' h* l3 z5 Y& M+ p9 k9 T% v  m3 F.bgc{ background-color:#aecaf9; color: #0033ff }
; a' i" M4 p5 U! p.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;* j1 O7 W8 a  y5 O5 W9 v
  border-bottom: solid 1px #4e7dc1;7 t) o$ A  n* W3 _" y5 K" p$ a+ f/ d2 A
  border-left: solid 1px #aecaf9;
* Z9 p. ^# T- V# I" H  border-right: solid 1px #5679bd;% g- Y9 b$ R9 S% F
  padding:1px;
  t2 f% J& O! ^9 {; E  margin:0px;}
  k) J6 B$ b0 ~7 C9 [+ z</style>" H/ V0 e/ x* G$ l7 X/ ^
<script language="javascript">
7 D- C% j" ?; v# b! U; Z<!--
0 {6 e' g; g9 i5 Wfunction rv()! W* n' z" t' O% {) l: K
{
) F& @3 H8 r6 F  B' T5 U  var val="";
: L7 @) |' T* o2 a2 P& ~% e& G5 v  for(i=0;i<combo_box.list2.length;i++){/ M9 {7 v, L- m9 e) j
   val+=","+combo_box.list2.value;8 k& W8 i: ^/ q+ c! e% B
  }
2 a. H0 B- g& b3 a  if(val.charat(0)==","){
# m: A; H& F2 k& T/ t# T   val=val.substr(1,val.length);
8 c7 I7 g  O& ]" |" Q- u  }, J8 X* f, {9 Z- q
  opener.form1.frecname.value=val;! K! U$ ^- C7 H0 z) I
  self.close();3 r/ `" O2 x6 F. z/ ~
}& F& L( J0 S+ r
//-->/ b' z. n+ `7 u1 c5 e& A3 [
</script>
3 H1 F  ^( }' v6 d$ ~<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">! R' A- ?4 V. G1 U+ U6 {
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />: c; V: Z* {4 P% H/ I+ h0 ^
<%, w& b$ `! c3 o8 _0 z+ c
  cdatasource ds=new cdatasource();  //数据联结bean实例- _/ U/ }' W/ N; j+ j7 x  @
  java.sql.connection conn=ds.getconnection();6 z# u# E8 t0 ]7 W1 S
  java.sql.statement stmt=null;
+ B: h! S3 f9 N7 \0 z' z" t  java.sql.resultset rs=null;9 Y6 s4 _2 G& _* u8 _/ B6 p
  cdatacheck dc=new cdatacheck();
/ u# G1 v* O& L1 y! G2 V1 d+ A%>" K9 m. i  s( B. Z& o
<%
, n/ }* n" L( I, bstring 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";
4 I- V. M4 s& D# o6 [stmt=conn.createstatement();
8 M) s* I# R' _$ g5 h" p# hrs=stmt.executequery(sqlu);' I, E& C1 i, m
%>
1 J( {2 ^* U) `<script language='javascript'>9 R5 Z$ q: m4 M! m9 @: T
arr = new array();) r- G5 Q' |4 [' _; p8 {
<%  int temp=0;( ~% a1 K7 F# h
while(rs.next())! X/ e+ V" m0 N( r3 v& k
{, I4 m3 k& a" ~9 x/ ?7 @
%>$ V' l( ~, O- M, M: |
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");( N' ]* Z$ A& x  }6 H
<%
. e! s5 `& A4 L* G8 w1 ?, `temp = temp + 1;
" |/ m, D5 g1 D# g7 K; ?: G" S}
1 u5 W/ N3 t  X, Z3 z8 k: k%>
4 m: f* N+ N' v+ K% E, @' r: otemp=<%=temp%>;6 o% c! U1 F# H) _
function changelocation(id){ ! S, P4 {% A/ A5 v3 M2 a3 F$ J+ p
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 2 V: N! A$ b/ _4 p6 A
var i = 0;
  o& P7 ]' V- T! ?document.combo_box.city.options[0]=new option('-------',''); 2 s' A* g( {6 p) N
for(i=0;i<temp;i++){
1 I! {$ i0 [2 rif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 8 \& u: K0 F1 Z
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); ) \2 n: ]9 @% r# {0 i; j8 l
}
% \  C" L/ q# ]}
2 M. ^8 O  ^; H% r. ]) `  B}
# X8 ?2 n8 w! X) G# n) F0 W7 @</script>1 I/ [& `2 u. e: r' ~" c1 j
3 k5 |! Y" ]( K3 I
<form name="combo_box">
  A& K4 W+ H: R3 h& L<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
6 H+ K1 m% ^* I: |0 R* A  <tr height="24">$ a- S; K0 U4 k
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>  g# }$ F6 F( t' {' o1 E
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>2 ^+ \% S0 u0 V0 d  m4 `5 j
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
0 M/ b' g! G$ V; r    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
  F1 s) v. J2 N8 V, d4 m7 C0 W  </tr>
9 e0 r4 T0 J  y5 r5 a  <tr> & Q; N2 v4 E" ?. L
    <td>% _4 L2 P9 A" e4 e# T# g; G! X+ b! R
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
* a) {5 F+ p! F+ W! B! v  <option value="0">请选择部门 ---></option>% T8 y: q) y& B" Q$ p& k1 ~
<%& m& u- z+ v2 d+ b) ^5 ~
    string sqld="select * from tdept";
" R, S( f8 B2 D/ b# U! ]5 h6 lstmt=conn.createstatement();; [# U2 |( ]( W8 D6 j- j
rs=stmt.executequery(sqld);6 j, h# ~% k$ K8 {0 _( [
while(rs.next())' l$ V0 C1 R7 }1 p# G# O
{
# C$ ~# N4 U4 U: e: D%>1 F) U4 {; ^! o5 N0 |9 `& i
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>4 q9 G6 ^0 S3 J/ t5 E% t8 A1 X
<%
9 k( w/ ]6 h' s}
! F' e1 |, P& ~1 K%>
& s% S4 V; A+ m3 H' [: s  </select>. c' L; e3 [" @3 [% w6 n# ^
</td>6 r" u! D6 C9 S1 u6 m9 ?
    <td>$ n# |/ k* H7 p! E9 `2 U. e1 ~+ _) Q2 h
  <select multiple id=city style="width:150;height:200" class="bgc">
$ W- D8 H9 P5 [8 H  </select>
7 V4 S' ~1 d9 x# ]% N9 I</td>* Z& I# E9 O! s% Z& O; W+ ]
    <td nowrap align="center" class="bgc">3 g; `- N$ R. j1 b$ ]4 z
  <input type="button"  value="<<" class="buttons">* m+ H- j  l& P
  <input type="button"  value=">>" class="buttons">" u. h( f) a; ]9 i- a2 W$ V
</td>; _2 p$ m. N; n
    <td>8 h5 m' K4 G( ~; v
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
2 `# Z+ M2 Y3 G! I  </select>
2 A& V5 [% `, U7 b. C</td>1 F7 }+ @/ g; f8 I% }. Y) _% I3 P/ Y
  </tr>: p5 J+ D& x0 f9 B7 q7 e, L& h+ @
    <tr class="bgc">
9 H! k, B# ^0 t9 \% N    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
/ v/ \8 Z2 U: t5 l  </tr>
% i0 q3 C, @5 J5 p% H</table>
( T8 }' Z4 n" U</form>* E% H) h9 z1 m& l  V) k4 Z
<script language="javascript">5 U( c' B6 J. Q8 W8 J
//人名移动
" H! t" h" r1 S5 D, i! k* r' wfunction move(fbox, tbox) {, |* t4 v2 x  I
var arrfbox = new array();1 K% N6 d$ ?3 F- `! H* c7 l
var arrtbox = new array();
3 |1 ^2 Z8 ~, [% G0 P8 P& Dvar arrlookup = new array();
2 l# l) G# y6 u  O2 Wvar i;0 ~2 A) W$ X( I  S; T* U
for (i = 0; i < tbox.options.length; i++) {
6 m8 p: \7 _" p$ Y4 y- V; ]arrlookup[tbox.options.text] = tbox.options.value;
' ^  F! y- Z* T" n' marrtbox = tbox.options.text;
% V5 V, I+ l5 M6 U( ]+ _}
5 y0 \% Z$ J2 d" y9 {var flength = 0;
# {& c1 c* ?' n( J$ W% Fvar tlength = arrtbox.length;
  s* G4 J; e* p/ h; x5 j( Afor(i = 0; i < fbox.options.length; i++) {! i. K( [! s3 U4 x3 M# a
arrlookup[fbox.options.text] = fbox.options.value;
/ u0 m/ U& G9 L+ x) Z4 ^if (fbox.options.selected && fbox.options.value != "") {
8 G5 V9 e+ u- X- @( u5 i! |3 farrtbox[tlength] = fbox.options.text;
: v4 z# {9 i9 qtlength++;9 @8 l- w) L6 L4 S
}5 l% D; R! `- [8 I) {, ?
else {" g  W" t) S, e- R* k
arrfbox[flength] = fbox.options.text;
/ r1 h! H9 J) ~! Y+ q3 U6 t6 A0 T( jflength++;
% I4 s/ W. J# f! X! m/ J   }. Q+ e" Z% Q# Z% y
}
2 u# e. ]1 J$ Farrfbox.sort();
* j, m! P8 _' J- v$ Aarrtbox.sort();
, {) C# |# q4 o; F$ N5 s0 z$ B) Q  U. ~* e
fbox.length = 0;
: I" w4 r0 U% F  o- ytbox.length = 0;
) E5 F) Z; Z, t+ T4 ]5 [var c;
" K0 x+ k- ~1 \8 \* ~7 `: Jfor(c = 0; c < arrfbox.length; c++) {: P1 T1 v. i" Q" B+ y% `
var no = new option();
% {- J4 J9 s% @no.value = arrlookup[arrfbox[c]];
1 l. s$ b8 P7 H1 zno.text = arrfbox[c];' x% f6 O: H" X; t4 `# m
fbox[c] = no;& R9 M+ y* Y5 ~, p' p
}' y! r5 B% S* |4 o
for(c = 0; c < arrtbox.length; c++) {
8 n3 a! e1 l4 R. Q; C0 Jvar no = new option();/ i, ^2 ]0 G3 T8 [0 f1 B9 p, r. j
no.value = arrlookup[arrtbox[c]];
1 n6 |# k) v7 e* G+ pno.text = arrtbox[c];( r; N* ?- O: q' r
tbox[c] = no;
# i9 E' Z; L$ v0 v' u2 s   }
0 e0 [# u! g6 C; |! c, {}
1 T- A- J% @: ~7 ]& @</script>
% b- J* Y, J3 L6 i</body>
# P4 {( v9 N3 x1 r' R1 P

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