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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"  \' ?0 c, h9 W7 b/ w" B. @/ T8 _
         c pageencoding="gb2312"4 _) W. _/ z; z
%>
9 E) [! f* F/ A; u3 n" c. \9 e<style>1 D4 u. d# \% V
.f9{ font-size:9pt; }
) v' q- T, I1 R! \" N- R' a.bgc{ background-color:#aecaf9; color: #0033ff }
2 v- t) b9 _. D.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
- n+ `1 U1 J6 x7 T) I  border-bottom: solid 1px #4e7dc1;% E5 L) i& D& ~' f
  border-left: solid 1px #aecaf9;3 A. {" U5 y6 I4 P+ Z
  border-right: solid 1px #5679bd;. T+ G% Y. z1 c! ^" l6 X* e' {- L. M
  padding:1px;+ w, A5 a* Z: F6 G2 j+ J5 b
  margin:0px;}' D0 n* }" d6 O" @3 I$ s
</style># S% L. W' @, m. e" v
<script language="javascript">
2 d/ e5 Z# N% T<!--5 ^; R% _$ C4 X' Z$ J4 l& M8 M* t$ Y
function rv()- F4 v$ {1 w) i5 x# O9 t( ]
{
- ~: G+ F; O# K  var val="";
- M) V% [& V+ J' A* `, a$ H; N  H  for(i=0;i<combo_box.list2.length;i++){' I4 i* k7 [1 F9 w' Q  {
   val+=","+combo_box.list2.value;, \. K% j% ?8 s, d7 p* s# S3 I' d
  }+ x2 N1 S3 d+ C  u
  if(val.charat(0)==","){
8 j1 G0 m" g& l0 D2 k# v   val=val.substr(1,val.length);6 i: F' o# ?2 S5 c- }  P
  }. E* M& G3 L9 z4 R' S' f! M# e
  opener.form1.frecname.value=val;- E) l- W% N& w8 _. m: o0 T6 X  Y
  self.close();
. k# k0 ?+ U+ b. d1 |}# [3 g: H; ^4 p  \* ]: E! u
//-->: d/ p7 l2 k, B! o# g3 ]% l
</script>2 p8 ?3 H* g1 F) }( L0 q
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">& Y) \+ n4 K3 l" B9 O$ F
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />/ s" U% a0 v# h# Q
<%
/ e: s0 m& @8 f2 A& y- R+ X' u  cdatasource ds=new cdatasource();  //数据联结bean实例
  N: ~9 p  S6 F  M( i$ L- b+ @3 O. o  java.sql.connection conn=ds.getconnection();
# b% H' y' S2 M) M: E8 [  java.sql.statement stmt=null;
" e$ R: E" U3 P$ l# n  @  java.sql.resultset rs=null;
7 v8 U8 X. ^, b: _+ i; G1 `7 D4 c) d$ I  cdatacheck dc=new cdatacheck();
. I% I: u' Z2 D/ ^%>
0 [: L9 _  C! E$ v& q<%
7 d: }! Y8 n+ h. U4 h& lstring 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";" T- r; F6 h0 C/ U5 ]+ X
stmt=conn.createstatement();
1 z+ u- r2 Z: Drs=stmt.executequery(sqlu);: J; z5 a) L% M7 w* {0 c6 e: e
%>" j6 k9 t7 S2 ^
<script language='javascript'>- t9 I. i9 C9 O$ C; Q9 G
arr = new array();
( {6 o3 Z& d- f6 B! ?9 M<%  int temp=0;
; J# [# D* f+ ^while(rs.next())+ R# x2 S6 p' M1 i) ~" P9 o
{
6 u. Q% x* f  G/ ?%>
$ K; a. o4 `8 D6 |arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");3 ^+ L6 i/ r# g2 u
<%
  v' I, ?8 b1 `9 R! Ftemp = temp + 1;
/ y1 R8 u- D* H2 N$ i& y}: |1 ^& F8 |. ?
%>
) O4 u+ r. |8 Q4 i; W6 Ytemp=<%=temp%>;
% o8 q/ t5 f+ k3 _function changelocation(id){ $ x# c/ {3 X, I& K
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 $ N3 g! \: w0 e; }. [0 k
var i = 0;
' D1 p6 F  L6 D4 D+ Adocument.combo_box.city.options[0]=new option('-------',''); 1 K6 K* U4 ^3 q
for(i=0;i<temp;i++){
0 r. k& D& d7 r3 F  F) R) K+ Hif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] - K& _' k& D( ?
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 8 O: t3 G% L; [5 j' [
} . i0 a/ b) S6 A" x; ~, W
}
0 r3 e+ {2 F: c# g- [& H} % a7 [  @& {$ b9 `8 a4 X. c9 x
</script>- K' Q5 B6 Z7 F1 N9 I
" v9 Q& {! O. A; {# n
<form name="combo_box">7 K+ F2 o7 L4 t+ Q
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">/ R7 z; A) ~4 T* ~
  <tr height="24">% o* @. S" d. }
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>7 C( M( ^" M" F' _5 U
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
3 t$ g# j8 o0 F2 B    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>: [, ^) `! D# `1 `
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
5 R/ O- _' H# N  ]# S1 c  </tr>
, F- R$ x- ]5 U; h3 ?+ g8 h  g  <tr>
  y9 i* G9 `7 e$ q! V    <td>' u) g1 {/ h, |5 B* l
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
% I& J1 A) f# `: k/ l7 ]  <option value="0">请选择部门 ---></option>! A# ?' a6 W4 |
<%* T1 c: H+ x, T: w# V" \, \
    string sqld="select * from tdept";) p1 a/ c5 t! r  \' K
