返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
$ m, G5 \+ Y- M  O         c pageencoding="gb2312"
( U, U  C6 Q$ K%>
2 f1 I$ @4 ?1 S- v$ P- T<style>9 s! h8 j0 M: a
.f9{ font-size:9pt; }
, y, ]$ u8 A/ r3 v7 l6 W.bgc{ background-color:#aecaf9; color: #0033ff }/ c, U$ Y6 S* L- X7 m+ o9 l
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;5 f% @7 C/ W9 w5 E
  border-bottom: solid 1px #4e7dc1;
5 Y0 A, U3 ~! z" x2 Y' }  border-left: solid 1px #aecaf9;- V$ n; F  b; D: Q+ U8 P
  border-right: solid 1px #5679bd;
! g3 g: W; x9 U! |  padding:1px;
" g6 `6 c" \3 Q- A, j  margin:0px;}5 F: H# ~0 E  Y9 d( D
</style>6 H! t3 M/ o1 D# J+ [& x
<script language="javascript">
+ T8 g: ~7 L, V  P; Q6 J<!--
+ p0 k& i/ h; v+ nfunction rv()8 l$ H. M4 Y( d( F) d0 ?2 E
{
$ b" U5 j6 H5 Q' V8 G9 [2 a! q3 K  var val="";
+ D6 D! N- ?5 N- B+ P  for(i=0;i<combo_box.list2.length;i++){
5 G2 a& M  F5 h8 b4 h5 {( x* E   val+=","+combo_box.list2.value;
  w1 {& r+ E: {, Y+ N0 K* A/ @  }
6 t+ \- ~4 Y- a  if(val.charat(0)==","){6 p* P5 F4 W( }7 j) }
   val=val.substr(1,val.length);0 }0 V& S6 i: ~; G' o5 b
  }, Y; i" s" a& w# |- O5 }4 B
  opener.form1.frecname.value=val;. R9 e: k) o% `' @! z8 }  Y! A: m
  self.close();
5 O/ E+ U7 {0 P# t5 M7 _}
7 e1 r: O% b2 F6 v1 w% C2 O//-->
+ j* v" H4 P- Z4 O) y</script>) [$ U2 a/ i4 K! H
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">1 d: Z9 F; T& ?; m. h5 Y! ^
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
! n9 D7 P1 Y7 \8 _; v<%
3 C3 |% `9 b& a  cdatasource ds=new cdatasource();  //数据联结bean实例# P1 k2 d+ ~3 }
  java.sql.connection conn=ds.getconnection();
8 k% \' G9 M5 `. C; M9 v2 i  java.sql.statement stmt=null;
' P5 c& \6 W( T. I& C  java.sql.resultset rs=null;8 |+ Z2 a  _' m, j8 R% @7 N' k
  cdatacheck dc=new cdatacheck();8 i$ M* y2 ?9 L) p. q
%>
/ e) n' s. n& p* s! z9 Y<%
4 }" E, {3 O2 L% d/ w5 x' G3 z7 Gstring 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";
6 ?7 l0 G$ b  J- K/ W1 t0 cstmt=conn.createstatement();0 |: s% J* f- l
rs=stmt.executequery(sqlu);
8 R. ?! t3 T  z7 U%>
6 n3 {- i# ^9 B$ l6 b" N5 ?- d- |<script language='javascript'>; y. ~/ P3 l2 {/ V
arr = new array();, v: ^- A4 |9 W
<%  int temp=0;* R6 L5 k  d/ k: x' |, W
while(rs.next())
8 @3 O* {+ B( K2 z{
/ H: q, i( t$ v%>
; {7 [: a/ z3 Y0 }# s6 W3 Zarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
4 l6 D1 Y& s' ]2 c) d<%1 [7 R7 I7 \! `0 \0 s4 `
temp = temp + 1;/ ^" U  h# P; V1 Z  e1 x
}+ @- M% p5 ~; x' t
%>) O; b9 ?( T5 s; S
temp=<%=temp%>;
' D4 h3 C2 M+ k" m# Efunction changelocation(id){ 3 ]' y% G3 {; ~5 k5 V2 q7 u1 U
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 8 d# ^$ \7 O2 k+ O( ?$ Q! b
var i = 0; 7 i$ M* _! ]" v9 H' m6 Q
document.combo_box.city.options[0]=new option('-------','');
; P+ r9 ~  r5 Dfor(i=0;i<temp;i++){
1 O/ g0 y; R3 C9 v  ]5 |if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] / U* ?$ u: T4 G6 x& e" d
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
( l" y& K9 E- B! \5 y# {}
5 q- {7 Y) M: s0 f) n4 A4 I! K} ' D+ N1 d4 L% \$ T! d
} 5 K" ^  }6 k) D, T
</script>
  R  U  n! @9 V' e1 f
( q3 A; s$ L" M<form name="combo_box">- t' Q, J# A4 r) \8 ?5 ~
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">3 Q9 b, ^4 G8 d& w
  <tr height="24">7 x0 s; p5 T2 d7 T* j* r: B$ ], W
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>! t+ p2 t) r  Q& e
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>- K" o) C: ^, `, ~
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>( s4 S. V. W! j% K1 G
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
1 b2 w" B& V% a4 R! m  </tr>8 E8 h* i* d( H) P6 n
  <tr> 8 T* W8 z$ e' R, m9 I
    <td>' R6 b# k1 X+ L4 I9 A& q4 S
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
% }2 q* E% Q8 P  <option value="0">请选择部门 ---></option>
6 J% r6 Q8 t- c! t: u. |$ r<%
1 p) ?' B& \2 c8 w2 M4 F    string sqld="select * from tdept";
; U; d4 [3 L9 V0 Lstmt=conn.createstatement();
  j2 b3 T( Z; Q( a, c. L/ o3 jrs=stmt.executequery(sqld);' U+ h. v+ G$ p3 e
while(rs.next())
. N: L+ Y/ U' X: l  J7 X% R" w" @; o{/ W, i" b; h- ~2 b3 m1 J
%>
9 h( b: \" |% M9 Q  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>5 r  s: X. j5 C( r6 R
<%
) u# ^5 x9 }' f- [( f2 |5 f: {}+ j" X( x* r* T. Y
%> ! {. o: V5 d/ `" z! o4 H8 h% C
  </select>
- K5 N4 s' J4 ^7 k/ ~3 K) q</td>/ K: j8 z8 |& i$ T8 c3 }) w; w
    <td>
& k+ R4 @! w: P. ~- H( j) P  <select multiple id=city style="width:150;height:200" class="bgc">
+ Q  `6 i" Q6 t1 K5 o  </select>4 x) I9 `, q9 V" `" E
</td>1 ?9 v$ p8 h( Y& }" a
    <td nowrap align="center" class="bgc">
9 _4 y5 _+ k0 c( x2 P  <input type="button"  value="<<" class="buttons">
& m7 t9 j6 w: r7 T/ r7 f  <input type="button"  value=">>" class="buttons">
0 m& n, X6 @4 K, m# [( N</td>+ z3 U& {; N8 n) y" z) S
    <td>
4 E7 _6 U8 h" G9 i  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">) F( {" _" y" N5 A& ^9 M
  </select>
+ {4 y% ?! ~, y4 Z' K! T</td>' v8 W! m3 |8 j* b- C2 E. t8 s4 L8 E
  </tr>
% }3 g+ Y  B9 a" p- q9 V    <tr class="bgc"> 9 }. g8 J/ p3 B  {
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>1 |0 E+ Z% h1 ^& F8 C" {, v
  </tr>
. E, D2 n. g6 C</table>7 t0 F4 {$ w0 \8 t
</form>( ]; ?. L+ X$ r1 t
<script language="javascript">
/ m& K& P+ D* G8 @$ z& t//人名移动6 z, N2 _; ?$ \
function move(fbox, tbox) {
6 Q* h  }7 U# {7 d' Pvar arrfbox = new array();
2 H: H% N5 E5 d  T5 zvar arrtbox = new array();4 m3 U# \- M5 |( k7 L
var arrlookup = new array();
+ `  q. g5 l, Q% U7 Dvar i;
& t7 P' {( J3 ^/ ?" yfor (i = 0; i < tbox.options.length; i++) {- c+ V! m/ x; |( q
arrlookup[tbox.options.text] = tbox.options.value;
+ i& _% `: f  s$ Aarrtbox = tbox.options.text;
6 b# j0 z( u' [' \}
7 Z8 J, [% y$ S4 e% \+ R' @$ pvar flength = 0;( y$ l( V2 S* ?3 ]: m( M4 ~, `
var tlength = arrtbox.length;
4 j( p' ~5 @0 d: Pfor(i = 0; i < fbox.options.length; i++) {( I- ^' [! }  x9 T
arrlookup[fbox.options.text] = fbox.options.value;
% X' t4 r) L$ L5 ]if (fbox.options.selected && fbox.options.value != "") {) H: _( Q. s7 X3 o
arrtbox[tlength] = fbox.options.text;+ y9 {, p# \: |5 t7 r7 @
tlength++;" i% f8 M+ \8 [2 ?
}2 j1 J7 o. L  _5 B! H; h- Q# d1 j
else {
2 z+ p& v% _3 t( P9 yarrfbox[flength] = fbox.options.text;2 p7 l1 A' d3 ]% {/ Z
flength++;
& {' y. G  E1 i   }
1 t% v; Q, J( S2 l" W8 W}8 C; B3 i) x4 `
arrfbox.sort();
, S# A8 B* ~" Zarrtbox.sort();
5 ]  A4 ]* c# [# {6 o: o# U
- a6 t1 g& {* Z% jfbox.length = 0;
: [( {9 u9 d* A4 x+ _tbox.length = 0;
' s9 i7 q6 J( i% B* Bvar c;
8 i8 ]$ F( J6 ]. dfor(c = 0; c < arrfbox.length; c++) {
) m; }% ~& V5 r/ W& L) O7 z0 |4 `var no = new option();, k1 y* Z& b" |# L. h; ?
no.value = arrlookup[arrfbox[c]];
1 g. D. g" s4 \& Q. u2 }no.text = arrfbox[c];# T2 z; o4 M8 X- K! l' Q
fbox[c] = no;
- Z% Y* K7 a( P: W& `}  y! U6 |: I4 Z4 d5 v
for(c = 0; c < arrtbox.length; c++) {: b) q1 J8 b. g7 A9 H
var no = new option();
) f0 I- A# P# C7 p2 F5 p8 o4 h9 Bno.value = arrlookup[arrtbox[c]];9 e+ b3 Q1 H% X# ~9 L4 w
no.text = arrtbox[c];' x9 d" e( a" K6 X' D+ I2 h5 {$ Y1 p
tbox[c] = no;
$ K8 i5 f. c8 C- H   }
) r. c$ j3 m% @0 ^}' x2 ?) W+ O5 H5 s3 R6 ^) ]! E
</script>9 u' K7 i6 @( Y' x. s+ `
</body>
5 s8 [3 G, o1 {5 H4 J$ E4 _6 x5 s1 R7 f

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