标题:
jsp+javascript打造级连菜单
[打印本页]
作者:
admin
时间:
2007-12-5 17:43
标题:
jsp+javascript打造级连菜单
<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
# y/ T. E+ l2 m2 f
c pageencoding="gb2312"
: B8 e% Q0 J% ~ s3 e
%>
4 A6 O: [0 @0 a/ F% L
<style>
1 U( F; T: d- J0 ]' [: r5 D3 y
.f9{ font-size:9pt; }
/ n+ O5 P4 }5 s U
.bgc{ background-color:#aecaf9; color: #0033ff }
0 ?7 Y/ V' [7 n- h* B
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
4 I6 H$ S* M2 c5 u7 A! d
border-bottom: solid 1px #4e7dc1;
0 C0 L* {8 V7 p1 |" h# s# k
border-left: solid 1px #aecaf9;
* O- Q3 b9 j6 e3 p" X; V
border-right: solid 1px #5679bd;
/ T" A* T& c2 m, t1 U4 d; B1 ~5 j
padding:1px;
9 j2 U8 M8 }. D7 a# b: w" C
margin:0px;}
) D) Z# l5 l5 P, W
</style>
* J% E6 n5 P+ p# v4 d; U
<script language="javascript">
+ x" I! Y% m% x: [
<!--
& V2 j& e1 e& i, j! d
function rv()
8 ], u! K4 J# P/ u- ]) [3 K
{
# X( T$ a0 F& f% \+ s' t( w) g' p
var val="";
1 J J- h, K1 F1 i/ ` x
for(i=0;i<combo_box.list2.length;i++){
) M2 s' q$ x" W N7 Y0 N
val+=","+combo_box.list2
.value;
$ v3 J# b/ B1 H
}
- K' o' ~ ~3 ^8 c* }* E) y
if(val.charat(0)==","){
. m4 D( {- \6 e6 W
val=val.substr(1,val.length);
4 V O! B ?: P
}
4 k }! F) m" ], m
opener.form1.frecname.value=val;
( L8 \5 i _8 b
self.close();
4 \7 a5 v% H) U% r' f0 Q
}
( M: B! w* b0 k5 j% k
//-->
9 k" _9 t% \# h
</script>
; t/ G1 H- T- B: d4 d
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
4 `5 ^# D8 [* v/ u) ?
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
* g; V. }( n! {& \* T
<%
& C5 H$ b" o8 \( b V, d
cdatasource ds=new cdatasource(); //数据联结bean实例
5 H5 U" L3 P R9 R; N4 [
java.sql.connection conn=ds.getconnection();
; G1 i* u6 C! T Q2 B
java.sql.statement stmt=null;
% c) d4 g+ ?( H, _; n+ l
java.sql.resultset rs=null;
6 h( d; P" f) j, i* h
cdatacheck dc=new cdatacheck();
, T. }- k# R* ?" I; L
%>
: e1 ^* C- L3 Y& E" h S& j$ }
<%
. N: y u0 \5 D" x
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";
- N/ y( M5 S. ^2 m: M0 s8 j) T: ~: ? }
stmt=conn.createstatement();
x! C. `/ d8 C3 B0 \: U
rs=stmt.executequery(sqlu);
5 H( J4 [; w$ U
%>
2 Z' \! r: |( F/ o
<script language='javascript'>
6 B6 p& K5 _, |/ T% G6 D
arr = new array();
0 Q' K5 R" |4 I7 g0 v% E9 {
<% int temp=0;
& M/ m2 M8 }, I3 k0 n1 ^# x
while(rs.next())
1 i7 b# ^: W# L+ u
{
# b$ O9 b; Z t! X9 e1 E8 ] P
%>
6 t# H8 k0 w' j) i' e- I' @
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
) N7 r9 ]7 R' |# G
<%
2 `. {& I8 l: b3 @
temp = temp + 1;
* h5 ?8 k/ n. `6 Y
}
$ m7 M0 Q* L8 b( _
%>
" m i9 s+ d; X
temp=<%=temp%>;
( c' r2 c, D! O2 `
function changelocation(id){
+ ]1 v+ V M+ ~. b9 y2 |9 d
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
6 s" x: R5 A7 h
var i = 0;
/ g' W( W% z! E" ]9 D7 f8 @4 x
document.combo_box.city.options[0]=new option('-------','');
- i4 G; u6 A8 J- r2 J1 v+ P
for(i=0;i<temp;i++){
9 t' N3 k0 b1 _+ v. z
if(arr
[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
" O) C/ W0 {( Q, u/ O, S
document.combo_box.city.options[document.combo_box.city.length] = new option(arr
[0], arr
[0]);
% D# ^9 C9 Q' C7 D z0 J0 x3 p
}
5 h4 _2 A* d, ?+ ^& o& \+ B
}
9 K9 F" o" y# M! A7 U9 ?7 ^7 g6 Z' k
}
, B2 c3 X+ u2 `' P S9 Y
</script>
9 n' F9 D0 A1 d
9 P( @7 B8 y2 t ~
<form name="combo_box">
! B/ {' ]! w* ?# t8 \" L
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
! O! m/ X( a) r$ C; N; J9 [
<tr height="24">
7 z; {$ U6 e" T: i, C$ K
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
7 h5 F2 q2 D7 r0 f2 Y
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
+ `; d8 Q8 Q- j% {
<td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
# z& \( y* p9 M- ^, V: I9 u
<td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
* V1 B% F) O- x+ S* e6 @9 i
</tr>
4 }' E6 T4 w/ G
<tr>
( p- y# T. q6 S" J
<td>
' J- f& j( Z# r' R
<select multiple id=prov name="prov" style="width:150;height:200" class="bgc">
, z& s4 N% v6 q4 h
<option value="0">请选择部门 ---></option>
1 |7 B( P/ b) I' o' c7 w
<%
+ s/ A9 e8 v/ b t: E; v
string sqld="select * from tdept";
3 t9 G8 a9 R0 N5 z/ p
stmt=conn.createstatement();
5 n: y" t8 |0 f. y/ r; e0 {( D
rs=stmt.executequery(sqld);
6 {. G w* t8 U! `% R
while(rs.next())
- c7 l/ h4 R9 @/ M2 s
{
4 X7 t9 E2 G- i# j0 l( j0 \
%>
3 p' j1 n9 ~/ e
<option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
: n. T5 z6 R0 w3 m+ f
<%
( Y. h6 ^/ V g& `" R- o5 P
}
3 Y- q( s+ |% i1 b5 \
%>
; ]0 ]6 r/ o: X! @! ~
</select>
" t2 p+ E! ]0 T: \, ?; x/ }
</td>
" W9 ^& @) L. h( s
<td>
3 L4 G) O9 p- K4 d
<select multiple id=city style="width:150;height:200" class="bgc">
! ]8 ?6 J8 i2 o+ u
</select>
7 z" Z+ ?/ F2 D9 M( o
</td>
% ?" }% w) W' T
<td nowrap align="center" class="bgc">
4 ~9 R1 h' u! r: p2 o d, L3 F# T
<input type="button" value="<<" class="buttons">
8 X, \. W# X' c$ T
<input type="button" value=">>" class="buttons">
$ B, [( O5 W- P7 r9 Q- e
</td>
- S4 z& j7 F; T- r% ?
<td>
; R& O# J6 a! t0 i( m
<select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
& z" P8 V2 V( J
</select>
* ]) c. A4 l: `, Q/ x
</td>
) q3 }' |# Y7 O+ s& Q! e% @
</tr>
6 X8 \) _0 x0 f8 f3 ^
<tr class="bgc">
! c* ?, J O) Y
<td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
9 J, L# v0 W# R8 v" ]# s! }
</tr>
# Z4 h. T1 D G. C8 L
</table>
* u7 l' o6 u( t0 z4 m
</form>
' U6 W8 h' W" N, V2 T1 S5 u7 m8 U
<script language="javascript">
9 z$ c) s5 r" y8 l5 d* k# M R
//人名移动
/ w9 j* K5 }2 O3 f
function move(fbox, tbox) {
$ C h9 c$ H" o d
var arrfbox = new array();
2 ~4 I. Y. h- V' V- N! ^7 K
var arrtbox = new array();
. a4 o' `, C& C8 t8 w7 v+ I0 z' n
var arrlookup = new array();
, d1 h! Z5 o; H# R
var i;
7 v1 i) s* p" @, @
for (i = 0; i < tbox.options.length; i++) {
3 D4 c# O6 C* O
arrlookup[tbox.options
.text] = tbox.options
.value;
7 H9 A* {+ v8 y4 p7 Y
arrtbox
= tbox.options
.text;
6 O. Z: ]: U( }7 @
}
/ |, G$ r! i+ B) {
var flength = 0;
0 n4 o7 w" S/ k& j- t0 q1 k5 i
var tlength = arrtbox.length;
9 d3 }4 H2 b) y9 t. I7 P6 k
for(i = 0; i < fbox.options.length; i++) {
5 {: v+ ?$ r2 A- b$ `7 D. _
arrlookup[fbox.options
.text] = fbox.options
.value;
$ N. y, `$ j: c2 A' f
if (fbox.options
.selected && fbox.options
.value != "") {
, d& i0 G0 z: F$ E% i
arrtbox[tlength] = fbox.options
.text;
/ ~2 ?* q- ]) m
tlength++;
% L, c/ {4 w$ J: P3 `& `; C
}
q% V3 R* M' k9 T1 x7 @
else {
' e. f. }: _4 z k9 b
arrfbox[flength] = fbox.options
.text;
/ S4 S* l0 W" \1 o+ b" a$ y( ~
flength++;
1 S. V: g; S. S% V; i4 [- m; e
}
- K3 m6 {0 r! y- o
}
1 i& F& N8 e$ m- q' x
arrfbox.sort();
4 {$ q/ O$ n, k$ B4 z: g' A
arrtbox.sort();
! G$ ?1 H$ K, \- t# R$ M0 E+ N
& g U' J: m0 Y7 e5 i4 K6 _. _) ]
fbox.length = 0;
* M, q6 j0 a2 B" c; K2 c$ W( t
tbox.length = 0;
; C% T* y3 l% Y! }' F+ ~/ M( Y. s
var c;
8 s+ W+ s4 z9 x6 a1 j2 d2 Z
for(c = 0; c < arrfbox.length; c++) {
# Q: N5 ?) I- y, }1 K& T- `$ z% m* @4 S
var no = new option();
' e* i- m( ~2 w/ o- A5 R
no.value = arrlookup[arrfbox[c]];
H r( t5 ?6 B+ z. y. e
no.text = arrfbox[c];
# d, y; O2 R4 L2 o
fbox[c] = no;
; m! ^8 A5 h2 E1 q! O; x# J7 |
}
! z% i8 n( S$ U, t3 @
for(c = 0; c < arrtbox.length; c++) {
& M8 t6 ?+ e( W4 |! k
var no = new option();
, Q* |2 ]# S6 e- `- k! n* D
no.value = arrlookup[arrtbox[c]];
7 M1 {+ v1 e* r( n# R# ?0 y
no.text = arrtbox[c];
4 O6 P# X: q5 L5 |
tbox[c] = no;
% C8 I7 p& E. ^9 e
}
# L9 Z# I) N4 S7 E6 m7 T5 Q/ {+ O# \0 U
}
4 s+ L9 W* H. F9 Q5 f0 x: w1 M
</script>
- |3 M$ d4 T: |( ]8 x
</body>
3 q u" [. R+ J4 m& t; ]2 V; O g
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2