返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
# i9 b/ l! I2 A5 L  X; C9 W* t2 H         c pageencoding="gb2312"
2 L! q! v) L2 G# }%>2 @0 S- `" G- l
<style>4 ^6 M& V* r  Z2 I5 z7 U. Z
.f9{ font-size:9pt; }
5 i2 s2 o7 R* b.bgc{ background-color:#aecaf9; color: #0033ff }1 i: X- f! `% y+ h; z# y  u
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
7 X/ u. N( ~6 l3 p3 n  \  border-bottom: solid 1px #4e7dc1;
6 W& i% z5 }$ L' g6 z  border-left: solid 1px #aecaf9;
& n! S6 }# _, h" f; E3 z4 i  border-right: solid 1px #5679bd;) |: M* @2 Q) z0 N+ R3 G1 a7 C6 E
  padding:1px;
) |; x2 Q+ j( X$ F. H/ V  margin:0px;}
/ n. ^2 T4 N- D6 d& {" w</style>
3 r  K! w: U& j' T- e$ u<script language="javascript">
2 i9 l# w2 e3 h$ x. p<!--( L3 E0 [3 t+ Q) s2 v
function rv()) t  z6 j" s0 j& n; \  r
{
1 k, `0 q" `, k( ~' s  var val="";
4 W4 H& [1 M7 C& ?. r* T/ D: r  for(i=0;i<combo_box.list2.length;i++){
6 N+ e% O* v! |: D   val+=","+combo_box.list2.value;/ W" P3 H/ ]) l3 C
  }- I! M8 E( i) d
  if(val.charat(0)==","){$ b3 V7 K+ B& g& ?) U
   val=val.substr(1,val.length);8 X0 i' A5 a. C* v& I
  }
, I1 ^6 ^4 t# [' d! o: \2 W4 G  opener.form1.frecname.value=val;/ J: a% H6 w5 x+ C2 |/ A0 P
  self.close();, |1 r1 D- ?. N; c, h# H
}& t% o8 [/ P& m, ?
//-->4 L( f. ]3 B6 Q2 E* |% w
</script>9 E6 F+ v3 l2 y: t/ m+ w! K  U" r
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
9 C) t8 _) c) z+ ]' s+ p" Q4 G<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
2 Q# l; N9 H0 Q  Q8 @: b% x<%
$ g; D5 u8 d8 b2 m# f  cdatasource ds=new cdatasource();  //数据联结bean实例
' A* Q' v+ F; M# z" o  java.sql.connection conn=ds.getconnection();& x/ A: v& Y" A6 Y, Y
  java.sql.statement stmt=null;$ W( N7 A5 X4 }/ t+ R+ d
  java.sql.resultset rs=null;
3 D  }6 B4 @; p7 B" p: k  cdatacheck dc=new cdatacheck();4 D/ k. u  |9 Q% q/ C/ Y; _' Q
%>' ^% ?- l- G4 B5 O
<%
) p, f8 X2 n7 v2 D- Astring 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";9 q" ]8 D9 \4 U9 C$ v/ @
stmt=conn.createstatement();
, V' u- i: l1 E# {rs=stmt.executequery(sqlu);1 o; Z! Q. s, b
%>
, C% ^5 b: l0 z: R2 J0 A4 E: _5 s: u# b<script language='javascript'>
4 I. v1 _( P2 v/ Q/ Jarr = new array();
8 A! Q: C. N0 S7 s  _" i<%  int temp=0;* s. W- j% f8 j3 A, C
while(rs.next())
7 h7 o+ ^7 e  k6 {$ ?5 A{8 C, l- V5 `& ^  }
%>, ?/ O6 w, q; Z3 ^1 X
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");! }4 j6 s  c+ R2 j
<%; d# X. E  Q+ v: d7 q6 f* _
temp = temp + 1;
+ z- h3 m8 P9 K}$ Z4 \: [1 Q2 m' K! {0 i6 ]
%>
' T- n( r+ A4 a- Ftemp=<%=temp%>;% @! m8 y) F1 S0 v: A1 }! w
function changelocation(id){
, z0 f5 o, f; c& G" Pdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 5 p6 a) w' \$ r9 z$ L' {
var i = 0;
' C- z. ]7 C3 ddocument.combo_box.city.options[0]=new option('-------','');
3 q+ o( g3 u0 Gfor(i=0;i<temp;i++){
* u0 ^7 ]$ U5 m& |) d6 ?- Rif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] ( C9 D) y$ J! ^: @9 V0 A* N) A
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 0 ^4 E1 ~$ z8 I
}
0 \8 t1 [- _; }  x1 F8 n5 o}
0 }0 N, \* J: `. J, |- B( k}
( O$ o7 w! y5 k+ ^</script>* u; i% j- C0 N+ M+ i2 U
- T  p2 u! s& r. x2 A, w
<form name="combo_box">
) {: h, `; m1 e. z7 \<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">/ x8 ?3 F- `! g  d, h3 y
  <tr height="24">, s/ [% I* r9 P: U& |# I6 _
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
' q( ?6 U. a5 c    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>  F( |& A7 v8 t9 y7 {  V9 A
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>' ?; O; i3 h7 [3 Q
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
1 ?6 J, ^1 H  ^% m$ {; E& ]- ~  </tr>5 E, b. k8 I- [% k, m# s, j
  <tr> 9 m. o* U0 |' \# u/ W1 b% p/ J
    <td>& k# u1 u5 T5 V! O; r
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
+ S7 c+ T' e$ k" k  <option value="0">请选择部门 ---></option>
, @# v0 g( F& [) c<%# Q. q) h- K4 P' M
    string sqld="select * from tdept";4 h  c3 g3 s2 }5 S3 U  H- a
stmt=conn.createstatement();! @# H& n" F+ q
rs=stmt.executequery(sqld);
. l) n1 t; l' @4 ?0 [: x) }4 iwhile(rs.next())
. ~1 t7 o: }% G; e! Z/ X{2 g, g$ O0 S" D, A% Y% F- z
%>7 p% F; K4 {% ]
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>) N2 X5 N5 C& J0 p
<%9 i  Z$ L; R: ?, x8 q/ ?
}2 e2 X% e+ `1 f1 a
%> 1 h6 T5 o( i- I% o0 z
  </select>. v: z6 H; g- U! Q3 ]- e
</td>; [+ q% ^5 m  u% I- {
    <td>
, a8 w% e0 _  i- F& X4 w2 [. D( R' Z  <select multiple id=city style="width:150;height:200" class="bgc">
5 K! ?* c$ @7 L, y' D' A  </select>
. t! V9 W2 d% z6 o2 ]</td>
' X9 L$ q; X: i    <td nowrap align="center" class="bgc">
1 e3 c+ V6 Y( w3 i  <input type="button"  value="<<" class="buttons">2 X4 `9 t9 d( n! v6 P. O) h
  <input type="button"  value=">>" class="buttons">
% P- n( X9 D3 x* b6 ?/ q</td>7 W" ~4 g, b1 i. z/ e: P. ?
    <td>
+ D/ n+ k9 r6 r. Z! i' U  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">8 {3 p0 d. ~4 S3 L
  </select>
5 N) l) S' p) a! k& A: n</td>
5 }; _! K+ E0 y; y9 P  </tr>
6 X7 N6 d# Q3 R! O    <tr class="bgc">
/ o' c" V2 y, Q+ {+ R! a    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>9 \2 j+ F( c* a& ~4 p- N
  </tr>
