返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"9 E% ]1 t' v- ^% ?
         c pageencoding="gb2312"* g3 b- w6 U. x' i: J8 ?# n
%>& o7 Q" z3 k$ [3 S1 z9 z! y
<style>  z: k; X! _! ]8 b3 a* o- D/ w& ?% Q
.f9{ font-size:9pt; }% F$ O2 z% i* ~) D
.bgc{ background-color:#aecaf9; color: #0033ff }2 N! f* {( k/ Q
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
& j0 ?4 [. p7 \5 O  border-bottom: solid 1px #4e7dc1;
4 z8 k- O* M" ?5 X6 ^  border-left: solid 1px #aecaf9;
: l+ U4 D8 ]$ M! m" B, \. q  border-right: solid 1px #5679bd;- ?6 b* S( T$ x0 m. \6 Z
  padding:1px;
5 b9 m8 p6 t* c, |" v2 w4 \  margin:0px;}0 G* b( |+ s7 P
</style>! `, H3 S, g0 h* h- A' J5 G2 q& h9 K
<script language="javascript">
( f0 l; E) `; Z% I6 C<!--2 E: ^6 k9 J- S9 I; n. I
function rv()+ H/ l% r1 K3 A
{
; H  m$ l! D) T/ f3 A) s! }) Y  var val="";7 Y( w; U3 j0 q" c7 \; k9 K
  for(i=0;i<combo_box.list2.length;i++){
, v2 r7 {, c' H% i7 M) Z3 T. p   val+=","+combo_box.list2.value;& C2 V, q! u3 `, d. i
  }0 j6 l2 ?  i. z
  if(val.charat(0)==","){
, U9 }. ]2 S: d0 A   val=val.substr(1,val.length);
! o2 r( u1 o" _- y  }' p8 w; J# s8 Y0 G' m' n: G
  opener.form1.frecname.value=val;
+ E& z9 ]" ~) y  self.close();0 u- t& ]) U3 M' y/ N7 \# @% R9 `
}
8 r8 i5 m# [$ P3 a& E& h//-->
* g4 j( E/ T: Y4 k- Q1 \2 Z</script>
: \. M3 v( N+ O2 I<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
) Z1 f3 ~0 U2 H6 f- l<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />% g4 Z! x5 ]9 N" W' i9 ^
<%
' W. ^3 F, P) I$ Y5 l- l, B3 @) d  cdatasource ds=new cdatasource();  //数据联结bean实例
2 ~$ q2 g! k( J3 w: v5 f  java.sql.connection conn=ds.getconnection();7 @2 @, S: E: T( [
  java.sql.statement stmt=null;
7 I7 s0 S6 l! D! V& K; j6 W+ k7 e  java.sql.resultset rs=null;9 e* a  P; t  S
  cdatacheck dc=new cdatacheck();/ l4 V' B6 e. R+ y: S  U/ z
%>
2 b: G6 M- J5 t1 q: ]5 o! h4 z, W/ U<%
7 F8 ]( {; N$ J6 kstring 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";
- c! _: X& W. K& h, Z/ cstmt=conn.createstatement();
' {3 P$ f7 c& ^5 c; N" B& ]rs=stmt.executequery(sqlu);$ N  `% q2 n5 M6 ~
%>
2 f: D  m6 h5 X5 N4 E$ F<script language='javascript'>% p; P. k; K+ u& N
arr = new array();
8 w5 L; O5 F2 s0 N* }<%  int temp=0;9 z- y* h! G* ~# d' t5 _" k
while(rs.next())" e5 w. T8 ?; r) W1 L& F; o; {
{
- u, g  d/ M0 i$ Y& t& f, d7 `* V%>9 _) x5 Q3 L; z4 t2 `
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
. ^) m+ |  N, d/ G9 q<%
, G* o* r7 |$ V: n9 V8 Gtemp = temp + 1;
& }8 R$ }% N5 b5 `0 n}
8 Y+ h- p! P$ I%>$ R9 B! z' ^# Q- m" |( @/ M
temp=<%=temp%>;
1 @6 i! I- o: e1 Z1 ]function changelocation(id){
' W# |. B, {& F* X# Gdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
7 V; l5 W" E& ~' ?# hvar i = 0;
' f: i: p0 |- T0 ?+ S: sdocument.combo_box.city.options[0]=new option('-------','');
, s8 V& U' T. G6 K, d& x# Jfor(i=0;i<temp;i++){ : T$ S* {+ m0 o/ w* M; S: Y5 \) u
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
' f, I, p& a6 [4 _7 Sdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
' h# `. h! g& v0 y8 Q0 {- {, I7 N} * v& c' ~1 ?6 k8 j( A' P
} + E- c7 ]* w' }
}
+ B& }/ F# z- ~! ~. c& \</script>
9 M+ P" S/ q) t; p8 J/ k2 z5 e/ w3 F! {3 C
<form name="combo_box">
/ f/ e5 u9 {; ^! U( j/ t5 ~<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">' |8 W9 }/ y5 I7 h1 L2 A& x9 M
  <tr height="24">
+ D3 {- F% A2 w" x* _& q0 e: L    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>" j: @# m3 R& w4 E) V
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
5 \# }" x: \* E    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
7 D2 X% d9 _$ p0 L1 n6 z$ R    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>% u- I: ?* A# C+ I% `
  </tr>8 R9 R6 S+ P, c- {  C/ W
  <tr>
/ b2 R/ x9 S8 a! ~# w( U% x* x    <td>
& R& }2 v: t- d  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
' h- h. `  R+ Z6 D) f2 u. s  <option value="0">请选择部门 ---></option>
. S  p( s+ f% g2 `<%
+ ]6 b6 H' y" q0 q; s    string sqld="select * from tdept";/ v) @) x4 x# ?4 O" G- W+ @5 K
stmt=conn.createstatement();
1 b4 B6 X- C1 e% r: ?rs=stmt.executequery(sqld);
( N5 [: O& E$ U; O0 `0 {' Jwhile(rs.next())4 ?) N5 \9 c; u& ~
{, P, r' k" U* r& ]4 d0 B
%>1 F; ?5 c- B! W4 B8 N) i
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>8 W0 A: m- G1 ]& i; P2 o
<%
* ]. a1 b( f; b' g; r1 ?}
8 ~$ c0 v$ J! z%>
" O; p1 j2 x  ^% V- p$ X& c  </select>2 h3 Q6 I. s# I/ L3 R& A6 D
</td>8 `6 w" k6 W3 B$ ]& H6 n
    <td>
: u5 r) f3 N* ]7 @  <select multiple id=city style="width:150;height:200" class="bgc">) r5 ^1 K( E7 ~, p. B- V1 D  \8 @
  </select>
# P) v# z% k) [0 S0 b5 w</td>
9 V0 a9 F% d, y3 ^: K    <td nowrap align="center" class="bgc">+ Z; F. ^' u. v# y2 U
  <input type="button"  value="<<" class="buttons">. m- n, p2 m' {& ]2 V$ `
  <input type="button"  value=">>" class="buttons">
- ]1 _! t; A& h- y8 B; R</td>
7 E/ x8 R( T" V    <td>
! Q. m* U6 N- w4 ], N  k4 c& y  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">7 _8 k6 X: f7 @" V/ X7 Q9 z! T% n2 C0 c
  </select>" g* [4 @7 m/ v0 D. ]
</td>
  |& M7 X, Q" q& o6 t1 I  </tr>, {3 z' B- X" }- Q% a( a
    <tr class="bgc"> / _. Y$ J7 w: A; V3 V+ D' B: g* \+ ^
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>8 F$ M6 o( m1 i) o8 t# A
  </tr>
9 G7 I! t3 |7 G0 C+ Y  b- C. T</table>
8 }& {  l/ ~6 ?( N" p( g( z</form>
5 Y$ I4 Z6 x$ ?, u: C, Z<script language="javascript"># a! |+ }1 ^2 `* {9 X
//人名移动3 `+ D2 j+ R0 a# h9 h
function move(fbox, tbox) {5 [* s$ A$ h& m( d
var arrfbox = new array();
# Q, Z& J$ L/ X" z4 T7 dvar arrtbox = new array();# @% V( v( S1 J1 M0 q/ s
var arrlookup = new array();! H+ L. i- D  G9 ]" ]3 A
var i;
& f, E( M4 c  `; \" Cfor (i = 0; i < tbox.options.length; i++) {* V- L0 d6 r, j6 k$ [3 x
arrlookup[tbox.options.text] = tbox.options.value;
* @/ K, F* V" F" xarrtbox = tbox.options.text;! K3 \" W: D; p! i, ?; }, v' [
}$ [: y& R* A* t! _' M- ?
var flength = 0;2 a0 L8 b9 o6 H$ ?5 X
var tlength = arrtbox.length;
# Y" I$ X1 I% Y8 Ufor(i = 0; i < fbox.options.length; i++) {
. j; p7 U  X# @7 e) i- e- C8 o8 Farrlookup[fbox.options.text] = fbox.options.value;% j) a4 r) R% C; a+ }  Q
if (fbox.options.selected && fbox.options.value != "") {! j6 O' |8 e$ _! n5 b
arrtbox[tlength] = fbox.options.text;2 M) B" \) p6 W( Y, ]% i3 P
tlength++;! g- f- w) i4 r. E0 r) |
}
7 b% m5 B/ d0 X* g! c) |0 P9 {. _else {, W, F( v; W+ J! {' C6 }2 Q. s
arrfbox[flength] = fbox.options.text;( ^6 u. T, D( p: D0 \
flength++;9 i/ C: ~% r9 A+ H2 E  C
   }1 w  F. ]- N( E  K, p$ o3 X  B
}
0 z4 K: k2 i' z, A4 }/ u5 tarrfbox.sort();, X( L% R+ f! o0 ?  Q' b: h
arrtbox.sort();6 h, j7 a0 k9 E% Y& R$ n; D

2 k. ]6 v1 I) A% [/ ]0 \$ I8 {fbox.length = 0;' H* r8 \6 Q& i8 Z2 r  y
tbox.length = 0;+ c+ z4 z2 }5 L/ r! v1 z  n
var c;3 L/ p, |( D) u2 B. c
for(c = 0; c < arrfbox.length; c++) {
! G% H1 R6 O! ^" |! V$ L# Hvar no = new option();* r0 P+ X2 I/ [/ B: W
no.value = arrlookup[arrfbox[c]];- x, c! S5 |7 n: x
no.text = arrfbox[c];
6 N8 H  ]$ e+ t2 `9 k- H- }fbox[c] = no;7 G& P- R. p2 N/ ~4 M; g) ~3 }
}  g6 h; |% P* g9 x& S9 o2 D
for(c = 0; c < arrtbox.length; c++) {
+ q+ k6 S; P# T3 _+ a- Zvar no = new option();* F( `3 Y% _+ \8 K9 p
no.value = arrlookup[arrtbox[c]];5 q  U7 w' G3 m3 C; d( F
no.text = arrtbox[c];: n: Z3 j+ G/ J$ G5 w
tbox[c] = no;) u7 b9 n& `4 ~, q: w5 D
   }
6 {, G5 o- z1 U$ C' n8 u}3 n' V% h% z5 F3 T
</script>; `2 E4 n- d1 D6 {
</body>
- S" H% H& W' h; I3 h  Z

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