返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
# t3 r) v& m% u& F8 r  n% }         c pageencoding="gb2312"
! V1 ?# x) `) t1 a! i5 |" `%>) _9 Z8 U3 D: |* \  L
<style>
8 J! f& z  ?' q. T# P2 M) R.f9{ font-size:9pt; }1 Q/ ]9 u9 @% D- J" X( @$ z
.bgc{ background-color:#aecaf9; color: #0033ff }
3 T4 a' G. g% B% P' r.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;/ W' Y: D' A+ V' b2 _
  border-bottom: solid 1px #4e7dc1;/ @; x' L' Z' A! z4 ~
  border-left: solid 1px #aecaf9;, y( B: r" y6 y0 n9 Z7 }7 ^3 y! y, Z( @
  border-right: solid 1px #5679bd;
: {6 I  ^0 D- C0 D+ I. ]! |. t, `$ B  padding:1px;
% E1 W" o3 ~- n  margin:0px;}: m+ F. O" W" K& {( \
</style>
, u% w% K$ A, _$ K$ r<script language="javascript">% B5 |8 [" o. a0 g
<!--
0 [# k( Z0 [5 Y7 hfunction rv()9 Z  |5 X) t1 C% m' b4 E' U2 m
{& B4 V. d+ b1 p
  var val="";' _4 G6 V$ j$ K/ `" e1 Z
  for(i=0;i<combo_box.list2.length;i++){
) j, C" n  W2 x% x' F3 y   val+=","+combo_box.list2.value;! d; n. x3 d# Z( r& h+ ]
  }
