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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"' W0 x* U+ {% p% A" _, O, G, t& Q  a
         c pageencoding="gb2312"- K6 E" ?. ~1 T1 Q4 I
%>
* A& U! O. s$ y* y1 p* A<style>
$ E! S8 T/ S+ C+ C3 d.f9{ font-size:9pt; }
# D* f2 N' e0 ^7 i4 z.bgc{ background-color:#aecaf9; color: #0033ff }' q. `: ~7 ~" B
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;3 t! V: P1 o6 W6 k3 n
  border-bottom: solid 1px #4e7dc1;. x2 q* R5 f3 }. r& f
  border-left: solid 1px #aecaf9;- [1 F7 S; d9 Z+ l4 l# K
  border-right: solid 1px #5679bd;! b' J/ ]2 Q( c
  padding:1px;4 }: ]. g9 A" `
  margin:0px;}
& {1 L4 W- V, [2 j</style>
5 J9 X5 z. H! _" @- {$ x( d4 |<script language="javascript">1 ?6 h& r& a! R
<!--
2 Y% K. y5 F# D, N; J1 ~function rv()
* H3 X4 `# E, D% [% L" q, U9 M{
) C9 Q& c' T9 m3 T( d  var val="";
. q5 ?) c* G. B" Q  for(i=0;i<combo_box.list2.length;i++){
1 f, I8 j1 N3 o8 p   val+=","+combo_box.list2.value;
5 q$ Q2 W, ]6 Q  ^4 n- s" O# L  }( o; R7 W! K2 U& D: V9 f+ C
  if(val.charat(0)==","){6 l, B4 T2 N# Q
   val=val.substr(1,val.length);
7 U0 J% a  k# ]8 h# z: ^  }1 x) q, v- T) _8 D$ k  f
  opener.form1.frecname.value=val;) G. c+ o1 P' B( U
  self.close();! C3 `3 b. q; _7 T- ~. \4 M
}
7 b2 V: i8 g8 S& j, a9 _//-->
9 J* r. M# f) F7 X5 I# @</script>
8 k# q/ R3 ~+ V0 ^+ c/ F1 u<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
8 E% o6 e6 b) E( l<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
. ?0 k* Q9 P* f2 C9 p+ X" Z: o5 Z; Z<%
3 E! `$ Z3 m4 {* m) x( N0 [7 }  cdatasource ds=new cdatasource();  //数据联结bean实例
- ^8 C; R/ V) D8 h  u  java.sql.connection conn=ds.getconnection();
2 c6 N* _9 P- R& v- N. M* y7 k  java.sql.statement stmt=null;% E+ J1 w1 C4 V; u. ~. K
  java.sql.resultset rs=null;
) J0 U( A& a; d3 ~2 ]9 V  cdatacheck dc=new cdatacheck();
5 S% S) E0 e5 I: n8 n! E8 x%>
3 }3 T; z5 z' N7 ^: k8 ~<%: r) [! r3 ?" O$ A7 ?
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";
, F6 d+ u. I9 rstmt=conn.createstatement();
  W7 G- {' _" {* Frs=stmt.executequery(sqlu);
5 d& f6 L% b9 \) W, y' G7 f%>
  X, d; n8 i2 M<script language='javascript'>
! l+ a4 M. ?& R& J$ {5 ?arr = new array();5 q5 w* m% z+ p. q0 a
<%  int temp=0;
- _) d7 I8 P; B% K; ^while(rs.next())  u: P! ]& @" Y; G2 t* d; J& y
{
9 o6 O# D4 G+ a6 q+ c%>. b9 I2 J3 \4 c7 ?- Y
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
7 v3 c2 v1 g( ~4 t<%! C9 Q- z* m& F8 K
temp = temp + 1;
% }- F& E6 k7 Q7 m% ]}# d7 L5 c3 G+ J- x
%>
, L( [, L* G8 Gtemp=<%=temp%>;
& ], H/ D9 [. Yfunction changelocation(id){
+ c' I1 L! n) Ldocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
6 Z6 p4 r+ f" r7 svar i = 0;
- k3 N2 j; z& q4 R+ ^) bdocument.combo_box.city.options[0]=new option('-------','');
9 b7 ]" P" M5 ?9 z1 Lfor(i=0;i<temp;i++){
/ a5 d* p: n3 h4 K2 g& v2 Q( _8 @if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] ; p+ {) o* J- Y) z
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); ( c7 D! B& ~; ?+ ~- U- h' _( L
}
+ \. I9 f3 \1 d" l7 o" {$ Q}
% u3 [% X3 f( w% E, Y" N2 I$ }" C} 9 ?- d( n9 [  X& j1 ^
</script>
4 B0 j1 k& _) T0 k" c" Q& Y8 D+ b( W
<form name="combo_box">
* p' h( t, A6 n4 N# y, A<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">! S% s1 t% ~: U4 }8 O6 S& H
  <tr height="24">9 ?4 U) w# H$ l4 y* o
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>5 i, T$ D: [  U( g
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>2 ]' f  }) a  S& S. O/ G: C' ~
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
7 P! ]6 J- `" i    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>1 d4 `' }, I; O6 I& E7 V8 ~
  </tr>8 ]% E* i* k& Q! S7 J
  <tr>   J$ w4 m) ?# f5 T7 X
    <td>
" u4 g$ c& ?- |: N8 A  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">7 m, z1 i) _. f' K
  <option value="0">请选择部门 ---></option>
