获得本站免费赞助空间请点这里
返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"2 |, v, E" t4 c, n
         c pageencoding="gb2312"
3 o! O' W. z9 H%>
2 Y; m3 c$ u8 w7 b<style>
, q6 X" i5 ?' {, L+ ^.f9{ font-size:9pt; }
$ u/ f; S8 Z* c4 Y+ N5 M& [8 a+ [6 ].bgc{ background-color:#aecaf9; color: #0033ff }
, [6 d0 P1 g+ Z& X; j: Z.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;- u% Z( f( j) H+ Q9 ?  t5 d+ H
  border-bottom: solid 1px #4e7dc1;
/ O1 N$ ?: H" U+ {4 ]( m, U  border-left: solid 1px #aecaf9;
+ L6 O, V; k$ N6 X2 s1 u1 b6 t  border-right: solid 1px #5679bd;
1 v0 X( o! ]* N3 e" }; \  padding:1px;
& V* D9 {& Z1 i! ~8 h. I  margin:0px;}  O4 m6 O4 C4 K8 F3 I/ O" Y/ R# _
</style># k! ~  S, ]! S! Z) I9 y1 U  o8 R
<script language="javascript">
% [- ]0 A- ]" B3 I* |: E<!--, N5 S/ v% Z3 F  U+ `$ z& U
function rv()
; I7 |3 s! K3 B. B- w$ D{
; t. q& c" r( S7 C  g! G  var val="";
9 M) D; F% O+ Z- X3 l, Z7 K  for(i=0;i<combo_box.list2.length;i++){
! F/ C6 G4 _5 \+ U- j   val+=","+combo_box.list2.value;  X8 c3 a3 w, c( X0 |$ r
  }  f# t$ u+ J- I: h: J9 L$ a
  if(val.charat(0)==","){5 j6 ?! w$ q7 I7 c4 N7 {
   val=val.substr(1,val.length);
7 f3 q$ N# P( o9 V: o3 f# @" z" F  }
4 ^  u, H! f8 m" N+ [  opener.form1.frecname.value=val;5 u5 t2 \- h" M8 ^
  self.close();
% O7 m; j7 V  A" u}
' X( A1 V" p5 U" X1 I& {$ @' \//-->  T/ E- `# m# p7 ~9 G7 L+ W" R( J
</script>
: o( X1 {8 s0 f8 ]% f<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">: ~; j- r$ g7 p+ Q
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
0 d+ G5 s! r8 ^6 `7 I<%
$ b1 [% j& Q: a7 I  cdatasource ds=new cdatasource();  //数据联结bean实例
( w3 I% u# F% R9 `4 w  java.sql.connection conn=ds.getconnection();
! r; Y/ s& H& F" }+ t/ f, y9 e& V! V% l  java.sql.statement stmt=null;7 I5 s! `% I/ {4 a6 K# E- d
  java.sql.resultset rs=null;
# u% S9 a' {6 H; t7 Q  cdatacheck dc=new cdatacheck();
* C' o" [3 p! H/ ^5 g%>9 g: m. y' P3 U7 n4 j
<%9 s+ g0 I* l$ e+ a
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";
# B1 m; V1 N8 h5 E3 Q& ?& Istmt=conn.createstatement();+ G3 V  l. x$ B: y! `) }
rs=stmt.executequery(sqlu);
( Z! Y: H" M" S2 M%># V9 Q. u" y" @# s6 N
<script language='javascript'>9 m( j+ q% P5 H, b% @( h
arr = new array();, k! C- {7 x: k4 p* \) o
<%  int temp=0;
# O; J1 L5 z0 o  E$ hwhile(rs.next())- I* B' c9 o+ a2 {! ?% m
{! g( c) C9 J7 {, y/ M* \' G$ p% o
%>. o8 x9 C- ?& |2 {9 W* }
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
, d' @4 ~$ f  b& l3 r( r# K<%( I1 Y8 T7 z7 `$ h) b4 U# Y
temp = temp + 1;
+ s" a, q; p0 u" T}
2 A8 [7 L' w$ F7 l" i& J%>
) n6 Y+ E, z! w  {, ttemp=<%=temp%>;
! w/ J# [; {# l' Gfunction changelocation(id){ 6 Z& A1 S% \5 @4 T+ {: P/ c
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
% X8 z$ |5 A& j- Rvar i = 0;
$ i$ G. ^3 D4 Gdocument.combo_box.city.options[0]=new option('-------',''); 6 W1 }) }6 @* q7 q9 Y
for(i=0;i<temp;i++){ 4 l- B! l) M+ u7 Z" {4 y
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
  q1 `! D' p! e3 R! Zdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 7 I! G4 ?  M  Y/ z7 u' i, }
} - d3 l8 }; r9 g/ u( Z& [7 l
} , Y& y7 {+ }0 y
}
( V7 a( e+ t# m; A  Z# o$ ^</script>% K* `( j1 M7 g' x

% g: _0 M- u+ B& p7 g<form name="combo_box">
# R" H4 m, Z% j1 f<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
: _( S$ `* G9 O) a. ]  <tr height="24">+ f8 D" o0 ~1 x1 X9 M
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>, d( n) Y9 r; V# H# a: l
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>; o' u+ l2 t7 ]7 P2 I
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>$ v6 V# X" {  E
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>7 B# r$ w* j# ^3 C% Y
  </tr>2 \! H( D$ G6 r9 ~- V3 G$ s
  <tr>
4 e' `+ S- }" }# `2 D    <td>2 J* b  o& u' D# z6 ]  d
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
( b7 Y: L) t8 [* C9 Y- e8 g4 _  <option value="0">请选择部门 ---></option>% q4 T3 L  @2 N5 J
<%
3 v3 O7 i+ X( x* R4 ]    string sqld="select * from tdept";4 _0 B5 g6 j0 l; g
stmt=conn.createstatement();0 P' {  o- F$ |' o6 P
rs=stmt.executequery(sqld);+ o! C$ @: k% V% R: U: A
while(rs.next())
+ |' `3 P8 n) k6 G6 L! P{
7 a' P& r( b# M  S* C$ q. j$ O%>
2 p. X( @) b3 Q  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
+ R4 x0 Y0 m1 Z& ^/ l% Z% I<%% P# b$ [6 g9 o* ]# v* h2 A
}& C# e+ P5 Q) g6 E8 J- K6 p. k
%> " {& e7 Q  D2 \. B$ H) B
  </select>
: P+ x8 L2 l; ]! M! ]8 t+ i+ ~</td>
4 }5 ?( Z" a. E( P$ H- I    <td>$ [+ g8 N/ c" z) ]' T7 F3 {
  <select multiple id=city style="width:150;height:200" class="bgc">! S4 r; Q/ e! J# Z5 L' _$ n
  </select>6 U) ^5 J, H: d4 r" ?* S
</td>  T: V3 F/ M# d' K3 Y
    <td nowrap align="center" class="bgc">
4 s4 J/ i9 y# a% e% L  <input type="button"  value="<<" class="buttons">. g. G5 k0 m& |& N
  <input type="button"  value=">>" class="buttons">8 |. p. H! B0 D" I8 f; w3 s2 T. g
</td>, P4 m+ @! D1 q$ `5 l
    <td>5 ?& W# S$ b: ^! k- y9 b; ~
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
. M* R* O% g. h. V3 q  </select>
: N0 W0 P% @( N</td>
6 T# w, t# |& k. m" W+ `8 [  </tr>% ]# Q6 w- R  \, s9 l/ G
    <tr class="bgc">
# c/ ^1 `4 O; u$ Q    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
, B$ u* X0 \2 ~3 b, P9 a  </tr>3 B# K1 t- a8 n7 I: ]; o/ N. t
</table>, ~. X$ d, A) V
</form>
( Z' ^$ s' B! a  \5 t! s( @<script language="javascript">; y  Y$ W9 b1 k' w/ e' a8 {8 `
//人名移动! `# l& I6 l7 R, R% a: f3 c! i/ I
function move(fbox, tbox) {7 q" N4 t: e" h) k8 l0 E% l! l5 w% H
var arrfbox = new array();
4 l, |$ N7 n6 G% lvar arrtbox = new array();
& a& k2 `0 }/ E+ B' I* H: \var arrlookup = new array();! o3 K+ j3 \+ G9 b& s, I3 N
var i;
7 O* w( A5 I5 k' ~) Bfor (i = 0; i < tbox.options.length; i++) {
5 x. `4 _( p2 varrlookup[tbox.options.text] = tbox.options.value;
( @1 I6 r; ?$ M" d( l! l' _arrtbox = tbox.options.text;
3 R- x7 x: e8 r- Y}. S% y# k4 x1 z& E5 b, L/ f
var flength = 0;' }' q* _  P9 |& |
var tlength = arrtbox.length;
, ^! Z( b$ ~4 efor(i = 0; i < fbox.options.length; i++) {
3 i/ C7 w+ d/ N. marrlookup[fbox.options.text] = fbox.options.value;
7 F8 o7 J, o9 j" rif (fbox.options.selected && fbox.options.value != "") {4 E# u, ]2 m. Y. L' X. m$ J7 _
arrtbox[tlength] = fbox.options.text;
4 Z; m# Y  b  g; R8 D: w1 j1 Dtlength++;/ X( h9 s0 i6 z& t
}
5 G1 v2 O0 b' Belse {
! A; ?6 o1 J, {, b5 Zarrfbox[flength] = fbox.options.text;
; \0 j# |0 s4 q9 M" p  Yflength++;
$ U: j' I- J7 G+ y8 _4 |4 u   }
  T- j0 r1 Y6 J0 `: k  ]% N4 j( o}
. Z- _3 }2 h( I) Q2 |9 Yarrfbox.sort();# k+ p" L+ @$ B. q5 ^
arrtbox.sort();
0 e; k$ i6 v! p7 Y; ^- U. W2 h$ |) Q/ b$ I& k5 M1 a4 i- _
fbox.length = 0;
% d; U0 z% m( O% m2 Xtbox.length = 0;
5 S% t6 m3 X, {0 l9 Y/ \& Pvar c;6 c+ I1 X; E% d& \
for(c = 0; c < arrfbox.length; c++) {! f& h9 d$ l9 {* v
var no = new option();) p" g, _( N1 ^8 U9 k3 F. A. G
no.value = arrlookup[arrfbox[c]];
: U$ e. Y& _+ m, xno.text = arrfbox[c];. o+ U- v4 \5 ^+ R
fbox[c] = no;* P' Y$ H5 Y* s9 k* V5 s( {
}; K0 B: ~/ f5 A4 U: |6 n$ j
for(c = 0; c < arrtbox.length; c++) {! {3 {/ ]" e) g) P1 S
var no = new option();, Z- X2 T0 `3 E$ v9 q' a8 Y5 y
no.value = arrlookup[arrtbox[c]];2 s5 F) w  ^; r  S
no.text = arrtbox[c];
/ Z3 y" I) P$ [/ @tbox[c] = no;
5 x6 {, N& r- B+ O/ J   }
- Z1 z+ F2 |, l9 C2 o% |}
% q$ r# q7 ~( c3 J</script>6 I. a4 I! A% \& C
</body>9 `5 z- d9 ?0 Y! q8 \  ]* \

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