返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
! f+ B. @+ N2 s* w5 P" Q& _% S: ?         c pageencoding="gb2312"
! c$ g: T: F) a8 o6 m%>3 M6 _* o8 |' l- v; E. F
<style>( n% X( X- v/ {% d0 ^% G7 @
.f9{ font-size:9pt; }* |4 b1 r6 A* V" b# \4 ^
.bgc{ background-color:#aecaf9; color: #0033ff }
: N+ H/ x9 p# h# J5 m: E.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;- S) L/ E' k, |" n+ q4 X  V2 A' ]
  border-bottom: solid 1px #4e7dc1;- c5 S$ P' C5 C3 w* s
  border-left: solid 1px #aecaf9;/ Z6 @* e6 e7 k% C0 j, D
  border-right: solid 1px #5679bd;+ ]4 g$ B& f6 x
  padding:1px;
. l/ n( v6 K- E  margin:0px;}# q/ V  j+ @3 r7 Q
</style>4 Z$ q3 W9 N' q6 t/ w
<script language="javascript">0 ]* T8 @! U" O8 ?4 }
<!--4 r5 Y& P' J) M1 Q
function rv()
( i( F( E4 ]% l% Q/ e# }5 E{
, R- W" U/ ^* v  var val="";
/ }% G9 X2 n6 a5 i4 i5 \% c) ~  for(i=0;i<combo_box.list2.length;i++){
: t: S/ Q7 G" K   val+=","+combo_box.list2.value;2 k6 L; ^+ K9 R! t7 c
  }2 T7 U; [$ Q; p
  if(val.charat(0)==","){
/ N5 X' t" g) V5 G   val=val.substr(1,val.length);
# T/ X+ I6 W! Z; \  }
* q; q+ z; k- A& x  opener.form1.frecname.value=val;2 T  o3 V6 |. U& e# O+ g: d
  self.close();
+ |. d! ?3 t) k5 z1 ?8 B6 N/ c}
# {5 [! e; e7 `) J: T  t  P//-->0 w1 P. u/ F! [$ \* J+ P. _
</script>
3 ~0 G* k, R  A% |/ _* q6 b* g<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">( [& d, K8 \% N" S
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
5 l  R$ u  o* N( Z* w<%' X9 \2 G0 ?& k* l. i0 I
  cdatasource ds=new cdatasource();  //数据联结bean实例) S8 X; a5 ]% a4 f4 e: }  e; M
  java.sql.connection conn=ds.getconnection();
' }+ @  p; d6 E+ O9 Q0 K  java.sql.statement stmt=null;3 D+ J+ S( m( H
  java.sql.resultset rs=null;
, _2 k' Q* |2 H( c  cdatacheck dc=new cdatacheck();0 J: N/ }1 L0 S+ _0 E- F
%>
6 ?. M& r! ^# {. m  A& o0 @% N3 m( V<%
4 }* C4 L9 h; ~1 E! H  Vstring 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";
; R& g: |5 D* P4 D, B3 Wstmt=conn.createstatement();2 d* P) a2 {% f. ^  O! E  g
rs=stmt.executequery(sqlu);* X; r3 w3 n$ D* o; d
%>
! X' M$ ?6 p% B# a5 G<script language='javascript'>
  M& b# ^" ~. v/ _# \) varr = new array();! @# _, q+ I4 X% D% w2 \# [
<%  int temp=0;
' b' ?9 Z! X( \, d9 N, B! g( ywhile(rs.next())
" i9 B% N, L/ h) C! V! p{% C5 Q0 Y$ m& Z# v+ @: I8 e
%>
+ i2 o" G. H8 W3 P4 h# ^1 varr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
+ I- Z* k7 s  o; k<%
9 |1 ^5 \) y/ T; n, l' [% O6 Otemp = temp + 1;! T4 K3 }( a2 [; P
}  F7 I" h; p# i# i# d' }. i
%>
. b% m* _% e) C; q9 dtemp=<%=temp%>;& C5 z* K# B* k  Z( m7 i
function changelocation(id){ 0 F: U9 I2 M3 K0 P" H
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 # q# N9 V, k5 ]% `* C! V. f
var i = 0;
+ B7 z! I5 l, _3 u. Gdocument.combo_box.city.options[0]=new option('-------','');
  l3 q) W$ J8 J" afor(i=0;i<temp;i++){
) ]+ u) q7 n% w4 U& u" e: Aif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] $ \* [1 a' c$ A5 f
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 7 ]7 S& ?, _- x- J  S% b
}
. {! P$ W. J& k5 L- E} 6 g% {6 A+ i0 [( P- x
} & Z& s4 Y: Z4 l
</script>& M! j! U% x( g, U* j

5 `6 F7 Z$ ~3 ^* z$ f<form name="combo_box">2 ?" ]5 K% u  v$ H" m' ^
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
0 Y4 i  T! S" z' b6 t  ]) P( V  <tr height="24">
0 Z( d" D" ~; S, f( i; J    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
, u( a" g& ]& Z+ Y% K' r) W7 w$ B6 D    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
4 K6 X4 L$ w8 ^2 }7 t' F" z: {    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td># h' k( e8 H+ R4 V( ?4 B: X% J
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>! k4 N4 R+ h5 {8 k, j! k6 I
  </tr>% K  p3 ?$ o3 ~6 M3 v
  <tr> # L+ N- b/ |: [* H. A
    <td>
9 _, r& D& Y. \& H! D: ?$ \  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
* H" o* Z  n' P- L: Q  <option value="0">请选择部门 ---></option>0 d  m, E5 @' m7 d8 p
<%
/ c# w% H' k& `; a+ h, V% p* o    string sqld="select * from tdept";
& R- V* O+ ^0 y, e+ D. ]( ?  pstmt=conn.createstatement();& E$ ?7 g; E" w; F8 i1 A
rs=stmt.executequery(sqld);6 y' ~2 {; K6 S  ?; @( z. R% d  F
while(rs.next())
9 A' L9 q: b8 @" Z{6 W, |) M9 i" I, T$ ^: b$ O% G
%>
& x7 O; Z3 O' y! G7 l# c+ M  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>5 I8 Q; i3 _! f3 B% P" K$ G
<%; Y$ i1 G0 T3 K" ]9 S# R" {
}
( u, g+ @5 d  X* r+ e1 }3 Z" t6 l%>
2 |; a( y# r1 V# p3 i  </select>0 a" Y; G/ u) P+ I5 `$ l
</td>
  s; X, N! R7 |+ m9 e    <td>
( W" \3 P$ E& n! q( w3 ?: T% c  <select multiple id=city style="width:150;height:200" class="bgc">% ?7 Y" W5 t9 Y/ [
  </select>& M! c0 S: {5 p$ B4 N
</td>0 A% j7 f- |3 r+ m7 v9 T
    <td nowrap align="center" class="bgc">; T) V9 e2 k$ Y
  <input type="button"  value="<<" class="buttons">3 N) J) h( e# A+ g6 a$ x4 l1 k8 X
  <input type="button"  value=">>" class="buttons">
: J$ R1 I. O9 N</td>
6 Z8 v$ z9 [* C$ r0 K3 y    <td>: D, u' x( v5 n) ]) z) f
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
3 s; y( A8 i9 v  P$ S  </select>
9 c- {' a( F; E</td>4 L0 ]+ O+ X& [6 x" y1 w6 z7 I
  </tr>' z( Q: ~, ^" t& ~& q
    <tr class="bgc"> & v. k5 ^9 K  _, z' h
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>" ?+ I( g6 H1 G! P9 N' }4 k
  </tr># _; z' p' P: }8 V
</table>; U( w( g3 N5 d9 v; S6 H
</form>
6 I2 `9 i" h1 j7 A5 c  `/ S& @<script language="javascript">2 r, C: U4 p. q( R) z2 Y6 b
//人名移动
# Z' T7 D. ]; P$ lfunction move(fbox, tbox) {; A6 Q, [  v0 Y8 u
var arrfbox = new array();
+ @: u1 Y6 q/ s+ {) w2 C2 Evar arrtbox = new array();: J  d/ \* F$ b1 T3 h/ ~
var arrlookup = new array();
! y* A; Y# ?1 jvar i;
% ^5 F  n: S' G0 _3 C8 i* O5 Z5 {for (i = 0; i < tbox.options.length; i++) {  R6 ?! D4 S( `5 L4 Y4 a
arrlookup[tbox.options.text] = tbox.options.value;. o0 L# m1 C- j0 q( y0 t. k
arrtbox = tbox.options.text;
/ I7 J& ^- S$ ]7 P" ]}
; K2 e, {+ C$ Q; O3 {6 evar flength = 0;  }! v2 M, q! Z1 S9 _- ?
var tlength = arrtbox.length;
3 b2 Q8 X, z6 |7 k  m/ Jfor(i = 0; i < fbox.options.length; i++) {
8 e7 j. m" E3 j3 i& farrlookup[fbox.options.text] = fbox.options.value;
7 o& X2 Z% P4 o2 [1 Uif (fbox.options.selected && fbox.options.value != "") {4 ^* b% V5 q; b0 [+ E  t; F
arrtbox[tlength] = fbox.options.text;( g" @5 u: G9 L, X7 S8 K; j% U8 x" b
tlength++;
7 R/ r; ]8 C' E, J) \$ z}5 M  H1 j" q, l7 n# I% @& N, _
else {5 A  I! a0 }1 {: o5 x3 }0 U
arrfbox[flength] = fbox.options.text;- m0 l6 R* n8 i2 _
flength++;6 p9 E: }+ m4 G& o) t
   }
$ ]. Q/ O0 S# l  ?$ S2 n}
. m2 `* s9 Z- |7 earrfbox.sort();+ v7 P7 {7 G4 `
arrtbox.sort();/ ^, e9 z, Z- j% S4 B; y

# T) H) G/ Z% T$ P+ j$ lfbox.length = 0;0 f' w( U! ~# M& ~
tbox.length = 0;' w/ {9 ^; N3 o+ C3 T* V
var c;: c5 ~6 z2 t+ S8 F) s) U8 ~
for(c = 0; c < arrfbox.length; c++) {3 x8 N4 p& f. c/ p/ @4 P
var no = new option();; C3 L4 P9 y5 x9 D( ~
no.value = arrlookup[arrfbox[c]];: X* R3 l* u4 U
no.text = arrfbox[c];
( T% P8 D( K6 v5 Zfbox[c] = no;$ x' P* `; r- b& B
}
, N2 i! p3 ^* c8 Z4 ~9 D# y3 ifor(c = 0; c < arrtbox.length; c++) {5 E) G' ~5 z/ D. V
var no = new option();
3 r+ u6 l" h/ \5 _no.value = arrlookup[arrtbox[c]];! e1 \5 y; g& ?+ |
no.text = arrtbox[c];
- T; ^4 x' P* Jtbox[c] = no;
- H5 B! T3 i7 h6 \& t   }. j; ^5 |! {' L2 {
}9 Z0 s4 q' ], u4 P! i4 |0 W
</script># J) U! P8 d$ t# @$ |- _3 u2 ?
</body>. `; z5 [0 U& ?6 b: z  }7 k: u: T

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