! T: _9 ], Y3 `; m- ^) s  if(val.charat(0)==","){: M% p' ]6 U4 S/ Q
   val=val.substr(1,val.length);
5 d6 U& f/ p5 @% n7 w3 l0 A, L+ g  }
* `1 X- d9 C$ P: H: o  opener.form1.frecname.value=val;
) ]4 t4 P/ G) ~* j: |  self.close();5 [9 g3 t! m( Z% n
}
9 P/ S3 T* a6 e+ A' E: c% g1 i//--># L$ Z3 N1 P! Q6 |; B5 c
</script>1 Z4 v* L8 c+ W# o  T6 O
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">9 Y5 \6 T  Z+ j5 `& ~/ R$ n# l
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />( f3 m: s, y0 r! {% d' e( n6 M: G
<%
" a! i: f2 ]1 ]% M  cdatasource ds=new cdatasource();  //数据联结bean实例
( u5 t7 q* p$ {: p: l  java.sql.connection conn=ds.getconnection();* M: c5 W% T( Q- r
  java.sql.statement stmt=null;- Z6 |4 Q0 Z' D, r0 v1 Y
  java.sql.resultset rs=null;
% d4 J2 C; q" W+ c  p+ }  cdatacheck dc=new cdatacheck();
- z- T- M* U# ~' E, _%>
. _; X6 X$ o$ p6 h; g& m/ ~1 x<%
- ?; }! G  G3 G+ A5 ?1 l; 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";" D. Z. k- I. x
stmt=conn.createstatement();& ^7 H4 \" d# T* [
rs=stmt.executequery(sqlu);+ \9 p- v. u& u* s, E6 C
%>
1 ?9 c9 x3 J% z* U<script language='javascript'>' X' [! {$ w/ M! b! x9 B' i# N
arr = new array();
& @0 a7 F0 \7 c; s7 o1 @9 y* C; v<%  int temp=0;" x9 f0 |" L- z" a, l) Y
while(rs.next())
% d- W5 a5 x8 w$ w( u+ M{
7 X# s7 l5 {5 \" C%>
1 J4 F' Q& _4 i( w/ o# t( i+ @arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
; t6 a6 g" l* B<%0 |* F8 T6 d8 _5 D, o: k: L
temp = temp + 1;
& J" ?- g5 k5 m2 s}
) d& z6 d& E* c+ K5 K; z%>% P0 L6 G$ J# K7 e5 \0 F
temp=<%=temp%>;/ l3 ~2 }& T6 P' l4 q
function changelocation(id){ . X( Q7 U0 _  J: S$ ]2 f
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 + u7 O9 i* c: \
var i = 0; 5 k1 }* ?6 J* j8 P6 w" ?
document.combo_box.city.options[0]=new option('-------','');
( P1 I3 V- B$ S+ A4 g9 Gfor(i=0;i<temp;i++){ 2 d; K+ _# ]) o- Q
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
; H  E3 h1 l4 C/ X4 P+ hdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); % e1 {4 o2 Z4 c( ^, n0 d
}
$ d$ I. b. @; s5 k}
+ L) G8 M9 p8 K  {) [" Z) B8 J}
, _/ Z, |$ _1 a</script>: M+ e9 R; s6 e

$ {9 j& ~; c2 B' O; h! S<form name="combo_box">7 A& \9 j! L4 m6 q9 D
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">9 z7 O3 }4 J" }$ P. @
  <tr height="24">: s4 p5 z6 d1 V* R4 D/ m; `
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>' c; d9 D  s+ u5 I! c
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>+ r+ m, h% U* w# ]( ?% C
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>  k4 S/ u9 W" s# R5 S' r* F
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
' \) Q; T  R. B5 @' @  </tr>3 U- a. d* c+ e
  <tr>
; _# T$ k! |. a3 ]    <td>; z5 c! {6 N! i8 S
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">' B3 P* ^+ P6 A
  <option value="0">请选择部门 ---></option>
, i! I' x0 K) l1 s& [3 ~4 Z<%
/ p' F" w" J9 P- u# \6 V    string sqld="select * from tdept";
6 `: g4 `6 a* U) G, l! Xstmt=conn.createstatement();1 \+ O' e9 e  q
rs=stmt.executequery(sqld);8 v( p0 o3 }! X- U$ }9 T+ {" E# i
while(rs.next())
0 e& X5 p% V, I  N+ \5 I{1 P+ l2 C) ]( Z% Y  y9 \/ |7 ^
%>( y; s4 b' w2 S9 P
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>( w% a* A& O1 q8 H9 t
<%' Q+ B& N0 c; z  m+ [; c' Z
}% j1 l- [2 d) t% k
%> 5 p. n* Y8 l  E7 ?" j! c: |
  </select>
7 h2 N5 M, T  ]! N: A</td>8 f1 ^( s7 ]2 d9 g
    <td>
7 l9 j/ ~. [3 x% |- ~  <select multiple id=city style="width:150;height:200" class="bgc">3 C0 L) P: G( n; ^  p+ Z
  </select>
8 {' `% U& k( _5 Z, x</td>4 n  ?  c4 E" X. L$ K
    <td nowrap align="center" class="bgc">
% x4 Y4 B  T  F/ A1 n5 j% A  <input type="button"  value="<<" class="buttons">
  i7 B0 e; T. H& K  <input type="button"  value=">>" class="buttons">- h4 h8 X5 f5 h3 \: A7 k
</td>
9 l4 y- K6 B9 ?9 O/ `    <td>: U% V/ ]6 z/ o( y/ F
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
1 K! ?" T0 m2 b  </select>
5 Z9 U0 f9 _7 t7 r' l</td># a  C, @: }( t6 ?( G# y# h$ [
  </tr>9 ]5 t4 ^+ K4 j: J1 z. i& a( Z3 Z
    <tr class="bgc">   ~* N% S) o! Q
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>% `& W3 l" \5 {: C0 F" d2 G
  </tr>
% \- ^! y; \* `7 |</table>; M/ r" y) h# R" M- ]  _- G
</form>
6 H7 j- C- A: a( A<script language="javascript">
; s+ I/ @+ u- }//人名移动6 f7 \/ i5 P7 Z: q. I
function move(fbox, tbox) {( I) r# ]& {: J
var arrfbox = new array();
5 t; \9 y4 j9 h- N+ wvar arrtbox = new array();
# t7 ]6 V. b# X5 [4 J- hvar arrlookup = new array();
$ L$ H* y' }! D9 K7 Y! X/ I; J, pvar i;! D2 q7 j  L$ \8 O2 K) R) I
for (i = 0; i < tbox.options.length; i++) {
( ^/ Z, e# N; barrlookup[tbox.options.text] = tbox.options.value;
+ o# I& A6 @( T$ A0 ]3 {/ parrtbox = tbox.options.text;
0 I( L  D% l3 v2 C& \" v! a7 m}
- }2 B8 i3 r) O* V& o6 Fvar flength = 0;
8 m& `" O0 A3 Q  ^: |1 Jvar tlength = arrtbox.length;
, e3 a2 V% r2 h7 E! j1 S8 k% Dfor(i = 0; i < fbox.options.length; i++) {
4 R# ~9 u5 }$ ~- Tarrlookup[fbox.options.text] = fbox.options.value;6 n3 z% L. ]( ~  F( C
if (fbox.options.selected && fbox.options.value != "") {
% \% U/ N# h6 R, u- U# F5 ]8 v; y, aarrtbox[tlength] = fbox.options.text;
- a% A6 Y. W# _4 d7 K! Qtlength++;
1 D  z0 u7 P) w2 n# t  P0 n2 S}
1 h1 o) k% {/ v  F, G* h) Nelse {1 J# L: [( }4 K7 f  `1 _
arrfbox[flength] = fbox.options.text;
; ?- K0 @" {8 b4 O# K% b5 Aflength++;
2 w: _" q7 I7 j   }* P7 ?* J" D+ Z3 p
}
* b1 Z" u4 J& W: l. z7 B. z. iarrfbox.sort();
# b8 C$ U! d& F; X5 K+ R' q; a8 Parrtbox.sort();3 [* L# x8 \! V9 u
6 H! Q* r) K7 O$ N5 b# y
fbox.length = 0;, p! i3 I% _" @4 Y+ k
tbox.length = 0;
+ [' }2 L2 Z% X4 b$ Kvar c;) G& \' U0 t5 ~$ [
for(c = 0; c < arrfbox.length; c++) {' P  v# c* a" O+ T& o, W5 E
var no = new option();
0 q, h# p* U$ {5 k; i' Bno.value = arrlookup[arrfbox[c]];( e" N$ j9 b$ K6 r7 c) F
no.text = arrfbox[c];& T6 U) Q" Y+ G
fbox[c] = no;
+ t/ \  |9 e- X( X}
. G$ W8 F7 O3 f, h. z( N( ~. }for(c = 0; c < arrtbox.length; c++) {: E. a- m' d+ Z* f- B
var no = new option();
6 C, S! M( q$ P0 Y! b  W/ Nno.value = arrlookup[arrtbox[c]];4 x/ t; R- y7 R8 `! P" V
no.text = arrtbox[c];% F2 w7 T0 k+ n# L
tbox[c] = no;
4 o, Y, n' K# j. K   }
  S2 a7 ^1 x( Y: v0 W5 X( O/ l}
& X- B6 k% y" q  X</script>; B: W* ~9 u% {( W0 z- Q
</body>
8 O; ~/ ?8 j! J/ Z+ b1 e9 T, T2 I

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