返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"8 u4 F8 \* P  X+ N, Q+ d0 p& h. E+ C
         c pageencoding="gb2312"
* C/ `3 ?5 {4 ]) S" s( e%>! f7 ~0 u, L2 K5 C
<style>
' Y; W. \7 f2 [/ F5 E.f9{ font-size:9pt; }
, C; w) r# o: [0 \.bgc{ background-color:#aecaf9; color: #0033ff }
1 Q2 c/ w4 n- }9 ~5 B2 _% u: }+ o.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;2 V# Y9 m) V0 |# }( H' s
  border-bottom: solid 1px #4e7dc1;
2 x: }3 S  X% L  O; B1 E  border-left: solid 1px #aecaf9;
/ W/ ^  d$ M. V" P- {; Z2 o7 T  border-right: solid 1px #5679bd;1 ?. L- x* L7 n3 s# G9 R; ~8 U- L5 p
  padding:1px;
( @4 I# V& [# c" c# a6 T  N) k, E  margin:0px;}5 L- X. _; n( Y: J% [
</style>9 t  n& F6 R1 j5 ^, e  m+ ]
<script language="javascript">
9 }$ d, S2 t+ l1 X$ ]# Q: [<!--
' V6 l$ y9 ?6 Y: x5 ifunction rv()
; {; A# h. C7 g! `7 Z# D{6 |' |3 P% Q2 G
  var val="";
! `8 ]% g, c: Y- ?6 N  o  |# x4 y  for(i=0;i<combo_box.list2.length;i++){0 F1 H/ A5 W4 p, w6 M( q
   val+=","+combo_box.list2.value;
8 ?2 s9 K' |: r2 ]  }
3 W8 R/ @$ S; d' r: l3 L8 D  if(val.charat(0)==","){
# }; x7 B: C5 u7 X5 S   val=val.substr(1,val.length);, [$ p! H4 ]/ g
  }
& h& X1 V) \3 `9 n7 U3 ]& x* j  opener.form1.frecname.value=val;; ^3 P1 I* O* K0 x
  self.close();6 P9 g8 g# m0 p# ]' S5 A/ i
}
9 l! `# M$ y2 \! U/ w# m. |//-->
; E8 E; ~" Q" ~9 l6 N5 Z( F</script>
% f9 W5 H- C' {8 ^<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">; O* _1 x- Z; Y' {* f8 U8 ~; s
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />: ~9 A0 `0 E- Z/ T$ L- F4 n
<%& r! B6 J# `" b6 D- {
  cdatasource ds=new cdatasource();  //数据联结bean实例  a: |0 j$ Q7 o- z9 z6 ?
  java.sql.connection conn=ds.getconnection();
