返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"8 V  |* z/ |, D6 e5 E
         c pageencoding="gb2312"
% }: b" o! ]) X' N/ D%>
# c5 F/ P: y$ a<style>. r1 e$ q; }- {" K8 }
.f9{ font-size:9pt; }
7 ?0 k3 M; c2 g0 N.bgc{ background-color:#aecaf9; color: #0033ff }
8 ]9 f) F6 D* Z8 E- a  b4 o: N- O.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
: g8 x' ~3 b5 N, s' x$ Z  border-bottom: solid 1px #4e7dc1;
4 a: I, B: j+ p  border-left: solid 1px #aecaf9;
8 d/ M2 A8 m' T3 q# L- T( I  border-right: solid 1px #5679bd;* t1 C$ v  y2 p; t# m
  padding:1px;9 B; H8 Q" P) r6 f2 Q# t
  margin:0px;}) N- k% C* d" G+ N7 W0 g5 R
</style>
, i$ `$ G% j) T5 P: l# n0 A<script language="javascript">
, R7 D% c8 h4 O+ f) ]2 Z9 F9 _<!--
; ^# n8 W5 R7 X  Z, cfunction rv()
( r  r7 K8 z0 ]2 q{
' }* K9 ^8 s0 ~  var val="";9 n+ m, R. U1 M' h
  for(i=0;i<combo_box.list2.length;i++){
& ?) a9 V! H" K0 Z7 v$ I% a   val+=","+combo_box.list2.value;1 ~0 ]% `; H5 k2 x. j& t% `
  }
9 W$ K, h6 r' E; k8 j  if(val.charat(0)==","){% S, Y$ k4 {! c; G7 a
   val=val.substr(1,val.length);  W1 C1 Q+ D' j( g4 r
  }- f* x1 ~- g  L; L8 {
  opener.form1.frecname.value=val;
! `) ^: H4 |' W7 e  self.close();
# h% w9 W$ |/ p& p0 {$ K) _8 W}; e+ z; v1 G* |. r" A" B# x
//-->
) z  K; k7 B, C2 c3 F% ~7 o5 C5 D</script>8 n0 O& L( q6 B8 N1 I2 f
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">8 {$ M+ P7 N) N$ q+ ?& |
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />$ {4 R9 \; u3 J# {/ l. N
<%; l8 d: |; p& c$ B% f
  cdatasource ds=new cdatasource();  //数据联结bean实例1 \2 K2 u2 h& S+ L
  java.sql.connection conn=ds.getconnection();
# ?& J+ b) t  [  y. y9 |( i, N  java.sql.statement stmt=null;
3 F- f1 d' O" {! c. _8 Z  java.sql.resultset rs=null;6 x# K, c1 T1 T8 T1 @! j  t: G$ T. n
  cdatacheck dc=new cdatacheck();5 W: w1 ?/ o3 v/ p6 K
%>- T6 F# m4 U* o7 }- ]  E9 k
<%) v& H# Y6 P3 G8 G
string 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";
: X. N% s# c7 t8 \8 h2 Fstmt=conn.createstatement();
  n. n* A+ |& I/ ?. G! _rs=stmt.executequery(sqlu);
, i) w& C& y3 m% d$ A, T* h%>. h% X# z- V$ _; U4 w3 f
<script language='javascript'>
- ]7 Z9 {% P4 z+ d/ P7 o6 jarr = new array();8 J6 K+ }) X5 d5 ^/ i: A
<%  int temp=0;4 D4 H7 Z+ E3 o9 `8 v
while(rs.next())7 r4 E7 T' `- F
{0 T4 U& V8 u7 T3 X0 ~, r
%>
9 d- E. n/ I/ G" W' x' K# W+ Qarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
( b) _2 x( G3 }+ n$ \, W6 r/ D( Q, E<%
+ r. S4 s7 m. F& Q/ C- ttemp = temp + 1;
1 ?# s2 u( a) ?+ }}
, F7 _: j5 M" d9 [- d4 q6 d%>" K  h0 M8 X5 }5 _5 y' G/ H6 \; K# `
temp=<%=temp%>;
! l) _* F% P5 y# Yfunction changelocation(id){ 6 {. g5 G* a/ ~0 X
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
: Z& ~9 p; e' T1 Fvar i = 0; ( L5 _2 B5 N9 j4 \+ c' h
document.combo_box.city.options[0]=new option('-------',''); " v* |$ {4 Q7 x$ q+ N, j
for(i=0;i<temp;i++){
% a7 ^- `2 J# ~* p+ Vif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] / L7 g3 T$ T6 l3 f5 p1 C
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 0 u* Q8 [6 Z( `- V- z
}
6 w( G. Y( @/ ?7 j' n$ F& z5 L) G5 U} , X: t# m4 r' r* N3 I# I" z
} 5 I' n6 X  V3 E' E1 \
</script>
2 Y0 `6 w: S# u* t& g4 ]: [$ i! l' {) i! W5 y3 i) c$ w7 n
<form name="combo_box">7 {" I1 [  C9 ~- ?/ D6 b/ p
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">6 m( g8 ]* W8 N) {
  <tr height="24">$ n# F+ _4 \4 u8 G/ L7 Y4 D8 Z
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
6 G( o$ ^% [) n2 ?3 G" C    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>* t) F. d# q, X% K4 Q6 i
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>, q* d# @* F+ Y* d
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>. J1 V$ o6 E3 G9 G) q, ^1 o
  </tr>' U7 e* u, F4 [
  <tr>   G5 h! D% E8 g" P8 K
    <td>
8 b" W3 D4 ~/ i: F  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">0 m$ j+ j9 [5 ]+ A% g
  <option value="0">请选择部门 ---></option>
  V$ {  W0 y3 p: P8 z% G<%* k7 ]8 J+ F# o- Y+ P# _8 Y
    string sqld="select * from tdept";4 M6 ^" ^+ W/ [% S: Q/ k3 G
stmt=conn.createstatement();
) K; ]( R; u1 t/ i4 Mrs=stmt.executequery(sqld);
* V, ?7 U) o' O" i. m; j2 Fwhile(rs.next())
  z4 @2 v3 X+ h3 W% Z{- O" }* C1 |. @$ P
%>
8 h5 g  ]% r; W4 N: j4 O( d, x  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
; K+ C) B5 E  X) j. g% Z<%# `6 |  N- _6 l! D. N4 R$ Y
}- z6 V' N" J2 S$ u* n4 v# f: P8 H" f
%>
1 J8 S- t) G8 a' _  </select>5 N. F8 Z7 z% S6 r2 \( D( T! [2 M
</td>8 F& B& r7 x6 [% b( n
    <td>6 G( X6 q3 |) l. L% g2 ]% M
  <select multiple id=city style="width:150;height:200" class="bgc">
0 d1 {4 O: C1 J/ J  </select>+ i  ~6 j' J! |: D. a
</td>
4 U0 P1 w5 d& E9 B& n7 i/ R    <td nowrap align="center" class="bgc">
: z% ]7 S% t  ?  <input type="button"  value="<<" class="buttons">7 B% d+ H4 F1 Z) |8 m0 c6 o
  <input type="button"  value=">>" class="buttons">8 i+ |" B- R, F
