返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"& r* B( T4 h. a9 r
         c pageencoding="gb2312"7 j( _* i. t" r% b! v4 Q
%>
+ \) U5 d& O" Z<style>; v! b* v8 e& `" ^3 T
.f9{ font-size:9pt; }
4 T: k# b9 j5 @& C  R8 b6 k.bgc{ background-color:#aecaf9; color: #0033ff }
# l& F0 a6 b* ^4 p: v6 l, M.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
- ^3 G! L& o& [; {. k  border-bottom: solid 1px #4e7dc1;
; w9 B0 B3 a6 M; o4 s% M  border-left: solid 1px #aecaf9;% ?% L! G/ _% }8 W/ V. z
  border-right: solid 1px #5679bd;
6 q. M( b  Z8 S+ `4 e% M) g  padding:1px;
! |, g& C2 Q% t5 @% ?. D  margin:0px;}
7 Q( i: t3 _2 W& Z2 F1 B</style># w$ p. j5 a4 V" b
<script language="javascript">, t1 p" }# s# u; J0 t3 K
<!--1 m: J; j2 }( w0 t4 u& v2 H
function rv()
: {( a$ ^" z% @; L% P1 g{
+ {: T. J( h+ X; `5 F* W  var val="";
/ h1 N# f0 q" _& s1 l  for(i=0;i<combo_box.list2.length;i++){, [4 v' m3 Y) P4 P
   val+=","+combo_box.list2.value;
# ~8 ?8 c2 c* E7 J& ]4 x  }
9 S6 R' h; M( n4 }/ F  if(val.charat(0)==","){
' s) q6 @' o$ c  w   val=val.substr(1,val.length);
1 x  ?, f7 R8 z' v: y  }/ k( G% x3 u9 I2 Z) N
  opener.form1.frecname.value=val;
  T- X$ t2 R2 @6 `% ^& t  self.close();
2 O% m3 e1 T6 l3 S7 }3 G}
0 @; l6 D: v( x0 u% }//-->$ R4 Z1 H6 G5 Y* m
</script>
) c/ q7 P: N/ x3 C: ?<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">4 D6 z4 K! B6 q* B
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
% `: b/ D1 P! _7 b# O9 R+ h<%- L$ X/ j# n, [' L
  cdatasource ds=new cdatasource();  //数据联结bean实例) p5 d& C8 M- ?# H( c4 _
  java.sql.connection conn=ds.getconnection();
( F- R) t% u  u! g. L7 r! q  java.sql.statement stmt=null;! X4 F7 Y) ^/ P3 M9 W- ^/ s
  java.sql.resultset rs=null;! J" N, k' Q3 m' N$ l% v$ h: \
  cdatacheck dc=new cdatacheck();
0 i' }! ?2 e6 d) R%>
( {1 a/ R/ F& y<%9 H/ T+ U9 V; L4 S# ^: |+ J; q
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";
- A3 f  q  r0 |/ o, Vstmt=conn.createstatement();
, k. c% O# R! ^/ i( Yrs=stmt.executequery(sqlu);4 p: r( {7 [2 Y% k) E3 B
%>2 U# P% U' S/ y
<script language='javascript'>, T) ?: {; ]9 N. a+ Q
arr = new array();
4 g( D' q, K) z1 X9 ~<%  int temp=0;
6 M* B' u1 I3 x  \: ]" C% _while(rs.next())* L6 v: A. m, f+ N0 M# a" W( [5 a$ W
{2 m2 m* b! _& L) ]  G
%>3 J: B: }! h/ q
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
9 Q) X7 |6 w, l, x<%
8 Y9 c& e& H8 r) @temp = temp + 1;7 l5 D5 T- s% s0 N
}" p6 U4 w6 G% A. u% v8 C
%>2 E, d6 r; S$ C) E
temp=<%=temp%>;8 s# ~( }5 Q& u3 j( Z+ y* p
function changelocation(id){
3 G2 R8 D: U9 O) Y  s% r) u) Sdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
; |' P' o( |  r( rvar i = 0;
8 c4 Q8 l+ l6 i, P6 _% Qdocument.combo_box.city.options[0]=new option('-------',''); ! x7 a: K0 H  |4 ?
for(i=0;i<temp;i++){ 7 o8 b, P( V4 j: f% `- P' S
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
& g8 Q2 H+ g- j% |# g. Mdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 9 d1 r3 u1 x# U" ~! p
} 5 a& @# @, _/ q
}
6 O& }4 ?1 a9 [: h) k- M' X$ `& B} 0 e9 J# S1 i! p5 {: X: \' C
</script>
9 P. \# S8 L* n+ N
0 H# q1 u- g$ d; m: O' ?<form name="combo_box">3 E% a. G; l# \! W% L+ |( g$ Q/ `
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
  H8 O0 W+ \* \4 w5 M* \  <tr height="24">" C; H  b& w% @% f0 R
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>$ L4 d4 y6 B: _; r" b$ J
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>, K: L! `9 x8 c' o6 C6 m. V
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>/ D' j. p# G' Q8 b$ }0 e  f1 _) @
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>: n1 {. g9 W. @
  </tr>8 p( a* K' L. A# e5 d0 ~% P
  <tr> " ~/ T5 s( ^- Z2 C% i- H1 n) t
    <td>6 m# q1 r- v0 I, d( h! F1 k0 G7 n
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">/ ?' H# K8 q0 t: f
  <option value="0">请选择部门 ---></option>' d* y: H9 n7 S( g
<%& `& C% u2 `$ F4 A
    string sqld="select * from tdept";0 B# o0 l9 h4 i
stmt=conn.createstatement();
/ F+ |5 ]) ], _7 h3 y; C, vrs=stmt.executequery(sqld);
, C0 V# s' r0 n7 Q2 X* Q- cwhile(rs.next()); F" m4 V+ v# N( Q8 a
{2 L, v1 c3 \* w# q' D
%>
5 u6 V/ `$ R9 d0 v  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
8 C9 Z- a, a# ^1 s, B( i3 A0 b6 |<%9 v: a& ~4 x: |+ D
}
/ \! v) K6 w, c3 |: B" |' p& ~4 v; r%>
% g( A) a% ^$ m. _, P  </select>$ G: v3 e# \6 K( r7 o+ b
</td>
) H6 L, H" ~2 n" }8 g7 d" s5 c    <td>
$ v$ n$ S) {( o) S/ K/ O  <select multiple id=city style="width:150;height:200" class="bgc">
0 a& ^2 ]: R- G  </select>  x' Y# m. g- s& o+ D
</td>
: m2 P- L- u' B+ t1 ^; O    <td nowrap align="center" class="bgc">
+ C- f. D0 C0 O" a: m7 \6 Q  <input type="button"  value="<<" class="buttons">$ B. X8 f- R5 r# m) U
  <input type="button"  value=">>" class="buttons">