2 L* f' S/ n& k6 x/ A  java.sql.statement stmt=null;
, U. m2 J4 F# X6 H7 L" J  java.sql.resultset rs=null;
) q3 C# ?/ {6 F% D  cdatacheck dc=new cdatacheck();! W6 O1 Q! q; u1 J6 Z
%>0 K0 p' y6 z3 Z0 A# X+ ]9 V5 X
<%( u4 L% M4 ~! u
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";
% j6 q/ S0 M8 m/ kstmt=conn.createstatement();5 m  v- Q% J' e
rs=stmt.executequery(sqlu);# J1 V  @# U+ M) {9 r6 B, P! m$ a$ F
%>2 K# D, @! m8 @
<script language='javascript'>' Y& y/ K7 J8 G
arr = new array();
* z( i1 L5 o' U, o8 v% v1 x- d<%  int temp=0;5 Z) j, F+ H( R$ E& W
while(rs.next())
- b2 n$ f. t4 {{( F" b6 K- X9 j. O* R
%>" e/ Z4 E0 T* C+ q
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");( c3 i6 b) m& E; L: s2 H" a$ B
<%: u0 U" g! U' h9 k' d
temp = temp + 1;* J! M, z# A* N* u  N2 M1 D
}
- q! X1 M. ~+ H3 Q%>
8 s' z. g& n& E8 Qtemp=<%=temp%>;
7 Y- M# e% u; }" G& W  Mfunction changelocation(id){ , Q2 n1 I+ J% [( z9 Y
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
8 r) p8 ^$ B9 qvar i = 0; , R+ U. F9 d' {# `) a
document.combo_box.city.options[0]=new option('-------','');
7 C1 x! a# }4 r# kfor(i=0;i<temp;i++){ & @5 L5 ]6 x6 w7 X" R
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] : Q7 U+ E, m& Q
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); / M8 n3 M7 {, c# B
} 7 D+ a& ?( B8 m+ j; `& G+ c
} 8 c& _, y2 K9 I+ Y+ M
}
: Z0 q$ ]! Y( t  h/ D</script>! X% R0 [& C$ i0 g' C/ E4 m$ z* C
* N4 T. m' ?- O
<form name="combo_box">* m' ^" g4 r. w. p" [/ g
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">  ]) D; i, E$ T0 Q2 c. Z
  <tr height="24">- o1 ^3 \& @) V  R
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
, \0 g7 W- G3 j9 z% s4 Q    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>. N  c9 @3 |! `
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
$ h* @+ y' ~- @    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
9 Y: s$ t* F3 v+ B" u* A$ B+ X  </tr>
' h) n) j* e# {. D4 m, u& [5 l* ^  <tr> " o4 H7 N5 {+ `/ R" x
    <td>
6 d  q- @$ x+ W' h  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
; {6 k/ U* Z. E  <option value="0">请选择部门 ---></option>
' B) J' |' P. E' Y, G( ?<%3 H  n' ~3 S( h0 l/ m
    string sqld="select * from tdept";4 K4 ~9 X  U- J' e
stmt=conn.createstatement();
$ g- M6 r: E5 Q& xrs=stmt.executequery(sqld);9 S5 [, f3 X9 T1 d1 W" x
while(rs.next())' u0 L; l; v; a, @" r  p
{
0 m1 p/ C7 Z1 j: q- g%>
# H% P6 W  f0 x4 g  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
( I" v- Y3 I/ t/ O" L<%
3 ]4 A' M& e9 e! \: v* a}
% O6 N$ _' k8 h%>
# y* y* l5 |+ m: O. ^  </select># [8 ]. _+ r+ Z0 ]6 o% |9 C! w: }& M
</td>: i5 J) Q+ a0 K- p1 f) T  @
    <td>5 T' M# [& u- P# E
  <select multiple id=city style="width:150;height:200" class="bgc">
( F  F- e' i0 \! d+ j7 b" k  </select>
" t  M% Y8 \9 P# m, c2 E</td>
! o7 q9 f, [& f( Y, m- d& `    <td nowrap align="center" class="bgc">  }+ F* p" D8 Y5 b# B1 A
  <input type="button"  value="<<" class="buttons">" p: e: M$ F+ j/ r" _9 G
  <input type="button"  value=">>" class="buttons">
9 V: v+ Q. T- h2 F# M" w" y</td>
2 ^* @: P# P& a9 ~/ ?    <td>7 n; |6 A- l; P4 @- u, G) K
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">& u# L9 O% q; [+ b9 ~  m" i! Y
  </select>
( ^/ d: N7 z# Q: c9 B" J8 a</td>
) m- K, C$ t! K0 U) u& o  </tr>
7 `- S# n( I0 B- S6 D) H1 K    <tr class="bgc"> 1 C( U: ^, b0 T9 i% b0 I
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
, c' D% E( z+ R: |9 r  </tr>
( k( H; C+ R& Q5 R" z9 I0 ]( e# q</table>
( i% p; P1 R/ j$ _6 M# N</form>+ H% ^  \8 c1 U# \  f
<script language="javascript">" o# \5 V+ U# {( g! |+ F7 e
//人名移动
$ [1 ~: ]8 N. u0 q# b+ N5 M2 s  L  Vfunction move(fbox, tbox) {
; L7 ?! {0 T% y" t0 kvar arrfbox = new array();8 b" v7 l0 O3 _: W; |0 G2 T+ W9 i+ U
var arrtbox = new array();% ?" T% z% p0 r, t+ ~
var arrlookup = new array();" ]" H" g# i2 I/ {4 n% U
var i;6 O# D/ B+ P- m' |& Z, N; Z* d
for (i = 0; i < tbox.options.length; i++) {# |! B5 ~) N% I. @! s: [# M7 q3 y
arrlookup[tbox.options.text] = tbox.options.value;
1 S. D9 A" U2 l0 d- B# d5 Karrtbox = tbox.options.text;* @8 f& |, T: A2 o; w3 v  W
}
. b; ?' g6 u, U: V: Cvar flength = 0;1 Z- J" V' o# w' {5 Q
var tlength = arrtbox.length;4 q: {! X' S' L4 h9 R
for(i = 0; i < fbox.options.length; i++) {
0 F# e$ d5 ^% K! {$ iarrlookup[fbox.options.text] = fbox.options.value;
8 ]+ ~( I. g# K! Q# E/ A* r8 u2 zif (fbox.options.selected && fbox.options.value != "") {  c7 y% v% a' A4 O
arrtbox[tlength] = fbox.options.text;3 }  X. t' M4 y3 H& U! V2 y9 Z
tlength++;0 X1 w+ \0 g1 H9 b1 c- O
}% W: D8 H- k7 i7 P& R+ o$ g8 P+ A
else {
/ g* X* O9 w) q2 \9 aarrfbox[flength] = fbox.options.text;+ J5 O/ B, l6 q! F6 e
flength++;
7 L6 B  s8 q9 A   }, e& d% u; A# S6 \6 p9 H
}, q; N/ b5 n% I
arrfbox.sort();
' Y2 Z' ~$ X: m# E! ?( a2 d7 Sarrtbox.sort();$ {/ b; X1 q  {" X0 E: s% h
* D! r$ l6 J4 J* P4 C% p+ J
fbox.length = 0;
9 d* P  {/ y% atbox.length = 0;0 ~5 S* }9 s, ]* h0 ~
var c;; P# K0 V$ ~6 A: `" t% `
for(c = 0; c < arrfbox.length; c++) {. L5 o8 ]4 ~2 b+ t
var no = new option();# x! b. a3 V2 K/ T
no.value = arrlookup[arrfbox[c]];
7 Y8 J4 ^/ n  T% j, U  y$ h  cno.text = arrfbox[c];4 R2 m1 c: A$ f& D: E3 U" S
fbox[c] = no;
1 @$ _- A, S, q- x( n. N3 {}! B. B( ^- R" z1 z1 E3 W* q
for(c = 0; c < arrtbox.length; c++) {
9 X" E0 x9 `8 T8 l! ?var no = new option();
6 w$ |4 e5 }7 [no.value = arrlookup[arrtbox[c]];
1 u& d' {* a0 P8 ^5 `no.text = arrtbox[c];2 {; L2 Z/ o3 E- L
tbox[c] = no;* O$ R4 O) B) X0 L3 G& E
   }
- s/ @1 E7 n/ s( ^! Z. {( Z, S}2 \  D* S5 a9 d5 A4 Z! s  H
</script>( b# p0 n+ h2 F
</body>
6 t1 g& n: q8 y, ]4 B) ~8 O. {

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