返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
+ O# n" e! i, U9 `2 V/ t: w         c pageencoding="gb2312"
" K9 N" I& E. t) P%>4 k% @2 R3 u4 v' m! Y2 A
<style>
8 _( d' a# U& b4 D! I" u4 ^$ a.f9{ font-size:9pt; }
$ ~  G( m+ N8 n  P" o; N.bgc{ background-color:#aecaf9; color: #0033ff }
" `/ Q1 V, [9 F.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;" z* ^1 K  p- u/ f+ S4 `1 @- s, k
  border-bottom: solid 1px #4e7dc1;
" Q1 W8 `' S9 ?& @  border-left: solid 1px #aecaf9;" t  h, j: z& J. ]7 I
  border-right: solid 1px #5679bd;* }2 ]2 ~$ q/ B( A' A7 d
  padding:1px;8 q' i! n$ i" r, y: m" R
  margin:0px;}
+ [0 l- b3 Y$ F+ N</style>
: @! u) a8 G$ Y; i6 W6 G4 S<script language="javascript">
: e# e" S2 L* M# ^3 q& M<!--- O) w7 K6 ]. V
function rv()1 ?2 h+ z8 @2 o
{
5 C- q0 W/ s" T2 |  var val="";
& W  g  C: d: Y# H( w  for(i=0;i<combo_box.list2.length;i++){, d7 {: i0 ^4 \' g! K
   val+=","+combo_box.list2.value;0 L2 O  J0 Y' ~+ r5 g# V. c
  }% i& T  ?9 _( O* s4 I# S2 b% x
  if(val.charat(0)==","){; Z8 N9 m" ?8 E( F
   val=val.substr(1,val.length);
1 ~7 w2 f/ P; p8 @  T  }
- O0 |9 a6 W( h  opener.form1.frecname.value=val;# t* N0 ?$ k- A3 f- r5 y! e/ d
  self.close();
0 V! x1 ^) Q# x5 i8 N! E! F}& q' f% A$ h3 a- t
//-->
% H( e9 T; W* a0 h) ^+ e2 U! s5 r</script>. I$ t+ Y( W; I) e) v& o9 y; s
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">6 ]2 t, R* B1 B
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
2 X( s) e$ ^( Z5 d4 W( C  N<%- B" q4 r0 b0 p/ i. o" r7 F" i* Q
  cdatasource ds=new cdatasource();  //数据联结bean实例
: T2 V  }9 h7 q! T2 A  java.sql.connection conn=ds.getconnection();4 h9 d2 R) N- W/ I$ ~9 D
  java.sql.statement stmt=null;" H4 S1 i; j+ j9 B8 y! S1 I
  java.sql.resultset rs=null;
' F' `2 m1 X  B6 V. H4 {  cdatacheck dc=new cdatacheck();
1 G/ A- [( B$ b) v' a( o& a3 ~%>
! p9 i" G6 U/ Y<%9 ~, P! [; y) o) b1 Y
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";
7 [3 ]0 g2 Q/ K. J/ fstmt=conn.createstatement();5 d. @3 b  ]6 q; \2 ^
rs=stmt.executequery(sqlu);! t+ D5 P# i3 x3 [! n
%>7 ?4 ?4 l: q8 x! j# F4 h( P5 i
<script language='javascript'>, U% {' O& n. Y: u5 [- I1 Z
arr = new array();
3 L: @' J6 P, E& v% s2 ]" R<%  int temp=0;! e5 b! m2 C! U( R1 N! ~1 t7 k; v1 W: F
while(rs.next())& p/ h& n" G# B+ u
{# n! K0 w" n& O$ c5 |# s) ^
%>) P% t& s- n/ G! L9 B, f: M% [* {1 I
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");0 ]3 [5 t3 f( e- N+ w( f: X
<%
0 \2 ^$ a* N" b) V1 {9 _temp = temp + 1;$ U6 J6 ^# U; x
}' u7 p2 J0 O: ~0 [# V
%>
7 E! |1 \, A4 Q; xtemp=<%=temp%>;
7 P5 N$ L( {4 ~+ b5 A7 }) m' sfunction changelocation(id){
3 J( s( K. s" Idocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
& }; y" \. W1 z! C; @# Lvar i = 0; 5 h- i- @4 v- L8 W1 \% C$ U
document.combo_box.city.options[0]=new option('-------',''); $ _4 B8 ?* S0 _$ B, g; I
for(i=0;i<temp;i++){
- a4 \# V: V& a* n# e# d! F+ Eif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
+ _4 `. l# B, _; Z9 ^( D" Gdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); ) ~; E6 U% w& V  b
}
8 l: c0 Y& J) d4 r} * a  k' u/ h0 T% h
}
: |9 r4 O& [( J9 r% r9 [</script>  W. r* a- l. M  S$ T8 \

% J9 {. U) E9 {/ |# c: b<form name="combo_box">
/ M" y5 |4 \( M8 K) q<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">7 F6 h) L) R' y/ ^% B5 ^5 X% ^
  <tr height="24">+ ]: n+ A& G& Y. ?+ m5 d) d  |
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
/ H, V. h: Y5 \& b2 e% B    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
/ {) m( i  I, t0 X0 V    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
, h" G# w8 O. k: {    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>0 }- X1 T; T; z0 m8 I
  </tr>
- L1 j$ q3 n0 L( M% Z2 ]  <tr>
8 n4 H4 X/ \  }! m1 X8 x5 m1 q    <td>  m" A4 ~4 i) l: y2 |
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
8 e6 n' L7 q! X* F7 `3 S! J5 @4 l" J  <option value="0">请选择部门 ---></option>
6 N& H( i" K6 y% f' N<%
3 P0 ]/ t; I# F1 f+ @    string sqld="select * from tdept";* ]4 }" L. U4 j4 d; Q# {
stmt=conn.createstatement();. N% P- q$ m, I5 {9 D
rs=stmt.executequery(sqld);* T; J: O$ Q+ `9 T; n
while(rs.next())) |, J* n! N% ]5 B% W! u, M& ^1 U
{2 M) z( u& [2 Y8 G
%>8 {# ^# H* B! L+ y! y) x
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>% T* j1 W7 @, e
<%( G# H5 E2 n- S2 h0 `( f6 J' c
}
: p; \' n7 p" P3 g%>
! e3 s! F- I) w' V; O+ A  </select>, v+ p7 E4 \2 M2 q
</td>) y9 j" l) U4 {# S7 n9 O2 E  X
    <td>: h( {/ t- l- U( h2 J7 e7 ~7 b2 @7 A2 m4 p
  <select multiple id=city style="width:150;height:200" class="bgc">& N$ X8 d' i/ \
  </select>: S8 k  s8 d. @8 ?  M9 }( O
</td>
( k/ V4 d' G4 a# Y7 `2 Q$ [( l% p; Z    <td nowrap align="center" class="bgc">3 y5 Z. w- @; G  z) t
  <input type="button"  value="<<" class="buttons">
+ j* k* H2 q) _8 u, |  <input type="button"  value=">>" class="buttons">/ }& {& z' v% H, |' k+ A. |: }
</td>
7 D! b. N- A( j& [+ x" k    <td>
3 t( R) E- m! _8 k1 q& L9 O3 D( j  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">+ g& z* M7 N6 b# M4 s( P  t
  </select>; R  T+ k, a3 U/ i& H- ~0 ^
</td>9 k" p) n# m; y% G" B/ P  I
  </tr>
4 B# p% T8 e0 G+ J7 N9 w! ]    <tr class="bgc">
$ z0 t2 N! Z0 t, ^& V' z; T    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
8 x) K/ s8 E. z  B  </tr>
9 P) s) v* g' c</table>
' D$ I9 o; h) i& P4 D* w0 X; k1 S</form>9 v/ ?$ {  V+ q6 J1 Q0 x2 }& X# t
<script language="javascript">
6 k0 j- A. R! i- O9 M: n//人名移动5 [" d2 D9 x3 J( W1 X2 ]( i; J
function move(fbox, tbox) {
  }0 n* ^3 H$ A+ Mvar arrfbox = new array();
$ {3 i1 Y6 M' ~var arrtbox = new array();
1 \$ v" G) m, V/ B& u5 J& p+ Rvar arrlookup = new array();1 Q# v! r; U+ \1 C' V
var i;5 J2 p  b2 Z& n  o
for (i = 0; i < tbox.options.length; i++) {
/ P: ]- \' g' F7 Y* Q6 {, e' garrlookup[tbox.options.text] = tbox.options.value;
" q9 B( ]/ u3 garrtbox = tbox.options.text;
! l: u9 B' D4 T7 M& R, d  X}. w" [; w( |7 H: ?: s
var flength = 0;/ I, K. s3 O: W1 |) T
var tlength = arrtbox.length;* B' C' S7 e! K9 ~9 O3 l
for(i = 0; i < fbox.options.length; i++) {
* ?9 T3 {1 _* r: h# Farrlookup[fbox.options.text] = fbox.options.value;
* R+ Z: }( \1 `$ U4 ]7 Kif (fbox.options.selected && fbox.options.value != "") {! }" y/ w! Q: x/ a, k3 O/ _
arrtbox[tlength] = fbox.options.text;
" s$ [# N7 a, t: ^tlength++;' }5 J  y* N- e  J+ b# ^$ G
}
' X$ f* B( H; Q! Zelse {/ C6 W" j1 K  _/ Z) A
arrfbox[flength] = fbox.options.text;2 y) U- k& u# B6 B
flength++;
/ [3 c  r/ R8 w0 a) z   }) A: V# V! H9 O3 m( j" P
}
' H+ W* O& S# o* K5 Zarrfbox.sort();
' X$ R/ W0 E  w3 Narrtbox.sort();5 O$ F( d' p8 {6 I% T

% K- G8 u; I& y0 c$ o9 ?0 K& W" afbox.length = 0;
" a, h% U: o* K+ Mtbox.length = 0;
) q% C0 \/ J" |# [var c;
" X* P& q8 o& p" z) H4 a% N% }! N; \for(c = 0; c < arrfbox.length; c++) {1 p4 r4 k! g- l4 B: {
var no = new option();
. T& k* j1 P) W( {4 e9 c7 D; pno.value = arrlookup[arrfbox[c]];- Y8 y) X8 d, j" G7 u" G; d" B% K5 {
no.text = arrfbox[c];2 e1 l0 w' E1 T, N8 \
fbox[c] = no;
: D: Q  [4 {  S( n, s$ o* S% L: V}
* d1 d/ M5 ?) Y5 S5 hfor(c = 0; c < arrtbox.length; c++) {0 _; z& c# F3 z) \  R4 Y; ]
var no = new option();
* Z! s3 [0 [8 w: U5 B5 qno.value = arrlookup[arrtbox[c]];! B9 V3 K( b% y' I  n3 c. [- o+ H
no.text = arrtbox[c];! q* ~: i- P# N3 }
tbox[c] = no;
& B8 D( T4 {+ @! ]   }
( Z( z# U" _0 b}
% M3 z+ A$ K5 s+ H* F1 _9 Z  N6 X</script>+ W0 ]0 N) f+ F0 F- j
</body>
. ]- ~. F) D2 s  J! ~5 |& C

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