, A) J2 z* n, C6 M" C</table>8 l9 d7 b$ Q8 i, k* q; N
</form># r" T- \! k% `* `; y( f% ]6 F
<script language="javascript">; G5 g0 D! a6 ~! D
//人名移动5 g  e+ W1 A2 {
function move(fbox, tbox) {" r& g( N8 I6 N6 m: y
var arrfbox = new array();6 {9 B* T- i# `0 j, B  n
var arrtbox = new array();- Y! ~  _5 V! N- N
var arrlookup = new array();
+ J6 B+ H9 Z, N, s+ I3 Gvar i;5 P8 L5 E: }- N! _  O
for (i = 0; i < tbox.options.length; i++) {
, p; J  ^# g, [3 s+ Q' M. rarrlookup[tbox.options.text] = tbox.options.value;% S. _' R8 Z& \! O* W0 H4 ?5 P4 ?$ t
arrtbox = tbox.options.text;
( q5 w/ E. J3 G( ?}
3 j5 z$ t& l* B9 d2 D3 k+ V) u, }) Y5 `var flength = 0;7 Y3 ]/ T, J7 @4 j- |. I
var tlength = arrtbox.length;6 e  B: Q& L7 i% v1 {8 s
for(i = 0; i < fbox.options.length; i++) {( p$ ]) S5 X2 M3 J0 b
arrlookup[fbox.options.text] = fbox.options.value;
) i8 \: \' H0 s+ r9 V" `/ Qif (fbox.options.selected && fbox.options.value != "") {3 [; |( t# }2 G. f4 t# w
arrtbox[tlength] = fbox.options.text;/ X3 C/ d& S# i
tlength++;  V$ ?7 r, e! T$ \5 M& e" Q
}
$ `  r$ k9 ?9 C6 M' _else {
- t; n; H7 ^6 o+ oarrfbox[flength] = fbox.options.text;$ s! l: t6 l% `- a, U! ?
flength++;( m* ]+ P. T; }9 g" l3 I
   }, U& \- D4 v! Y( }7 \" |* R
}
' c" L+ y+ f% a# u2 I* ]arrfbox.sort();
- l, t, K7 ?, i4 Narrtbox.sort();8 k7 ?7 X' I6 _2 l; R( Z

/ a1 _5 _1 O# S# F1 S2 Qfbox.length = 0;
# ~# Y0 X0 S8 mtbox.length = 0;
5 y1 {" r4 w  d$ c6 ~var c;
" i! K+ Z- ?9 w2 y, B% Efor(c = 0; c < arrfbox.length; c++) {
! _8 F  t; H2 ?var no = new option();
) Y: ^) ]6 ]6 u6 |& ~/ H! d4 hno.value = arrlookup[arrfbox[c]];; z! J3 M( i0 D2 z9 R+ D' y; N# L
no.text = arrfbox[c];0 S+ q2 w- l8 D8 |5 R
fbox[c] = no;
/ w9 d2 f1 D  ^1 B$ _- d}
# [; R/ t3 Y7 |8 W1 l  D+ ?0 Afor(c = 0; c < arrtbox.length; c++) {
$ H, W( b, O  ^. c# `2 W& s  V( ?; xvar no = new option();
9 d4 V6 D% B  ~; W& `1 E0 \no.value = arrlookup[arrtbox[c]];& ]' {. w: w3 X
no.text = arrtbox[c];) \9 h: t! Y  d% |8 P
tbox[c] = no;: v+ H' P2 m- p" p  v) N
   }: }( R( F1 a- y# k0 p4 m% g5 {
}
9 R' C6 p  |  d/ F</script>
7 O5 W* d# o6 ]2 U8 ]* C</body>5 r* r' A+ c; b7 l; r

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