返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"! c8 K: z( @: L
         c pageencoding="gb2312"* ?! V( L1 X& }# S; x0 |% `6 ]4 l
%>
' D' @; ]& h' O+ Z3 c" L<style>8 m$ F" I; N% I% v- U
.f9{ font-size:9pt; }
! {8 B* `; Q% H, o; j- x.bgc{ background-color:#aecaf9; color: #0033ff }+ r) F' u+ T9 v
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;4 F; @5 T6 Y( x/ Q& y
  border-bottom: solid 1px #4e7dc1;
2 S  w) ^1 b6 X) y. b  border-left: solid 1px #aecaf9;: h8 ?, J: c) c  f+ S1 [, A" R2 D
  border-right: solid 1px #5679bd;( l- f# E6 I0 |& H+ R
  padding:1px;8 Z; ^- Q* x6 \0 `; P
  margin:0px;}
' ^( X9 k+ G: u" z</style>
/ [( ^4 w7 z  r9 C. R9 j2 l& x<script language="javascript">
- Z- D, V; Q* w( y  P+ {1 m<!--
& Z1 F, B/ s% c8 f  x8 c0 i. g& Y  ffunction rv()
! S0 Q: E6 s$ K$ Q- E5 B3 X( t% s{
5 _3 z' T, c0 O$ W8 j9 v  i  var val="";
9 V) u, H2 X& r0 a  for(i=0;i<combo_box.list2.length;i++){+ G6 x1 z* h% h5 X2 K+ w) |
   val+=","+combo_box.list2.value;
5 M; _5 E% H9 ]- j5 C  }7 H6 Y) A' W: b% ?; _: q8 H' u
  if(val.charat(0)==","){
# O, u6 I: S" I  z   val=val.substr(1,val.length);& g& g/ \: |: ?8 l- A, C7 k; ~5 f9 A
  }
" T& x+ r) D0 Y( h0 C5 C1 p/ E  opener.form1.frecname.value=val;
  B, B& ]0 b: `7 W2 b) k  self.close();
: T# y4 m# x" ^* o8 ?, E7 X}
" }; A% ?4 M4 H* ?+ J! ?; q4 j//-->
. J! W. j: Q) u/ f</script>
! I7 W- f  G1 _( q<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">/ q; \5 t/ q3 [5 B0 W" z( o
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />& i& k3 Z$ L) N8 o( ]' z4 ~4 l
<%/ g9 v  e" r9 g
  cdatasource ds=new cdatasource();  //数据联结bean实例2 I) V6 U$ C8 S
  java.sql.connection conn=ds.getconnection();
+ ?1 B6 P( a5 P) K7 I" o4 S2 \( H  java.sql.statement stmt=null;. ^0 K4 U6 M; H0 O  c; H7 G3 x* U2 d
  java.sql.resultset rs=null;
! l0 V% ~. k- d: i. t7 Q  cdatacheck dc=new cdatacheck();& j1 A8 G$ z1 F/ x/ }% s3 t
%>
  B! u5 p$ R& {+ L<%
- z1 u) E4 e% k, R* z8 Mstring 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";7 h4 O, q) V5 S' i  B
stmt=conn.createstatement();2 t! J) b+ l8 P1 E8 y  _# Q; H; I6 J. d
rs=stmt.executequery(sqlu);
  V* B* L5 O0 A; \% M0 Y+ `%>5 A. Z* A1 ^. q8 A6 r+ g7 E
<script language='javascript'>9 @# }7 H/ C  Y) Y! B
arr = new array();
, T% i  a6 `! L! I4 W6 M<%  int temp=0;
. C$ }; s& z6 ^1 e# U" Q. @3 ]- ~while(rs.next())( O9 G2 g5 m, M( ?) Z
{
+ j1 i( Z3 }" P( j4 |%>  q) V# N1 j- ]2 c
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
: {6 a9 w6 c  W3 R7 C9 H<%
0 o* j# [# C3 k5 xtemp = temp + 1;
$ S- P# S- S$ L1 Z8 C2 L}
& j1 W9 f" Z0 y* M& U2 o6 U; [%>& L  I* S+ Y# u
temp=<%=temp%>;
. n# c" B3 a! g2 U) tfunction changelocation(id){
+ ?. i$ @  u9 m4 V4 Z0 R( [document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
) Q  w. Y) o. u0 k4 T* Nvar i = 0;
: n8 f/ e9 r+ [+ e: _0 P+ o+ u6 c0 Vdocument.combo_box.city.options[0]=new option('-------',''); $ q0 ?% U. n5 E
for(i=0;i<temp;i++){
0 d( M1 {: F( r) Q+ eif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] % p  v0 }) G1 M+ X- w- F/ F
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); # a6 V) S$ W" p7 L' E
}
* r: p" V# s) z7 F0 [}
+ I+ s& o0 x+ J$ c: w} 6 Z8 R+ s0 J7 r# ~$ H
</script>9 N5 M! ^8 F7 m9 d
3 J1 @, T% b: f: s. @! g  {# i
<form name="combo_box">
2 h. E) l: r  v, D3 d% w<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
' X. [% S, O- A& X7 M( m6 Z  <tr height="24">
& ~5 k  W1 Y& ^' T    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
# F2 q- R' j  |* @    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
8 x! g/ A& n* f6 S- ~4 J0 H! U    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
% u% }3 c8 k% U6 \    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>" J) ~: G- i; n$ c
  </tr>' j. s: V/ Y3 y( e* B
  <tr>   C2 q- F2 R8 o$ g* K
    <td>
+ [9 X- O) R5 N/ Q( W$ R( r  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
8 A7 ?6 [2 N& p  A- r% J  <option value="0">请选择部门 ---></option>0 J1 s5 }4 T) f0 ~9 Z
<%3 f3 _& g% ^/ y) y
    string sqld="select * from tdept";- R! ]9 y/ V3 E) @$ @$ l
stmt=conn.createstatement();, \1 \2 ?; T/ S" m
rs=stmt.executequery(sqld);- u8 J" T1 E+ R- |& U! ~
while(rs.next())
) W1 Y; l2 j/ c/ _2 V$ p{
: v/ _0 N& f! _' {%>2 Z; y  v4 M! R* S1 [" H+ |, g& @
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
3 i$ [2 X8 _& [( L<%
- K1 I; v2 O1 g5 Q- r3 C}6 A% t7 u/ k' f. c
%> # H1 T8 C# Z4 Y4 J+ O
  </select>5 N8 ^. M7 h5 t( k7 s1 I, `
</td>! t8 l9 K  L1 l
    <td>6 H& T) e' g3 Z6 g! p
  <select multiple id=city style="width:150;height:200" class="bgc">" J* G% c' u8 m2 S. a
  </select>
