返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"0 G; A" E# T' d- }2 Y
         c pageencoding="gb2312"0 c# l9 y8 ?6 v4 v( t' {
%>
) P" k+ W8 n4 N' E<style>* j* i/ y7 [/ D4 S& G0 ^' d; l
.f9{ font-size:9pt; }
' d! \- L7 q9 ]. x6 U.bgc{ background-color:#aecaf9; color: #0033ff }
* {9 ^5 u* l9 Y8 z8 a.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
2 I% B2 k/ o. n- w7 w  border-bottom: solid 1px #4e7dc1;
5 M  b$ x, L( f  border-left: solid 1px #aecaf9;
7 W) ]) x' _" o/ e; v' T' d" H/ H6 M  border-right: solid 1px #5679bd;
, ?1 c6 M$ w; d& P' d. g  padding:1px;
7 R6 o7 j3 i8 `2 c) K8 c  margin:0px;}. j5 }# t+ o/ K/ g8 t9 E
</style>
$ O9 B3 Z" q3 H2 @: F2 k<script language="javascript">* l+ t3 b/ t/ ~* a* `
<!--
, R  Y5 `, {, J! N; n7 I- r8 ifunction rv()
& @. v) ?7 Z) q& a: V0 V{( F, l  T( t0 g1 A* V9 `
  var val="";
: B3 [' i# w3 b! S7 Z" H% f  for(i=0;i<combo_box.list2.length;i++){  y- N" g7 R( L& F& i  b5 w6 l0 c+ n
   val+=","+combo_box.list2.value;; m% U1 \/ l" V; k2 D
  }