</td>
5 z" z9 m) q( i: C) O5 Q% P    <td>) A3 [& Z7 E5 X
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
' M9 a2 w5 \% z# O8 D' _  </select>0 z8 U3 X5 V7 x1 }( ?% @
</td>
, _$ r" M" @8 h. Q- f$ K% n: ^3 W) ^  </tr>% |# e: j* O; \0 U. d( _
    <tr class="bgc">
. Z/ s; v6 D, Z. u    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
5 X' }) ]& T* n7 S. c9 M  </tr>" l6 _4 y" G9 _  z" P. q
</table>
4 {+ ]9 p) O3 u* B5 q; J, E2 B</form>5 u' e8 C; p6 [
<script language="javascript">
# j+ v6 R3 c, l" l, p* y//人名移动7 I& b6 S- E* m  y% K: H6 a- h
function move(fbox, tbox) {$ L, ~0 x' }0 m4 ]
var arrfbox = new array();, {: u5 w( I# J7 x3 j
var arrtbox = new array();
( G7 P: M2 w  ]0 I" V- G6 K5 Y* Nvar arrlookup = new array();
: J* K5 n1 b$ ^: o9 v: s) [# U$ Lvar i;7 G" C& w$ \9 V$ w6 O
for (i = 0; i < tbox.options.length; i++) {+ L$ g* m: D& y
arrlookup[tbox.options.text] = tbox.options.value;
; d$ i  R# J4 R' E+ S% Narrtbox = tbox.options.text;
! G7 E5 P) |1 M& H) a) Z) ?}
- Q$ P+ Z; a" F8 W( l5 x+ Cvar flength = 0;
" L) J# E( w& s' T8 h8 zvar tlength = arrtbox.length;
+ A/ \! v: @) g- U; z# \for(i = 0; i < fbox.options.length; i++) {, v7 j" s+ O( f. R" M, X/ P  @: Z
arrlookup[fbox.options.text] = fbox.options.value;6 x$ \8 E* |# n" F- p. i+ o
if (fbox.options.selected && fbox.options.value != "") {7 {# A( L( _8 h1 o" O6 {2 q! D4 N
arrtbox[tlength] = fbox.options.text;0 S4 [; \- x4 w; T
tlength++;1 x$ ~: J2 S3 Q' S1 I/ {
}" w4 k& v+ [" w* D
else {
* I4 t! G' ?& t- A# n" `6 garrfbox[flength] = fbox.options.text;
" w' S. b- J* l% Y" I8 M+ D1 Q- dflength++;
, T3 h8 F* x5 l9 C) G   }
2 ]$ e  ^9 M. e6 M% v% Q}
( x% D; J( O( q, P, S  carrfbox.sort();! \9 W* n2 B2 ?  {
arrtbox.sort();5 ^0 Y4 J: \# g7 U3 ]: I

1 V3 T, u7 P( Q& {1 G' `fbox.length = 0;: i7 G. k+ i% O
tbox.length = 0;  I; i+ }" S' P% t: J
var c;" |. Q# n1 m' s
for(c = 0; c < arrfbox.length; c++) {( E& r, m7 H- p4 b
var no = new option();
. N9 A- J! C4 B  b/ F# Qno.value = arrlookup[arrfbox[c]];
: ]; ]8 E( i* {" lno.text = arrfbox[c];+ Y. c& D( r! l$ {
fbox[c] = no;
" t4 D) t4 I$ k}5 O7 g9 c) l2 l9 w2 V
for(c = 0; c < arrtbox.length; c++) {
0 e( I& c3 R/ [& y# yvar no = new option();
+ f: k! Z3 j7 N! y, Rno.value = arrlookup[arrtbox[c]];4 W. A. H, |: u* W7 _
no.text = arrtbox[c];
( L  v: x0 h2 x# J& x: ctbox[c] = no;
: o$ f+ w/ R" t) e' m# \   }
+ t# z: x" s+ |% I}7 T/ V/ Y: f. d) w2 ~6 I
</script>
/ h* Y7 A& V; a. ?0 a+ f</body>& y& R. x! t6 D' _% {

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