stmt=conn.createstatement();
( y, v  g. V( x! y. ]) L2 V% p) hrs=stmt.executequery(sqld);
0 K2 J2 _: S/ wwhile(rs.next())
- [- v6 F$ l: d2 R9 o{2 `. q# S* D: \8 B9 d9 K! p4 ]
%>9 G7 {( k& ?: F
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>* G& j7 f7 H# `
<%
. _" l0 G) e4 P" y3 S" v1 X. x}
4 Y% B* B. F! B/ ]% L, [9 ~3 f%> & W* {3 t6 p: _. a$ [4 U
  </select>
+ r! v  i! i. g' z7 N</td>: G  M! r/ K. Y! J0 u1 v, X/ |
    <td>( d  W$ i$ F& X* {* R1 H5 F8 w
  <select multiple id=city style="width:150;height:200" class="bgc">7 Z9 y  M+ e: Q8 X" W
  </select>
: K& R8 k$ `4 ^* Q</td>
% e6 n. f: O% k. n4 X    <td nowrap align="center" class="bgc">8 v. o. N" C6 [' Y
  <input type="button"  value="<<" class="buttons">
6 ]. w  H: G) @  <input type="button"  value=">>" class="buttons">; F% Z+ Q! [& ~. c$ o4 T# G7 j
</td>- ?0 w6 p, [* e3 V, u' \1 C& B# r
    <td>% ^4 o* W) A2 g* _% o
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">& C! r9 X5 f$ A) f3 G
  </select>7 w: i$ {# {; E6 k! j% P1 c
</td>
+ X  H0 ^4 D- \- |3 a. x; _- W3 v  </tr>
# e0 \  I4 D  n' @% S    <tr class="bgc"> ( s! U  D8 g) x' Q+ \* V1 q
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
, j# \4 `* I" i6 S$ [  </tr>3 k$ q5 l. G+ R# P1 n* u
</table>- E: X7 e( c5 X7 g/ x
</form>
8 h- }: {2 M6 o1 g: X) T: b<script language="javascript">
. g$ U4 p& u2 U. L1 v# W5 f: G//人名移动
1 |, }) y3 {; k, t: qfunction move(fbox, tbox) {
- f7 {: {" [8 I0 f7 |/ Vvar arrfbox = new array();
/ g& j" {+ p/ H- t6 p8 h- o7 A( ?' L5 jvar arrtbox = new array();0 c" i% Y; W. w5 }1 L
var arrlookup = new array();
4 b0 Z; f: B, B& P6 e1 _var i;
9 l. d# c4 k& w2 |6 `* G6 U6 c/ kfor (i = 0; i < tbox.options.length; i++) {5 J$ D: E* C; ]' P$ ~# n
arrlookup[tbox.options.text] = tbox.options.value;
$ o) S' h5 B. C% D7 Jarrtbox = tbox.options.text;! e% u* ~9 c$ {( z
}9 ^0 v! D3 s) H( s+ ^. V
var flength = 0;
2 k. x. ^% c: |* Dvar tlength = arrtbox.length;
% V6 z+ k- I) \. lfor(i = 0; i < fbox.options.length; i++) {9 o! m( w4 K! s& T( }  e0 V
arrlookup[fbox.options.text] = fbox.options.value;2 g, O8 t* t- g/ c! s) v
if (fbox.options.selected && fbox.options.value != "") {4 B; ^0 A/ |0 B5 [
arrtbox[tlength] = fbox.options.text;3 z9 w# f' n9 x# w4 j9 J8 c; m# `
tlength++;
! @) ^# ]+ b8 o}
& {2 w6 C; `# P. N/ jelse {; I& v  ?2 q4 }2 z1 Y( z" y, P
arrfbox[flength] = fbox.options.text;
- @. x1 `6 v; b3 W7 pflength++;0 a! y5 R/ r6 m( I$ {# ?6 j0 y% _
   }( `7 S& F( X  I7 E+ k  l- B
}0 _+ g6 f% ~# q: I7 T
arrfbox.sort();
. q1 ?% j5 K+ [' d, R: Earrtbox.sort();
7 p, T0 f0 g( L0 W
# a* A& M8 N. I3 Efbox.length = 0;
" j6 k1 M" l  o8 h9 \+ z- |# Xtbox.length = 0;
! U4 b- g1 F7 w3 ]' F* ^& ~var c;
9 Q  z: \, v% c) V# u! Q0 tfor(c = 0; c < arrfbox.length; c++) {, c- c# \2 e+ p  w* W' t" h' r3 b
var no = new option();
2 K: y- a4 A( Ono.value = arrlookup[arrfbox[c]];! w  M( ~4 `* v5 V! @2 [
no.text = arrfbox[c];- S8 Y  y1 x3 [( W; ?: E
fbox[c] = no;
' R$ f6 n; N8 G. N; ?: f, b! x" {}3 w5 K( ?( d7 k
for(c = 0; c < arrtbox.length; c++) {
' T7 T0 o) Y) S6 v8 q7 Wvar no = new option();/ [, i9 `7 i) v0 C; f7 n
no.value = arrlookup[arrtbox[c]];
" G) i* v1 n8 }5 S. m0 yno.text = arrtbox[c];
& D0 H3 Z1 Z" O3 F" ]tbox[c] = no;( f3 x' C/ P; ?( M. I, z
   }
& j: k2 d, H7 ]( Y0 s: A}' d) h+ H& H, v% R2 R' z( z
</script>
; t$ g% |4 V% k! u& j$ U</body>
. h  Q; c$ O- R; G

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