返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;") l, D4 Z" A$ Z, Z* E3 _
         c pageencoding="gb2312"
9 q) i6 S$ ^4 _7 d%>
& W. P% d$ e9 B% l, o<style>
% P3 j: |. W( v1 _. t5 `4 ~  ^0 P# J) e.f9{ font-size:9pt; }
7 B  ]* M8 U5 i6 t. c.bgc{ background-color:#aecaf9; color: #0033ff }
, g3 c9 y& i9 ~% m/ Q, }.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
2 K! W- ?% W; @, R, Q' l  border-bottom: solid 1px #4e7dc1;
* O  F- H+ r. ?6 n  border-left: solid 1px #aecaf9;5 z2 e6 |8 }4 S& y% n
  border-right: solid 1px #5679bd;
% ~; ^* G, }- A( f  e$ A5 ~$ ~  padding:1px;
. w5 e0 H8 N; G" T: E+ r  Z  margin:0px;}
0 Z+ K( y/ C3 x+ S/ u6 v) g</style>
. R% c) \& X& _6 ?2 C0 }<script language="javascript">
, A- E  P, Z/ [<!--1 c- g8 k! Y. P1 @! A# r: i* R6 ?
function rv()0 _) R" P2 i, z0 Q9 j, J
{$ f2 k, R& d# C* t  t" L
  var val="";9 v. i7 a" n: ^
  for(i=0;i<combo_box.list2.length;i++){/ G5 h% {7 F! R/ }$ y0 e
   val+=","+combo_box.list2.value;" b4 W- E. L: T+ q8 K% \' y
  }9 w$ I3 q" t' _: E. Y$ A
  if(val.charat(0)==","){
/ m5 f. S! M% C) w( {   val=val.substr(1,val.length);- N0 q3 E) P+ F0 f- @% H. `" h
  }: j! `: _3 v( @* x  Y$ o6 D( e
  opener.form1.frecname.value=val;
$ Q7 C( v8 c& X( x  self.close();
* K. f4 |' T6 U1 R}, c1 ?6 O; C' B6 M6 T4 F
//-->8 J, P% S/ _  z6 Y5 r
</script>
( f5 M( H! t! z6 Q5 B<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">2 Q0 H7 r' _. P" [
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
+ t" W) W/ i5 W9 y* R. k7 @<%" D/ h  ?% `3 }+ w' K1 N7 ?" e1 [( o
  cdatasource ds=new cdatasource();  //数据联结bean实例
' i: b3 S4 J; D% i" W6 }  java.sql.connection conn=ds.getconnection();* {( L2 C0 I6 k
  java.sql.statement stmt=null;
