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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
- ^4 C' h6 g/ O. u* ]+ a4 |         c pageencoding="gb2312"! v; `0 D$ D7 K
%>3 N1 a- Z" h/ @4 i
<style>
* X1 P( v2 E9 G" n0 Z.f9{ font-size:9pt; }( X% ~: H/ E- |- P
.bgc{ background-color:#aecaf9; color: #0033ff }8 B2 [* m0 P( N: u
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;+ L4 C9 e0 e/ Q1 @) X
  border-bottom: solid 1px #4e7dc1;! D2 @8 D& m% |- f) u0 O/ U
  border-left: solid 1px #aecaf9;8 x7 ?0 A) i$ t5 n5 S! a
  border-right: solid 1px #5679bd;+ {' ~$ Z* }" I* G
  padding:1px;
4 y- R, K/ K& s% B( c7 k  margin:0px;}4 a; V! f! v" M8 Q, H
</style>
2 ~; T) o, u! t2 ~3 {+ i7 V) w<script language="javascript">
( \3 G. k" D9 e<!--, k6 y9 a: I1 f0 n1 l% A2 u
function rv()0 W8 R$ _/ T. @  T
{
) L9 |9 F3 h2 e$ \+ J  var val="";
$ h; @2 u& h1 J  Q/ B) Z# k  for(i=0;i<combo_box.list2.length;i++){
8 |  [: O4 N/ l$ {   val+=","+combo_box.list2.value;/ N6 @: `% ]2 m: K  y
  }
- \+ R+ b: q% h- q$ a  if(val.charat(0)==","){
0 h5 N: _- ^! H   val=val.substr(1,val.length);3 e) R( J0 q# c& h, D" p
  }
; x# y1 v# t1 f9 P9 b. w% K& M  opener.form1.frecname.value=val;
5 s0 w% E' u! p# k* C  self.close();
9 T5 k, ~6 \: z" N}
; D3 ?: C; U; P//-->
& ^! {- [2 ~. u. i: Q</script>
# r) T1 ^1 |( g9 S5 I& n<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
/ |" K( b9 w" n<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />: Q0 Z, n. y9 V
<%
# `* q5 n" S+ A9 J  cdatasource ds=new cdatasource();  //数据联结bean实例
5 w7 `% [1 O' \- E. m) Q" p) m0 z  java.sql.connection conn=ds.getconnection();0 w9 b7 B3 A; ]5 Y1 h
  java.sql.statement stmt=null;
2 |' j' A/ v0 Q7 p0 g) i  java.sql.resultset rs=null;
- s: a3 j' n" o  V- S  cdatacheck dc=new cdatacheck();; e8 f- o/ B% l3 w1 ?
%>
( B! n9 U2 ^0 y( n1 O# j9 S<%: d2 n7 Y! O7 x: F9 m8 g1 ^
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";
. f8 X* H0 A; Fstmt=conn.createstatement();' L0 d8 @2 c7 [2 U- F# F. N
rs=stmt.executequery(sqlu);6 {; {* r- S) y1 U" L" m' |5 ]
%>/ c/ y( `8 x1 P: T0 F- m
<script language='javascript'>: b, P  W0 A% g# I
arr = new array();  b# R3 ^( e* b/ l& o
<%  int temp=0;9 M3 q& k+ T" g2 n
while(rs.next())
, n2 J* ~- A4 E9 z' l  T{
: Y" N0 h( ^7 S( z%>
8 W0 T: Y! ^5 aarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");+ e" @" j# H# U5 i
<%
, i! t( t8 i$ R" Q0 [$ Wtemp = temp + 1;& D) k3 p, @& T
}8 S/ z1 Z3 v; t7 I6 M
%>
( Z; o! S' N- {2 H: U8 ^  htemp=<%=temp%>;
1 Z3 G0 o5 v5 wfunction changelocation(id){ 9 \* ?% }7 H& w( h/ |- \
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
. u9 ^* ]3 A( Uvar i = 0; 3 `, `! ?: z) K+ o4 y$ e
document.combo_box.city.options[0]=new option('-------','');
: t4 Z8 a) \- L, dfor(i=0;i<temp;i++){ & f* j- W7 j; K9 M! a7 w
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
$ g" [7 c# {1 Z' R6 l8 j2 C; [document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); $ n. E6 ?) S5 d+ J; z  m9 D7 u. f+ O
}
* F; i$ |8 L4 H4 B# j} , |+ @; X+ W1 w* {; G6 Y, c/ d' a
} 0 F8 |3 Z$ _. W. `" I; _6 K3 a; s  s
</script>; k  g7 p/ E% C2 V. N7 O6 j% I

% w2 E* |7 y3 k! d$ H* n6 U. |<form name="combo_box">  x; A* C! V: ]* V8 e8 J
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">  h3 p- r" S+ \5 E
  <tr height="24">
& E7 @5 Y+ Z* K. P! n& p+ T7 N# C    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
9 ]% [5 Y) U9 c! K7 I    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>" n1 d0 ?9 r( M. _+ t' O
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
% P: f5 y' p, [    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
0 h6 l+ x3 b0 T, u2 ?% H  </tr>% U/ B0 B9 n+ j" d# t- B
  <tr>
2 n7 l: |3 q/ P5 x/ @5 I+ w    <td>
% S8 d" z0 {" W  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
( ]  W3 O2 d  F( R. J5 t  <option value="0">请选择部门 ---></option>
6 C0 M7 M2 K8 S7 w<%
# [& I3 U8 C% h9 E: G) `7 T    string sqld="select * from tdept";) Z; ~7 q3 `$ }- A; U
stmt=conn.createstatement();
# H  f+ H4 v7 x/ o3 vrs=stmt.executequery(sqld);# z* [- B0 y% ?9 C
while(rs.next())! C& b5 F  J1 D1 q- i% ?! |8 c
{7 g: [1 g$ ]" y; B# N
%>( T, K& D- }6 A
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
! J  ?" g1 N3 N* N<%
9 Y7 F. \7 M5 o6 U" B& |}
+ o& C8 b/ L% ?5 p$ ~4 i%> / ?- m9 ~* B; l
  </select>
) |( f6 q) W8 T3 R! y/ L4 K5 J</td>
% K! Q1 Z/ O, B; I- u# x+ S0 m    <td>
8 F2 `  @2 L3 \2 V  <select multiple id=city style="width:150;height:200" class="bgc">2 u/ Q/ t" M: R* ~
  </select>) t& {/ q- Q1 R6 S4 n1 e
</td>( ~& K9 p4 Y$ K" V6 ^  `
    <td nowrap align="center" class="bgc"># y' L+ k( \0 X8 @1 w4 Q( G4 b& _; k0 D9 {
  <input type="button"  value="<<" class="buttons">
# y) Y/ z9 j  u0 m  <input type="button"  value=">>" class="buttons">
  H6 ]& W& Z& Y# e; \; O</td>
; {3 e! C2 O" x+ [. T    <td>! ^1 N3 P1 B, U" U  {
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
9 B! y) N- U- J6 o  </select>5 {! @  T3 T  X
</td>  }# g' g" ~+ K1 \. P* o; E( A4 G1 J( v
  </tr>! c& U, w2 G# m2 l# L
    <tr class="bgc">
0 ?  p- U- N7 S( {    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
5 s9 N3 \0 G7 G: K$ W" a8 I" ?  </tr>. F. F! H5 ~8 a$ C' t# J
</table>( h7 m2 a* ~0 A* L
</form>
: R' N: z9 S8 e- J) o<script language="javascript">1 C/ j3 j& M* \6 b1 [8 m( T2 J. R! J
//人名移动5 R# |4 Q7 }( E' G* I% T0 C+ I
function move(fbox, tbox) {
. o; w2 j& ?# b2 M, O; |7 nvar arrfbox = new array();4 B. q' D$ D' o
var arrtbox = new array();
: c; ?! x( q" g0 U* R% ]var arrlookup = new array();9 U" S+ c. k  Q' G
var i;& A! i& z5 Q6 c7 ?# Q
for (i = 0; i < tbox.options.length; i++) {$ ?* S3 `; J  [; b/ o
arrlookup[tbox.options.text] = tbox.options.value;- K8 i- u- H! [6 Q/ S; s
arrtbox = tbox.options.text;
/ m5 T% e2 C+ w}, d9 t8 g( f$ N: s: \
var flength = 0;; z4 D& B+ l5 ?/ w+ L6 s# D9 X
var tlength = arrtbox.length;" S" Y8 l* ?4 F' \, L
for(i = 0; i < fbox.options.length; i++) {
# b  s( ?6 n2 a3 l& W3 P4 Garrlookup[fbox.options.text] = fbox.options.value;
$ W2 K! C8 d7 f& h9 w  x5 hif (fbox.options.selected && fbox.options.value != "") {" l& y% _% D! w; N  h/ o  F
arrtbox[tlength] = fbox.options.text;) t  v' f+ L! M
tlength++;
1 X/ `9 Y6 |: o+ E5 l}
- S* A/ n8 S8 ?; y' P: s8 F2 xelse {4 a' Q: Y0 L; V& a# T/ K' a" P4 v
arrfbox[flength] = fbox.options.text;
% W. e' Z: J5 ~flength++;# q2 ?- g  Y, s1 a% n
   }# v+ E2 \+ m+ ^2 o! N9 x" @
}
4 D" E' S  g5 V3 M- q& parrfbox.sort();- G3 k. o$ Y1 j9 {. X
arrtbox.sort();
+ [, T6 |! i0 f  a, J. N
' _# A, e* k  u4 U" ]fbox.length = 0;! L5 O: v- [: V
tbox.length = 0;
' P  ^+ N; y/ P! x% z& [var c;% F% q2 I; d$ v3 d8 l2 a
for(c = 0; c < arrfbox.length; c++) {
7 {3 B; s/ V1 l( D4 pvar no = new option();$ }3 l1 a7 x( y9 T' x
no.value = arrlookup[arrfbox[c]];
+ ?: K3 f; e+ Q! mno.text = arrfbox[c];9 M1 D$ m% O7 P  Y: E1 F6 C3 c
fbox[c] = no;
1 Q- K) X& Z& V  h. n+ W1 Q2 k}5 N1 J) Z6 d0 X# Z: ~2 ]& G
for(c = 0; c < arrtbox.length; c++) {
. c- s4 d/ |( E* X( g+ I2 W7 Avar no = new option();
  t( T5 K& ^8 O6 v8 G1 b+ zno.value = arrlookup[arrtbox[c]];- n) G0 c1 X  X; e! y$ f8 d
no.text = arrtbox[c];) U6 B- l6 ?2 M6 ?5 G" ^
tbox[c] = no;2 S! @% W' a/ z5 ?
   }
. X, z% |/ u+ g( F4 L$ x}
. E2 A  |0 c4 g9 p% J# Q</script>
2 a( y, ~  i5 ^2 t; O</body>
" V1 a9 W3 @7 z, b0 t

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