0 w1 c7 G- z  B2 B5 h6 |</td>
4 c5 w1 D* {# c% Y$ Q    <td>
& j2 S0 q6 J* W, Q$ I  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc"># W" ]: @% O, A# v- L( ^" ?
  </select>5 E. _# T7 _/ F0 U, M. X
</td>
% U/ N+ C+ O. o4 s  </tr>9 q7 h5 p; u: p- \) P; A+ ?
    <tr class="bgc">
' G. O# E! j0 m* l: p3 E    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>1 I$ v9 e4 S, I" [
  </tr>2 Y" a. x* U. B  s) e9 r2 O
</table>5 A5 n* q1 d! j5 A9 u3 a* {6 j
</form>" C. f% ]& q9 J, i' C+ k5 x
<script language="javascript">: q4 c* a: d& u( B9 \( K8 ]- }
//人名移动" d+ b9 x8 D. n
function move(fbox, tbox) {) k* n( [8 w, T, O
var arrfbox = new array();
+ i; r3 N# [# i% p& j4 ?var arrtbox = new array();
2 M/ N0 U& m5 {# d  d: m; t4 W) Jvar arrlookup = new array();% O" E4 D$ @1 }2 t3 M" K6 F
var i;& c! g. b8 }# w$ t
for (i = 0; i < tbox.options.length; i++) {- k1 e0 }7 y" D( C5 p( q1 d( k- R# E
arrlookup[tbox.options.text] = tbox.options.value;) A& l3 i& F/ X* w- o$ O; L4 z
arrtbox = tbox.options.text;
! L! W+ q: w/ G7 _! _5 `1 `}9 s9 e3 W$ {$ i2 K/ D' i" @
var flength = 0;+ b  `- O) M: }, w; X
var tlength = arrtbox.length;; W" {: E8 u+ A$ ~; {
for(i = 0; i < fbox.options.length; i++) {
( |5 F" [( t. S, h$ m+ karrlookup[fbox.options.text] = fbox.options.value;# x. v( y; W/ t1 }* J& N
if (fbox.options.selected && fbox.options.value != "") {
8 o& Q* b' O# e+ c/ l5 Yarrtbox[tlength] = fbox.options.text;
* J  x9 |  L- Mtlength++;
5 @# z& ~3 B2 s/ o5 Z) \}
( v! p# G: b/ f+ X: Z) D9 `* y1 E0 pelse {
, P! ]0 h) G/ ?" I" O5 varrfbox[flength] = fbox.options.text;
( X& m% Y4 F9 g8 z6 c8 Mflength++;
  [- R3 Y6 k; B: H   }  r9 N3 k$ u, u  Z0 O' A( q
}
$ b; ?9 i" J! d2 K! v  k- B) ]! qarrfbox.sort();
8 Z. W6 [3 U; C) i# Larrtbox.sort();, m* B; r! {6 r% F, ?  ~! g

! {& q; e" N3 ?5 j6 H! C: S( hfbox.length = 0;# L4 G5 G! h5 Z4 e7 e
tbox.length = 0;
! [  K0 w; Q6 i+ E: L6 L, svar c;
; {3 M$ h( U2 j. A% v$ t+ R7 Xfor(c = 0; c < arrfbox.length; c++) {8 S9 w" N8 w' B5 ]! a
var no = new option();
  h' m3 R. C1 p! v+ \no.value = arrlookup[arrfbox[c]];
% R% s; w$ y9 U4 [. ^+ j7 `+ ^no.text = arrfbox[c];- V0 _" X5 R. g  y) z" E
fbox[c] = no;/ t& N* c9 P; a0 m& }2 \0 M6 u% Q* I
}2 B/ A5 h9 m, W- x" O
for(c = 0; c < arrtbox.length; c++) {
8 d5 q* c* N8 c) m& Jvar no = new option();! K8 d" v' ~% F  j# u! W1 ]6 H
no.value = arrlookup[arrtbox[c]];
; n. C4 b* Z. x  rno.text = arrtbox[c];9 B  f3 D( ^9 R8 D7 H
tbox[c] = no;
! R9 |; ]% H+ e6 I" o% \5 W- ~6 z% w   }
7 i$ g7 x6 F/ A9 D5 t8 \}: h9 R4 [0 i; }6 E9 G0 l9 E; z6 a
</script>4 s: J" `$ \) X: q
</body>
  t. ]- ?! \5 t% X$ M4 c3 Z

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