4 `: S; a/ |- v9 U2 f  java.sql.resultset rs=null;6 F) {) |% p. V
  cdatacheck dc=new cdatacheck();
4 F  n' J; ^( L& T+ A% q* t% ^%>
; L) A. X. L4 b; |<%  r9 l7 z9 S  r5 e6 D  }2 K0 d) e
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";; o- a+ k* w& \: G
stmt=conn.createstatement();
/ S1 i% m' h: p8 X1 ^rs=stmt.executequery(sqlu);, R2 R& N) x" H. @
%>
& R( [0 z" `9 l, h% \; m$ ?( ]<script language='javascript'>
7 g; P2 _9 p& B6 y, `arr = new array();
( Y) ]& M8 t3 V/ R6 K9 e+ s$ N<%  int temp=0;
! J+ \" j# Z% q; ~. _3 v* l. H) swhile(rs.next())
* }7 \7 w/ B" F1 |" m3 `& U{
4 U- p; R  N$ x5 V1 [4 ~; y: d%>9 j! K7 c8 h! Z- w1 z
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");& \- z$ g6 h3 [/ J9 G* N( S
<%+ E( S* S6 {1 I% i/ @; p% ]
temp = temp + 1;
( U) ]" o5 s, H' K' X$ k2 Q9 T}
# Z( y2 Y1 Z$ ?; q" V; P9 h%>4 P, v9 @8 W! o7 e/ Y$ q
temp=<%=temp%>;
% _! }# M8 H: j) z  {5 ufunction changelocation(id){ , P+ x! a5 U8 I: a4 Y
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 ; T! j: Y5 q. s% @! N- b
var i = 0;
7 J. L3 w) s1 [$ _/ ^- mdocument.combo_box.city.options[0]=new option('-------','');
5 ]8 {$ n7 O  P1 e7 T' h# Kfor(i=0;i<temp;i++){ % b# C8 A" U; e# p* t0 p) r( U4 c
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
$ k* z4 x" j& }$ i4 zdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 0 s# n( t3 _7 s- Q
}
2 D$ x, U, Q$ [, i- V}
+ G* c9 g6 @; V0 G! [}
$ N& D; o, H7 @/ _1 T% b</script>
( P/ k* M9 T! P, W4 D2 C2 B+ f8 @  |: ^+ z( W1 P: M
<form name="combo_box">& l' p# L# t5 y- v  s0 b1 O$ s
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">. W" \; y7 }5 ?+ W- K. J
  <tr height="24">
" {' ?* ^5 T- y4 Q9 ~8 ?8 {    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>0 I' F  |. d5 @4 C0 N
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td># I0 p! D9 Z3 M- Z- r
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
3 E1 v8 g9 z# J" X1 Q! B$ U    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>+ m9 S+ @6 ~, c3 e
  </tr>
0 L7 t: ?. \6 w- h/ a" v8 r+ L" N  <tr>
$ p7 U- Y( V* N: F' n    <td>
9 b9 R4 {8 Q3 I7 W4 l6 B+ h0 ]  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
8 m5 B& y1 j  w, ]2 y8 E+ I  <option value="0">请选择部门 ---></option>) x+ j- ~/ T+ H" P
<%
. f* M- a8 I9 ^) y    string sqld="select * from tdept";% H8 Y, m/ J4 ^9 C+ ^$ J3 o
stmt=conn.createstatement();  P5 `3 @: Z6 }
rs=stmt.executequery(sqld);8 ^, V! R6 s% V: H% c. B
while(rs.next())
5 q1 B! D; D* Z2 N2 ^. c% e, g8 |{1 C  i  ^& k: _& x$ r
%>' Y0 T5 z, V$ h2 B
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>- O) K8 }3 G0 W
<%
* i: o: {- Y$ u. L5 I2 z}! S/ @' {1 S  j' ]* }* d/ a
%>
$ ~) O7 L% I6 j  </select>0 y5 v: l* a2 d  _2 B
</td>/ {# E$ q* w; K
    <td>  q4 d& y" Z$ X3 f
  <select multiple id=city style="width:150;height:200" class="bgc">; q- [3 E- g. e% z+ A, |) z6 {3 J
  </select>
4 \  K; Q- {: D3 c/ a" K5 v$ c  z</td>
- g3 b6 w% J2 y6 M4 K( J: a    <td nowrap align="center" class="bgc">
0 \; v/ Q9 q9 G+ V& Y- D1 W' ~" ?  <input type="button"  value="<<" class="buttons">* _5 t" r% i0 Q$ y' E$ `+ ]! v1 S
  <input type="button"  value=">>" class="buttons">- M/ K5 {7 R$ K( A( ^" Z' E/ e# z
</td>
) @* z5 O' r; H0 d5 R    <td>$ K0 o9 s$ E$ P2 M, [8 {
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
7 q# E: A5 Y& {( M. |$ @- L  </select>: z6 L: E$ O! }8 ~
</td>
  j% e4 s) @/ P3 _$ b3 I8 e7 C9 C  </tr>5 H9 P. n, P/ t
    <tr class="bgc">
. M% ?5 t+ a& g    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
' g6 B7 v- |+ ~, {  </tr>
4 C3 w3 K5 A7 C: u7 {</table>
/ {5 l9 a/ C) a3 {. x6 s- h</form>6 q7 i* z+ e! [
<script language="javascript">
( M9 t( r4 U8 U! }//人名移动, X, q! H9 X8 ~0 A* O4 [: w
function move(fbox, tbox) {3 |$ v( r" g  ~6 C
var arrfbox = new array();5 X+ g! E6 y* E* e* h3 [
var arrtbox = new array();0 v4 ~0 E. I. V7 R# H$ N5 n
var arrlookup = new array();
, @/ @1 J9 N% Dvar i;
9 D% E( s/ g! lfor (i = 0; i < tbox.options.length; i++) {. V0 T  I( s. ^
arrlookup[tbox.options.text] = tbox.options.value;
( m2 ]% t% m8 B8 w# j9 b% Varrtbox = tbox.options.text;
" y4 W  C3 v3 D+ h}- m/ h4 ?5 X0 l" h
var flength = 0;) |/ D+ s8 k; p- E( ?  b3 ?
var tlength = arrtbox.length;
% O# u0 ?# p* F3 Z8 d/ C6 Dfor(i = 0; i < fbox.options.length; i++) {
- y4 M) ]9 [7 p6 y# ~# R3 H  karrlookup[fbox.options.text] = fbox.options.value;
; @$ Q0 @: b1 D4 gif (fbox.options.selected && fbox.options.value != "") {
) }  S: G6 n& m$ s8 T) Larrtbox[tlength] = fbox.options.text;
% F. ~# {/ \0 t1 N1 d2 n- K7 ltlength++;) `5 Z; x. k1 `: |
}2 o* H- ^% z" v! i3 b
else {
* ]6 @) C. T5 c' p; e1 uarrfbox[flength] = fbox.options.text;- M8 T9 ?2 U, ?6 [
flength++;7 k- p. Z: d  V) k5 N% X# U! _
   }- j1 }/ D" ^3 ]. O! C+ ^
}
) A4 v3 h2 T( o. R0 C4 Earrfbox.sort();
2 @" Y* s, o8 q7 karrtbox.sort();" q+ a: r2 a# ]/ z( d3 V

8 k# K9 J) v% J, s; o: xfbox.length = 0;
- i! C& ^3 E/ X/ J4 s* vtbox.length = 0;2 J7 R6 l! M  R( E- X
var c;6 L7 h" H2 }4 V  w8 B1 I
for(c = 0; c < arrfbox.length; c++) {
: d- J7 p0 G2 @. _0 M1 a! rvar no = new option();4 d: f9 k" s5 G5 m+ U$ B" D
no.value = arrlookup[arrfbox[c]];
  c. X9 `, n# `" s1 sno.text = arrfbox[c];
% w* y+ S) H1 b/ q" z  ffbox[c] = no;
7 D& R$ W, Q9 |" ?) x  s* }( X}" b( l' G8 n: {  q' Q
for(c = 0; c < arrtbox.length; c++) {
; G9 A0 a9 R+ A8 F$ j& l) `7 `6 Hvar no = new option();2 x9 O, s/ R8 s6 ~- \' v$ u8 P
no.value = arrlookup[arrtbox[c]];3 h, c" W8 R0 v; K7 C3 F8 c
no.text = arrtbox[c];. v5 M2 C6 z1 K+ a! z7 y
tbox[c] = no;4 h1 Z" D( ], X  e6 d: {! M6 m
   }
2 F9 W# N! K7 q( J3 _* Q}
( Y( k5 N& j4 t/ G</script>" c7 b) Z) r; ~* I
</body>
9 c% n% p/ D9 i5 b. z4 i9 Q

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