标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
, V/ T( @ t# u; z S) c+ a
c pageencoding="gb2312"
* h/ m, ^% j( j: Y
%>
8 V- v h0 K" u& `3 y7 o/ }
<style>
0 d0 T* s* z" g$ o
.f9{ font-size:9pt; }
R0 k7 E; ?5 d
.bgc{ background-color:#aecaf9; color: #0033ff }
2 k& ^/ X' f: `& {& Y$ V
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
! b K) H1 a$ c3 q7 b& ?
border-bottom: solid 1px #4e7dc1;
/ y" `4 S1 ]/ d" K* z( ?! ` H. d3 j
border-left: solid 1px #aecaf9;
. L" `8 O$ C2 b# ]8 ?* N. H
border-right: solid 1px #5679bd;
7 |3 `8 |6 I+ w4 Q6 _" F
padding:1px;
% a5 I i! D: B
margin:0px;}
9 V( K; h7 ~( K6 R$ a2 Q
</style>
9 i7 j0 M8 C0 l/ ]% n
<script language="javascript">
1 W7 M( c: a, B& \$ a( q
<!--
* a. v1 C( ~3 i: X) ]4 v
function rv()
# }* O9 o* L" p) }; @0 \, B9 n
{
2 }, V/ w/ |( S5 J
var val="";
# @$ a9 ]2 j( H2 s$ Y' b7 _
for(i=0;i<combo_box.list2.length;i++){
4 c9 {# ]% i; t- j& l( f; _
val+=","+combo_box.list2
.value;
- [ a% v5 U& s
}
6 L0 O6 u5 Z' j6 [* M8 L
if(val.charat(0)==","){
7 P8 H ~3 t1 W, g
val=val.substr(1,val.length);
$ o: s3 p) ]2 S0 T. S8 s
}
3 V2 m0 R) n' G+ i; d% _8 O
opener.form1.frecname.value=val;
4 g1 {; Q) q+ `9 H" L- ?
self.close();
! s+ m& u1 j- N, N3 z+ {$ F
}
0 N) |1 @$ G4 ^) ]) ?
//-->
& m. L$ h4 A1 d/ S1 a5 e
</script>
! u7 x+ b6 B6 `5 b) U
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
9 G$ F5 d% `( p' a, O
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
" a& K7 P4 N9 a
<%
- k* r# z7 d2 l" X1 M+ h' N. P
cdatasource ds=new cdatasource(); //数据联结bean实例
& K5 k m0 u& s l+ t; T% H Y
java.sql.connection conn=ds.getconnection();
$ s0 B2 d7 @4 @) y1 P% c4 R, P
java.sql.statement stmt=null;
0 `6 m0 X5 q, x
java.sql.resultset rs=null;
8 R; D% H4 s% V5 I6 U
cdatacheck dc=new cdatacheck();
" N# |: |# ?' x0 [ ?/ l$ g
%>
J6 d5 U7 H5 f2 @- T* t: L
<%
5 u/ O0 }( b3 K
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";
% @1 h* {9 v8 k5 g8 Z
stmt=conn.createstatement();
) Q0 H! L0 |. ` I) c4 s
rs=stmt.executequery(sqlu);
, E W0 s0 p! Q6 N7 Q
%>
) g1 J! N0 s0 z9 e$ H% v
<script language='javascript'>
0 R9 M# k, {8 p( }* @# U4 }; C
arr = new array();
, p5 D% s- J0 t% t1 S& O7 m
<% int temp=0;
8 G8 L1 p1 U8 o8 l
while(rs.next())
) F; x9 |9 ]9 Z+ ?% F/ b& b: A
{
3 }; `9 `5 T1 ]) j& E: o
%>
2 E( f/ M! V5 K! q
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
( V1 J( ?4 g: i6 @
<%
- |( V, @8 R& [8 f2 W2 {
temp = temp + 1;
; D" |% Q$ e. ~9 x
}
& L$ y2 B ~ P r1 {
%>
+ S( I7 f% p0 ~$ x* A$ a/ o
temp=<%=temp%>;
3 |3 S# y7 c1 x% U* }) k
function changelocation(id){
4 o. A+ Q/ f2 @0 k
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
" Y j6 p7 }! B( }5 I
var i = 0;
! b# [( y1 X# x; S0 p1 N3 i
document.combo_box.city.options[0]=new option('-------','');
# p9 a% n% E$ e9 F. N
for(i=0;i<temp;i++){
. \" ?. B F2 h& y& W
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
6 ?1 ?0 s" Z. T( R/ n
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
+ j; H; R" U& }) H' y! F+ p4 S
}
/ A1 z7 @3 n2 H" |2 r
}
3 A" Y) S# ?9 |* o* j
}
- R; K' \% [. I: _$ K. a
</script>
6 R! O' @0 m; y G# F
( j0 |. L/ _9 }4 B0 @5 w9 A H
<form name="combo_box">
# H4 i* H# `; L
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
0 @9 d9 M2 X. D- ~' f- G4 b
<tr height="24">
* v- ]% a. G5 s# k/ |
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
$ I5 |4 V& n$ V" k: C a' _: C( k
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
5 H2 q1 @, _0 D1 F# `2 ]3 [! `' B
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
; t/ A0 Y9 I8 P
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
0 I( _8 Y, `( i/ a% ]6 q- i
</tr>
) p8 A1 o( y" D4 ~6 c) ~" r
<tr>
; [; \7 E7 I6 f) U3 w
<td>
/ G; P+ X& y' u4 ]. x
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
( H, p6 R7 ^0 A" a# H1 ?
<option value="0">请选择部门 ---></option>
* I3 J0 e; m0 ?) \5 t
<%
7 W! U) c- U& O5 _( [6 d) p
string sqld="select * from tdept";
+ V7 `: t# L, Y! E
stmt=conn.createstatement();
& B8 S, z$ z: {: f
rs=stmt.executequery(sqld);
7 G3 S) m( M1 u/ s
while(rs.next())
( V o/ \# f; U9 b; b( r* p
{
: U% q( e7 }) x* n. S
%>
3 l( G1 O7 `2 w" `. i$ {
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
. ]" O; I. s9 N$ W- n
<%
7 K$ I# i9 U' T* _
}
) c& n6 a0 L: _, F. q( \7 H+ v1 _
%>
5 o% {- z+ v$ S# L0 v) V5 D
</select>
) x. f% I- G& N0 `. R$ w7 Q
</td>
+ v& k* z0 N( I* q t
<td>
3 f t! m) {& l* s p* T7 g1 q
<select multiple id=city style="width:150;height:200" class="bgc">
8 q8 o' t F. H0 \/ k
</select>
) a. T# o2 O- c, n# r& b% [
</td>
, l4 j" o. O6 I/ c
<td nowrap align="center" class="bgc">
b; A/ I6 w: {; Z1 E7 c
<input type="button" value="<<" class="buttons">
8 e% }1 c: J# ~, {- G
<input type="button" value=">>" class="buttons">
$ z( M( u$ l# \6 P6 O1 z
</td>
$ ^8 y1 \& J9 K) V% f0 L# }1 O5 |0 D! N
<td>
0 T$ e# K6 G' @; L& I/ ~# O9 X
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
& g# W2 v; [8 C* d
</select>
) o0 \) O* s" W3 Z( F
</td>
- \0 i5 V8 t& O9 ], l0 I# _, n
</tr>
+ s# ?# v6 }/ v$ L/ q
<tr class="bgc">
$ s1 ^' O" s% y& G* P; d
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
5 I& X1 \4 Q" j& b. o1 I
</tr>
; i! }0 L# I+ I! `
</table>
0 f; T! }5 E# [6 O, ]! q: z1 s
</form>
' r1 w% Z) u1 Q/ l* J: }
<script language="javascript">
4 N' l; `" o' S* \1 e: J1 j
//人名移动
" m: R9 w) r. R# L: g
function move(fbox, tbox) {
A- ]' k8 h5 g* D* [' l- N8 I2 [
var arrfbox = new array();
6 Y# J6 _. N# T2 J2 s; z
var arrtbox = new array();
6 N7 |( i5 Y% ] T" L5 ^
var arrlookup = new array();
: G/ C# y8 E2 A4 T l4 V- G; C6 I
var i;
# E7 K: c/ G( @, y; ]' X
for (i = 0; i < tbox.options.length; i++) {
% r9 E2 S' d% n
arrlookup[tbox.options
.text] = tbox.options
.value;
2 K% _4 c+ Z% f+ T8 O$ Q1 d
arrtbox
= tbox.options
.text;
8 F, f5 p# \" l1 w8 a* J* t
}
. A# U1 g/ v$ a. i7 V* }
var flength = 0;
5 V5 E$ r" U' o" I0 i
var tlength = arrtbox.length;
$ \2 K- [9 S: \% w9 E( L, [
for(i = 0; i < fbox.options.length; i++) {
$ h' _, Q, x: n% {3 ?
arrlookup[fbox.options
.text] = fbox.options
.value;
' b' ]$ W- X. T4 h" E5 x
if (fbox.options
.selected && fbox.options
.value != "") {
2 ~7 I, `+ \- ]
arrtbox[tlength] = fbox.options
.text;
0 ?. W \" x; l) g
tlength++;
0 A% ~3 a+ w. Y$ w% v
}
; Y* A/ |8 z6 O. z' C' X$ A3 L
else {
8 m7 a; r0 N" N7 q, n# k- R" _* D
arrfbox[flength] = fbox.options
.text;
5 E% _7 p( m% R7 \4 s# V
flength++;
0 k6 p# ~2 o" B" P* K3 \
}
' ?8 P& f( t) x0 z; l" T4 k' l$ R* B
}
- E+ q% w* T) k
arrfbox.sort();
& g, o% S' X/ V( O' R& v1 ]6 S+ o
arrtbox.sort();
( O9 |7 M* {- T. b# {
. c& m+ U* v. o3 g
fbox.length = 0;
" i) L9 N: a; ]9 q" V
tbox.length = 0;
: P7 U2 v+ a) E4 |* V; m4 o% C
var c;
' T0 r! o/ a. f5 Y7 }9 b
for(c = 0; c < arrfbox.length; c++) {
- h3 K4 @% ?/ a. R
var no = new option();
) ~% @5 [: J' B/ M2 R- t R
no.value = arrlookup[arrfbox[c]];
* i9 L' ^% g( c9 i% |
no.text = arrfbox[c];
& M* ]5 K! A2 f5 @; Y
fbox[c] = no;
/ A; F. B& _! Z4 t: Y# G/ m& |6 r
}
$ p _+ m) j1 o6 Y9 W
for(c = 0; c < arrtbox.length; c++) {
5 V) b2 }' ]5 x& x& P3 G' }
var no = new option();
# Z& r- H( J' @7 b8 {" T- s/ P, H
no.value = arrlookup[arrtbox[c]];
0 k3 u$ [& |( s; h9 n4 A8 p
no.text = arrtbox[c];
! o/ W9 x4 g, i' O0 R! F0 L
tbox[c] = no;
3 v, O0 \# N0 F1 D* A& i$ f5 N" I
}
0 Q V V+ a6 C; m
}
+ o( O4 F2 i c# l) |* } b4 G3 y
</script>
: X' o8 M- F) F1 A
</body>
# z2 Z2 h* o2 ~' R2 S/ h; {
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2