" e7 |9 ~! J1 m2 |8 o2 g1 u" M: i  if(val.charat(0)==","){
: V; n( i- m) ?) W; p6 ]% R4 [   val=val.substr(1,val.length);
4 L1 ^- \% j$ a, i  }
1 A0 _8 x9 a9 g# a) E! [2 y  opener.form1.frecname.value=val;1 j; f( o% L! y
  self.close();; `6 w& V4 g! E( D$ ^# W1 m
}6 Y3 w5 u( \" J2 C$ @, q. w
//-->
% R- L4 ^+ r- m  W</script>& Z0 h. x6 `% a* S
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
0 w7 E8 \/ r7 |% o2 S- u5 L<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />0 E9 x) D# k3 W! p
<%
6 I9 [  T% g0 m2 z! j) x  cdatasource ds=new cdatasource();  //数据联结bean实例
- \# D- ?9 a7 ]7 ?  java.sql.connection conn=ds.getconnection();
' c; q! z. d& @" H6 M  java.sql.statement stmt=null;
: ~' v7 g/ r7 V1 j* o  ?  java.sql.resultset rs=null;
7 N8 J) _3 O5 \! i  D& i  cdatacheck dc=new cdatacheck();) j5 d. ]$ d4 }  l8 [( l8 ?; j
%>
* D. m% r- v3 z7 F5 u  D<%
8 A# f  z) s; l- H; l4 Ostring 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";, d5 |. j3 r/ k" X2 K! Y5 n7 j
stmt=conn.createstatement();
$ A. O+ i# h$ c1 B2 G* P2 Lrs=stmt.executequery(sqlu);. b. t# C$ v0 G. y3 D- c
%>3 B+ |' ]7 [. N( F
<script language='javascript'>) f5 T2 L4 {7 i: l1 x* Q4 U) s- {
arr = new array();
0 h. H. ~$ M4 w8 A. [. A1 o<%  int temp=0;( T  ~4 b+ t) M' Z# Q0 `
while(rs.next())' Z6 W, E3 T- q* ]+ ?/ @3 k
{7 p  N. Q- n/ c, b- K
%>
: n. s7 @3 \+ s3 ^arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");: A! I; E  I: `$ B
<%
+ R' n. E$ V1 v! p. btemp = temp + 1;3 h" A7 H" u/ h6 d
}& \' O0 j+ l0 `5 M
%>
' E( w9 S0 u9 ?temp=<%=temp%>;
* a* q) E8 V' s# I2 k& kfunction changelocation(id){
  l8 r8 F4 y* \$ S6 Tdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
1 F. l3 b, g, X$ F( o+ [4 Ivar i = 0;
: |2 T$ D! Y6 q- t, Z" k$ a3 M5 hdocument.combo_box.city.options[0]=new option('-------',''); # U8 D  k' g9 ^& a
for(i=0;i<temp;i++){
1 w* e  g. q7 p  ~0 I. [$ zif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
- R& y, o* B# S/ L4 {7 _8 ^document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
: j5 v# m# W& ^8 J3 Z+ [% {} % [0 E  B. Z! q, {0 \
} 7 t  p! z  J1 R  ^8 e& U) M
} 4 B  S5 F8 T7 S$ Q. O, _
</script>2 m1 H; h+ R/ J( C0 a" r- t

  I* }1 B+ [5 Q0 W<form name="combo_box">9 N- B- B0 ?8 q# @
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">* x  o1 ~/ g: e( c0 R( M! M# e
  <tr height="24">6 k- b/ G! t2 M! G( F
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
  F  a' K7 j, q% B    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>( `* A7 I: Y" U& s: L! N6 Y
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
0 c9 p. H+ ]# A' z9 W8 K* l) q    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
, ^6 R9 Z( ?0 M  </tr>) x5 H4 n4 d4 B& h8 Y1 ^9 S) c
  <tr> . I  t0 m9 H( I- e
    <td>+ p) u2 E" _9 O9 ?
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
) S! b- O1 d+ M+ ^  <option value="0">请选择部门 ---></option>2 r+ T* ?" e- i# z* E) i/ K
<%
: I* u. t8 i5 B1 E1 n8 i1 n1 o2 x    string sqld="select * from tdept";
  ^! B+ O5 {4 h% [1 Tstmt=conn.createstatement();! e8 Q# f8 P! N  A8 u$ C* _
rs=stmt.executequery(sqld);5 C" p: |9 }: }% Z* @3 |
while(rs.next())
$ L' U' R- `# s/ v{- }, f+ W/ j1 e8 l
%>7 s% |- h; p5 L4 r; U
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
/ v; M" A8 w$ Z9 T1 h<%1 J& _; w' n* Q5 r' h5 h
}5 A/ Y$ G% ~$ e" o0 n8 H3 V3 C5 [
%>
5 H5 d' X, u3 g# l! g- r3 W$ k8 w  </select>& Q) S: r( A3 {; S
</td>
8 x6 i4 i" k$ F# j    <td>
; L$ g% n. ~1 g" Y. p( o' q  <select multiple id=city style="width:150;height:200" class="bgc">
: ?8 ~8 N- ]: U, r$ R  </select>7 c) {0 J8 _# c  f8 A8 @
</td>3 L( M. V$ M+ r" N3 A6 D- L* a
    <td nowrap align="center" class="bgc">
1 H) \- G) p6 f  <input type="button"  value="<<" class="buttons">
. ?6 o0 c& R# A0 b. B  <input type="button"  value=">>" class="buttons">  y+ B. B7 Q& j- P$ X- Z5 s
</td>
' B! e) C2 a# z& Q    <td>) n: s/ R5 v; r6 _6 R8 d6 U/ m9 b
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">8 O( i$ _9 {; [. g3 y
  </select>
8 k; s0 p2 j# g' _0 ?</td>0 F) L+ y4 ~# w
  </tr>
1 {4 l$ U! [5 E5 w, L1 ~7 f5 {    <tr class="bgc"> & [. G6 ^+ ]( H0 v0 y5 t! R
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>( u/ I: O1 M1 Q1 \+ ^
  </tr>( ^+ k9 K9 `1 u* R
</table>
( i9 t2 J, l9 o) h7 l8 e3 L9 Q</form>9 z9 Z! c0 U- s' o
<script language="javascript">
3 }8 i3 F, o, _) i//人名移动* e/ x; H6 [- x) V
function move(fbox, tbox) {* q& y! l8 t( p/ p
var arrfbox = new array();
; N3 [. M2 J) nvar arrtbox = new array();
/ d; m7 L, H5 [- uvar arrlookup = new array();
; m' F) V2 i* T% v5 w/ R7 M% T+ Cvar i;4 x0 J( t+ s' s1 L, e& _
for (i = 0; i < tbox.options.length; i++) {
) V7 s; Q" \9 c$ W+ c. oarrlookup[tbox.options.text] = tbox.options.value;
" i- H9 J; i: {$ ?; A' R! A! \4 qarrtbox = tbox.options.text;
3 J3 m* v1 ]3 m" v! u) B* `8 y+ m}5 h1 Y3 y4 X4 U' U
var flength = 0;
2 h8 F, r' q5 U  ~) U; V8 ?var tlength = arrtbox.length;
( a, t3 F! a7 N3 S- }0 Yfor(i = 0; i < fbox.options.length; i++) {
4 {7 @/ |% ]6 v5 y; carrlookup[fbox.options.text] = fbox.options.value;
9 |/ {2 d4 ], ?& oif (fbox.options.selected && fbox.options.value != "") {% H" {, ~/ |0 q: Z/ M: \
arrtbox[tlength] = fbox.options.text;
3 e9 n1 Q4 W  B" gtlength++;! o% E" A. P2 Y+ S  T
}
; ~  B% x/ q& ]: E7 w7 G' O& ~else {' T9 U; k1 |- i; V; X7 Q7 ]/ N
arrfbox[flength] = fbox.options.text;
4 L9 I' r: F+ W7 @5 n& Vflength++;; r% ~3 t" g& w/ P1 ?/ v
   }& }; s1 v/ g: v$ h4 J. x/ G3 }
}' Q& C7 T' [  m
arrfbox.sort();7 Q) W0 H' W) D( g7 y
arrtbox.sort();+ t0 k% }+ S; z' V: J, i
7 E- T3 d9 {" Q) m2 d
fbox.length = 0;; c1 i3 n! h8 @
tbox.length = 0;4 ?$ _8 w5 e( A* ]. A6 @! h+ g
var c;
' W( I' a' D5 y! g. Sfor(c = 0; c < arrfbox.length; c++) {. T# D! ?/ R$ @7 F4 T% X" ]6 L
var no = new option();+ F$ v- h2 H' t7 [, x$ }* @
no.value = arrlookup[arrfbox[c]];( w; D( A8 ~8 g6 M- Z9 _
no.text = arrfbox[c];
* o3 N! R% f9 s/ B& P2 U$ y( ~  lfbox[c] = no;
; J1 P# v+ K' ^) F}
3 R  e! E# s6 w* o; @9 Zfor(c = 0; c < arrtbox.length; c++) {
& t9 P3 [3 {& Cvar no = new option();! O& x1 p$ [8 Q# Z" c
no.value = arrlookup[arrtbox[c]];  p$ d+ T" q: ?/ h1 @! U
no.text = arrtbox[c];
' B, z# M/ S/ Ltbox[c] = no;
& W  r  E$ a" z1 I( R4 s   }
7 `  j) i9 E  B! y}
2 A( c* v+ k/ A  Q( E3 K5 P2 S</script>
2 z7 ]: i5 ^+ b# F$ S7 ~" t; D</body>! @5 r3 n8 W. u

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