/ r- N0 R0 H! l& G& _1 [- f<%
8 b. w( h5 P: `    string sqld="select * from tdept";/ d, X' h  Z& o5 C. i$ \# q
stmt=conn.createstatement();
9 |& r9 u/ G! f0 |rs=stmt.executequery(sqld);+ N9 t, o9 L3 N# I/ |- C# Y( Q
while(rs.next())$ g" z( N, g: W9 w& x, J
{
( k+ N9 [  k4 ]; l. v$ `%>( F3 d0 l- E8 E+ q) ^) |+ h
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
6 G/ J/ g+ S# e/ x& ~<%
4 ?6 E' k2 {& l4 @}, M( l9 M8 u# p- k8 I
%>
5 u$ Y5 e. E9 s$ }3 n' W5 ^9 |4 R6 w  </select>. Q; W3 \0 O+ m& r- P; U
</td>
3 p# `1 T/ t7 s    <td>1 v+ P4 Y0 o1 ?# s* l; v" x5 i) ~
  <select multiple id=city style="width:150;height:200" class="bgc">6 U% s8 M% d. |# H5 o
  </select>' x  z! a% D3 m
</td>
8 D* t+ i0 t, S# k/ R% a    <td nowrap align="center" class="bgc">
  Z2 n2 Q: C0 G' U' z( a6 S' H  <input type="button"  value="<<" class="buttons">
' s6 h: k8 c$ R, M- l0 ~  <input type="button"  value=">>" class="buttons">  Y4 T, z  [$ T' r) f
</td>; U1 f0 K# N( U; j. l
    <td>+ N8 Y  ?# J2 z% y8 A- A
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
" a8 K% ~8 x- ~5 d  </select>
2 J8 Z% y" K/ o/ P) Q</td>6 n! C8 Z& u7 x7 K" }3 o
  </tr>
  s$ H4 K( `* M9 b5 O5 Z! |    <tr class="bgc">
1 a* ~, t) ?$ i1 k7 P" n    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
; @; z6 J" E  Y* }) ]$ w0 C3 \- h9 n: I  </tr>5 u) u& j2 J' p& r! y* ?/ x
</table>
3 b  O5 l6 |6 c  V1 Y</form>
7 ~7 i+ z: x1 i" I* w- E  w<script language="javascript">; Z5 y+ \$ ~- p6 e4 Z2 H
//人名移动
* w; S. p* R& _* _function move(fbox, tbox) {
- m* z/ f  ~& g7 q% {var arrfbox = new array();
4 {5 h* r0 A( D' L/ e7 F1 X; dvar arrtbox = new array();
1 m# F; b6 |$ R' W; x7 c/ Fvar arrlookup = new array();
) `- M7 a  t" y  Mvar i;
. M( G* [% g) Q7 p3 Q3 x( ffor (i = 0; i < tbox.options.length; i++) {
& p* h$ t2 e: G7 X, g" ]: `arrlookup[tbox.options.text] = tbox.options.value;
; s+ {6 i- }7 j) t* Q: xarrtbox = tbox.options.text;% g4 O2 l4 Z9 }
}
) u0 ~/ M1 r/ Ivar flength = 0;' n9 m4 C1 z. Z  t) s1 H' @0 S
var tlength = arrtbox.length;
; J4 x1 J9 _6 J- t; p9 ]for(i = 0; i < fbox.options.length; i++) {( \, X, O: q; q$ ]- o& H; ~
arrlookup[fbox.options.text] = fbox.options.value;
4 P. D3 b& N4 @( L8 r5 s: Pif (fbox.options.selected && fbox.options.value != "") {2 K" B, ?' O& R# {# }6 r3 t$ V
arrtbox[tlength] = fbox.options.text;
" O& K4 K' E- `4 Z8 I( B  I$ utlength++;
, o7 \" \" X2 T5 E}# X! M# i) w" S/ O/ o: p8 \, J/ F
else {2 [4 I9 p0 d6 ?
arrfbox[flength] = fbox.options.text;4 R% Y. d2 M6 i/ A0 v2 V* r- E- {/ W
flength++;% D$ E& }/ ]( T* S! G
   }& P% I7 |% d7 u& V$ t
}
( |8 X$ M( i$ k, D5 m2 U+ |arrfbox.sort();; S- V$ h$ K- i9 d) r8 A
arrtbox.sort();
; Z% ?9 |& p! t  P  [, H0 M# `+ X+ J) J$ A7 D" V/ \' C- e  X
fbox.length = 0;
: f- g" u2 B& Ttbox.length = 0;$ \9 R' R- K8 \- t0 s
var c;
+ |% S/ ?5 J/ Pfor(c = 0; c < arrfbox.length; c++) {3 g2 @6 l- f1 @+ l! @8 P
var no = new option();+ l$ @$ {, ^3 Q+ X! e0 K
no.value = arrlookup[arrfbox[c]];
, s" S/ G! O4 C. jno.text = arrfbox[c];' _* F; ^. e: V! K/ o! a
fbox[c] = no;
; F+ k4 {" z3 \$ a3 g1 q/ _}8 A# F( K4 z% [& Y! ?. R" z" x
for(c = 0; c < arrtbox.length; c++) {' l: E7 X5 B1 h5 K3 g
var no = new option();
7 \# |6 ]+ E% ^: a* N) y8 z- m2 Cno.value = arrlookup[arrtbox[c]];
$ q& S: H& s! S" N2 _" {9 d' Jno.text = arrtbox[c];) d* Q, }, l& f$ m6 D- z3 L! p3 B
tbox[c] = no;
! @4 B) M7 ]3 I6 E   }
% V' d% V7 a* W: {  F4 x}
* K/ O- c" W2 t' P. t</script>
+ M! V; _9 C8 w: u# G</body>: `- S/ k5 M" I% o# Y! E6 K

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