返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"6 G0 _8 d& s  K( R' L, ]
         c pageencoding="gb2312"
+ q6 k; J7 |( I5 ?+ q" n6 X%>) k# a  v+ p9 s
<style>, J3 p4 I8 W; a. n) v3 w; N
.f9{ font-size:9pt; }
% a7 o9 O1 e& c' f.bgc{ background-color:#aecaf9; color: #0033ff }: h6 }- S/ J$ M3 S% m$ ^
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
& z* o# N1 A* e: r+ s" y  border-bottom: solid 1px #4e7dc1;
, E1 u( @! p7 E; U4 N/ }4 p  border-left: solid 1px #aecaf9;
  i' O( h" o: F0 q: I* X  border-right: solid 1px #5679bd;7 v( K  W- P! B! ]2 D! Y
  padding:1px;
& h  d; |& y. s: m0 W8 U7 s; P  margin:0px;}
1 w  u  A6 Q- t</style>
) r5 a. V- U+ K# T4 \7 h) m# U! s<script language="javascript">& O9 |# K. e5 T9 C# @
<!--# k3 |+ A& ^+ _; @; @
function rv()
0 |1 _4 d; C) O% J" n  d+ \{
& l3 G  [2 P+ H9 S# f& ?& s6 j! ?  var val="";3 Z  P; f) R6 ]/ x5 z
  for(i=0;i<combo_box.list2.length;i++){5 s8 q2 B2 I' @: @
   val+=","+combo_box.list2.value;3 a1 |9 b6 o- I! r
  }0 @- Q: ~( L  s! ]( x: t8 C
  if(val.charat(0)==","){
" d; `# \' V& E6 d   val=val.substr(1,val.length);! x- @3 d  V4 Q4 p5 [
  }
/ V5 X2 j& }+ z" F7 _3 p3 E) E  opener.form1.frecname.value=val;
7 P" V0 H) |: ?& u: {  self.close();+ U; r. T7 z1 i6 S; G; V, B
}. a; n. z, {+ B' A2 E% y8 k
//-->" Y7 R& _$ u5 T+ _5 {
</script>* B: D0 |$ s! A) a
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
! ^2 ?% B4 k) E* M# l7 j<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
$ ^. S& X; S7 s" E- W$ o$ a<%
! h# l" \. S6 k  ^& T8 A9 Z  cdatasource ds=new cdatasource();  //数据联结bean实例
7 Z, z% y; n* D+ ~9 t  java.sql.connection conn=ds.getconnection();( B; ?( l+ |/ t. Y$ M! h" m
  java.sql.statement stmt=null;
4 a8 J+ I& J! I  java.sql.resultset rs=null;  }; T, w) @3 }) j# H
  cdatacheck dc=new cdatacheck();' j4 `& N% C6 |: v
%>+ ~( q6 p' _5 l1 N5 e1 Q. b
<%
7 |, z$ S. B9 O: ustring 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";
4 K! O! G$ c  a( h" B- u( r. [3 Qstmt=conn.createstatement();
7 j. O0 K5 H, l2 Y3 P' T: U, ?# ors=stmt.executequery(sqlu);9 W$ ?5 z1 }  W( V6 G/ W
%>! \2 S0 a- u. z% h3 Y
<script language='javascript'>2 d  T! S0 R. G! [/ L) M* Y- I
arr = new array();
/ D4 s* J/ r6 P8 ~<%  int temp=0;! A+ \4 L; ?0 ?
while(rs.next())
: s# q1 W, }2 R2 R2 q{
% n' k3 _0 W% k- r%>8 ?' j9 s9 I& F! b3 M* C: c0 P
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");+ x# y1 {0 Z1 M5 n( O( o
<%/ H/ Y( B7 z5 K5 c( H
temp = temp + 1;
& V1 u8 v$ J! b& G- Z- P5 h}
* s- L. z. R# K* ^# x% y* X5 Q$ b# P%>
& W0 b0 o4 ?" f* W9 f% d6 Qtemp=<%=temp%>;
% {6 O  e* t/ g# a0 `function changelocation(id){ $ }- }0 ?! C7 U9 q# Y
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
, S/ J  k) s8 {. _$ b' tvar i = 0;
/ r4 Y  X4 Z( H2 ~2 Cdocument.combo_box.city.options[0]=new option('-------','');
; c4 L0 @6 X' P% k) ?" L7 ~for(i=0;i<temp;i++){ 9 ^3 f2 K- P3 Y( M) H% x
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] ' {0 s1 d5 i3 A8 a8 I% O8 G
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); ; c: f3 Q4 W; L8 m5 I: e6 J
} ) j2 F  y3 U1 l! t6 q% s( I
} " S! N% ]! o. m" Z# I* w- i1 m# I
}
- Y( |# _7 h0 J$ d6 _# @8 `1 [9 R</script>7 ]& j9 `) T9 \; ~2 K  Y# N2 V* T- {

8 C( F, u$ G5 x5 C% G$ a<form name="combo_box">
: H0 D) v! s" _0 g( F) y( c<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">6 M2 t9 G7 i4 ?3 }- W
  <tr height="24">