* w6 F, f( G; Q1 M/ s" R4 M</td>
% p5 B6 }2 w3 F4 k( t- J3 G" p) j    <td nowrap align="center" class="bgc">8 r4 q( P/ E' {. k) e( `% \2 t5 O
  <input type="button"  value="<<" class="buttons">; U7 `4 y1 i5 j; e) |' \
  <input type="button"  value=">>" class="buttons">
2 b' E" y6 O. ?/ q0 R& S. d2 |</td>8 h" [. b+ B4 a, h9 S& D( O2 ^
    <td>
1 L4 z4 F7 u* m  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
' d" w5 u. l5 o: Z  </select>
% L; R, D- J! E% U+ w</td>
* c- q* d# z9 v1 j$ P  </tr>% M. s8 N4 U# S* d+ ^% J
    <tr class="bgc"> 1 I% X$ k# r& ^% g# g
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>5 m& S6 q  d6 Q
  </tr>1 F2 O+ t) R$ a$ _+ Q4 B$ N
</table>4 U8 @: d, I# L% ^
</form>" ]( t8 n" s% E$ Y( b! U" j0 f
<script language="javascript">, N* g) e% t6 N! A- S% M, c
//人名移动
  t  i  l+ a. `' x3 R0 h/ J3 U1 Zfunction move(fbox, tbox) {, a% f* Z, p" }
var arrfbox = new array();
, k$ k4 H2 ?+ A+ k- J& d; Cvar arrtbox = new array();' K" d+ @+ W6 x
var arrlookup = new array();
5 d8 d* V" d& V8 Hvar i;+ p* }4 S+ O3 F7 ~, M8 o) s4 q
for (i = 0; i < tbox.options.length; i++) {* Z# {0 @& c: K- b
arrlookup[tbox.options.text] = tbox.options.value;
1 {" Q0 K% u5 U) w. b  x# farrtbox = tbox.options.text;
% o* C/ `  c. X- v9 T}
; Q$ n3 W" Y3 r  T- Wvar flength = 0;
3 V0 I/ r, b: Z4 `var tlength = arrtbox.length;
$ {" M2 Z+ k1 i/ Y9 D$ Vfor(i = 0; i < fbox.options.length; i++) {8 C, g$ `  N0 f
arrlookup[fbox.options.text] = fbox.options.value;; o$ H" q) a! d4 {; r8 Z. d: X) G
if (fbox.options.selected && fbox.options.value != "") {
% _$ J/ T$ {! e7 P' W4 uarrtbox[tlength] = fbox.options.text;" o9 Q( X- {# v1 s& \+ a
tlength++;0 L" `: h) W& I; Z7 H; S
}' P0 c  d1 |. L- g2 f& M
else {
& V6 Y3 o5 o6 harrfbox[flength] = fbox.options.text;' n! t  o2 B6 O' R
flength++;
2 k; x! p2 ~( J   }
1 _4 A. x# c6 ?1 K}: W$ G; v+ I3 E& w6 m
arrfbox.sort();, y- Q  J0 m! t% Z, v7 }4 a
arrtbox.sort();8 b# K2 m2 _9 A( C3 k

2 y# z0 M- \1 o4 u, R: Nfbox.length = 0;) f/ c$ a3 L$ X5 {3 H7 _, `
tbox.length = 0;
# e8 ]" w1 q! J' xvar c;
+ A8 g( d( o+ D+ vfor(c = 0; c < arrfbox.length; c++) {
. X) _0 Z$ ~9 S$ O' h. nvar no = new option();
  c! W6 u% I& w& lno.value = arrlookup[arrfbox[c]];
% m5 r8 f0 p2 T" Y6 V; }) bno.text = arrfbox[c];+ ^' R8 i) h" f$ M$ C
fbox[c] = no;# M6 A: D3 v- o; L- v: w
}
) |0 ^4 B- y5 Y4 k/ F6 cfor(c = 0; c < arrtbox.length; c++) {8 `; P7 J, o; t+ r- {
var no = new option();
2 e: w. g9 R% u* B0 f1 qno.value = arrlookup[arrtbox[c]];
4 Y' I$ X# l$ \2 ^7 v" o% kno.text = arrtbox[c];2 r7 M$ t( W: E5 a! M4 u5 B. r
tbox[c] = no;
- ~1 _! s1 s9 N  i8 Y1 a+ u. g   }
8 {2 U: |9 f: W1 `1 e}
% {" a9 }7 `0 o3 T3 w$ A* J</script>
! }" A8 j$ b' O6 e7 @</body>" p5 n0 U% D" `4 l; {

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