; I5 ]( o5 Z3 s9 a, P' ?" h4 [    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
, i# F! V* r7 F3 y7 K# l' E  V    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>8 r) }1 ]5 |5 S" P% Y: L
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
* A' S. t0 q8 Q' j    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>1 w" e& h% r: Q  p
  </tr>- Y7 c; Y# n' ~9 R/ j3 h
  <tr> # Q! H) ^/ w# V% y7 F
    <td>
/ _9 ~% ^1 I% `) i/ o; |  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">+ ^9 v, J8 N/ U) e7 Z
  <option value="0">请选择部门 ---></option>
9 g1 V, {! j7 f: f% W" G, ^1 N<%
# V" ]. `& {5 `+ T$ V! l. R- o    string sqld="select * from tdept";
& l$ g. x; j& [6 N$ {7 \; H4 \stmt=conn.createstatement();- s3 h) {2 X# P/ Y
rs=stmt.executequery(sqld);2 s- ]% v- b( b7 V0 W1 I
while(rs.next())
5 p2 c& A4 D' d" y' s9 L{
. `0 y0 |2 D) s%>. h% m4 |; g- w% ~! T( |# m  ^. |
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
/ u1 j/ F* F( z% z0 m<%
* s* `' q; s5 m6 V+ p* P}: E  A- G5 m8 S, y  f
%>
/ T, O  r# F) z( A4 r4 M# o  </select>
/ I* }' o, F( n5 R* U</td>
3 ~, d- N4 }+ P8 X7 C3 l0 {    <td>. `5 }5 q* A3 W
  <select multiple id=city style="width:150;height:200" class="bgc">
2 {5 h% O1 m! x; y; a, x- u  </select>
+ s% b, ?* `: A4 C</td>
, S( c' O  j- o& i  J% `    <td nowrap align="center" class="bgc">
0 k6 @9 p& c) s& z  <input type="button"  value="<<" class="buttons">. M5 v* s. }0 O# X. x- W# }3 q
  <input type="button"  value=">>" class="buttons">
. ?; j) {% Y: y; m</td>
' x. L7 L( y/ [2 R    <td>
! Z  ~! m! a9 c- u5 N  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">' p) K5 }: e" Y+ A0 ]1 ]& F' J
  </select>4 K7 k* C/ o! Z3 ~! q# b/ S
</td>( s5 f. w" e2 C  G4 S
  </tr>8 W) Z/ f1 I  b8 b7 V. J
    <tr class="bgc">
3 w# y9 v) j$ A    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
- ^% R" z' ~7 T2 O# B. \) G6 }$ D  </tr>9 B5 m0 O2 A) w3 C+ B8 d
</table>
3 b6 I3 ~) M4 ^# ^+ O! g</form>
0 Z- f% e' V$ f$ T1 _. r<script language="javascript">. \: {# {, H. s! Q
//人名移动
$ m" H6 B# G3 I+ |0 gfunction move(fbox, tbox) {: I) T; E1 q4 i4 l# L* M7 I" U2 s
var arrfbox = new array();& j. T: X! R7 j( v1 A- G' c
var arrtbox = new array();
1 K. F0 {2 b; r6 p8 o+ ?  V: jvar arrlookup = new array();
2 b- {! R+ e9 cvar i;
# c& a% o, [+ u' Ufor (i = 0; i < tbox.options.length; i++) {1 `$ S; W# n- Q" l, b1 C. j
arrlookup[tbox.options.text] = tbox.options.value;' ^8 f! ]  ]% t! s1 ?$ z) u
arrtbox = tbox.options.text;
1 J8 s* k6 z$ g* h% M. `8 f}
  ~* I/ h. X) |9 f6 x$ Pvar flength = 0;) O8 Y  x3 w* t1 {
var tlength = arrtbox.length;
) f. L. N' \9 b" Mfor(i = 0; i < fbox.options.length; i++) {% p/ Z2 b6 v4 U  i6 @% D
arrlookup[fbox.options.text] = fbox.options.value;# I( F" }. P4 s6 R& n) d
if (fbox.options.selected && fbox.options.value != "") {. y# n7 F& k6 A8 {! ~7 v2 M3 {1 r7 ^
arrtbox[tlength] = fbox.options.text;4 z* a& a/ a/ O3 l2 \8 V+ o
tlength++;
) r' d; W. p+ J/ `0 Y& e9 _4 f}# L' ]9 Q/ r0 I' }" u$ [  Y
else {. x8 R; C5 j1 l, S2 ?
arrfbox[flength] = fbox.options.text;
. R8 r. g& c" b. K- Eflength++;: K9 y/ M1 F3 Z/ @
   }% G3 N* J5 t5 w8 M# l/ @- r1 I
}, N4 o- p# C) e
arrfbox.sort();
# E, `- t! y. x  J: t- m1 Jarrtbox.sort();
& \0 P! P7 T5 w
* Y' i  a9 o5 r& C" E& i& g" Efbox.length = 0;( y0 C6 I4 G6 n) K
tbox.length = 0;; ^/ c$ q8 u9 {% |# q
var c;, `) @! L* H9 v
for(c = 0; c < arrfbox.length; c++) {* J1 Q; i7 R* V3 N1 J
var no = new option();( B! {' v8 }- I; V- O
no.value = arrlookup[arrfbox[c]];# m3 |3 S2 }0 v; F+ |5 S
no.text = arrfbox[c];2 C- L. e3 b( K! V7 }" H; g3 I
fbox[c] = no;8 s. N/ b$ s; Z+ y  ]
}) o4 n7 H. ~! |7 h2 a
for(c = 0; c < arrtbox.length; c++) {
1 B/ ?6 c" X2 A3 ^! @( {var no = new option();
) V6 ^/ h; D9 f3 k" X* Vno.value = arrlookup[arrtbox[c]];
" ^$ ?3 @& J! y% N4 Uno.text = arrtbox[c];
1 z+ d6 [9 e% Y$ O, h9 v8 ~0 h  g9 wtbox[c] = no;( R/ N/ D. s6 p2 l+ i
   }1 P8 D: B7 _: ~; |" s8 q
}. z" G# c" Y# |5 g% l
</script>
& C( s4 Y% a0 f7 ]6 M" g* \: ]. A1 v</body>0 V/ z$ H/ D+ D: l! w& F; t

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