返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
6 d1 v1 L" I$ r* @( X, r         c pageencoding="gb2312"; s7 @$ u- Y* I8 V+ H
%>
+ n6 `' z3 ?) T" U# i' T3 s<style>
$ S7 M# G/ g+ V.f9{ font-size:9pt; }) N' i- S( r! a
.bgc{ background-color:#aecaf9; color: #0033ff }, y# v, \! A4 e! k  S
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
# c# \' Z; }6 v# |& H$ M1 M  O& x  border-bottom: solid 1px #4e7dc1;
: C# e7 A) r8 a1 O- r  border-left: solid 1px #aecaf9;
0 ]  o! l9 O# u7 b7 ~6 v  border-right: solid 1px #5679bd;
# o4 q! C4 G/ ]7 j  t$ w/ Y# J0 r; o  padding:1px;
% y. |# f8 v5 O" b3 h2 X2 v  margin:0px;}- M% y. n9 k) s& Q1 x
</style>
, u: u, D; E7 N0 V8 [<script language="javascript">
8 n! P, ]: ]' _# n) A0 u8 W, `<!--' U) d% f& `( I! W
function rv()# `5 {% _! N5 e& ?3 b' ?" N
{
8 x) C* z" R8 j  D& j  var val="";( K4 u- U( K- u$ W5 E
  for(i=0;i<combo_box.list2.length;i++){
/ H" U6 [$ Z% z* E0 b   val+=","+combo_box.list2.value;$ {2 _5 M. W# N6 d+ _/ T
  }
5 Q/ c/ F. Q% m, E3 x: U  if(val.charat(0)==","){! f6 k/ Z4 d6 b% }. h' k1 c
   val=val.substr(1,val.length);
( f* d2 m+ a3 y; o4 }4 _  }
- x3 G/ N1 W- T5 I  opener.form1.frecname.value=val;
* k' K5 N5 X% W; x  self.close();" E- {# g) v! Q% }# v7 V0 x. g
}7 ?2 d: f0 g9 G, u* F% ?/ o
//-->& h# \3 p; G* S: b2 |0 Z2 |
</script>
" Y& @( {* u5 O  T4 s# b( B: Y$ C<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
3 s8 p/ B4 c1 m<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
1 [+ Y& ^9 C, N; _* z' d4 g, I<%
! k9 X/ j$ c8 V; [5 c  cdatasource ds=new cdatasource();  //数据联结bean实例
* @9 n! X& b  a2 N! V9 g; c  java.sql.connection conn=ds.getconnection();
& H8 A6 }6 k7 i9 C  Z  java.sql.statement stmt=null;) M% W  w% R( t( V  \' T1 {1 |
  java.sql.resultset rs=null;
3 P; E+ B( V" W" \4 z2 A( {* G  cdatacheck dc=new cdatacheck();
  |% P  y/ y  u1 y7 r3 ^%>
; e! N( |$ Y5 q( ~6 r<%8 Y$ V& R) G0 u6 E, J3 [
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";
4 m: O3 S: f+ _+ Cstmt=conn.createstatement();
6 r; F; E  A+ Z( ?. N- rrs=stmt.executequery(sqlu);' \, M% \8 [9 {8 M
%>  \. ?% Z/ A0 o2 F# e; Z8 ]
<script language='javascript'>
* @, g; v$ h) u1 \6 marr = new array();8 ~2 K$ G" G7 T
<%  int temp=0;
" m5 J% b: ]3 jwhile(rs.next())
/ N" A( M8 s! T) V" F{. G2 ^9 Q. [0 i$ |
%>- \, t6 i+ J! {
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");4 u6 R% F( y  r7 A$ Y0 D% J9 J
<%$ P* h: n! v" W
temp = temp + 1;
6 b0 v% ?( g8 _/ {4 A! P& j  F8 b}  K4 _% e. ?+ b6 v
%>  a5 J# r9 c0 N) }" ^' K' o
temp=<%=temp%>;: y3 d3 `/ V: [5 g: h' k6 Q
function changelocation(id){
9 C3 i$ k5 b' ]. Z+ {5 Tdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
: R" o( K5 U; L/ j) ~( U" I+ vvar i = 0;
. S$ b: A1 j5 Q: k* u2 @8 I& V6 edocument.combo_box.city.options[0]=new option('-------','');
* q# p% _! h/ bfor(i=0;i<temp;i++){ . h) {9 I) _9 k& J- t0 Y( I
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
" O( o8 r( D* Jdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
' d1 a& B( @) z7 i: z' j; }2 q}
" |) M2 Z! _2 G( e6 T} # e* D+ I$ x! \8 R3 K* }
}
$ l# o# \4 C+ Z, P8 \# R- g</script>
8 f  J* D( G( k9 S3 a
% E4 D& ?5 i) V<form name="combo_box">! S' S2 s3 |) }3 s4 f
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
  p0 \  O2 w- \/ u  <tr height="24">
1 z% O5 L6 ]7 |% Z    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>( n5 G( P% |7 n% D# G* g
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>* \% ]5 N" q" A/ ^9 ~$ \
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
8 Z! Y2 r- X* }8 t: G; M2 Q; s7 C    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>* ?: J0 c4 ?9 v! q
  </tr>
2 x+ P9 z9 \1 v; C( _+ m  <tr>
$ J; k$ E, z" y& i3 B2 D( k2 W+ G    <td>
$ d2 `* f$ _& H+ c7 O! W9 C% _  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
9 H# [( _& f4 \; u% s  <option value="0">请选择部门 ---></option>+ v* t. O3 U" E! N) V1 @
<%
- o1 z0 j8 P9 [5 @    string sqld="select * from tdept";
4 E" v* R% q* W, z# F0 x7 ~stmt=conn.createstatement();1 |. ?& h$ Z! k2 K- Q
rs=stmt.executequery(sqld);
3 a2 i; [5 I+ G. Y+ swhile(rs.next())
( ?* L8 h: M. z1 X$ r{9 @2 T: u- G9 i3 P* |
%>
) H  c2 d" c0 F1 Q  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>2 e1 h7 u! A; r, h+ _5 M# Y. a
<%- b) l3 Y8 w) g$ `/ Z$ J2 ]" o
}
) v. G) w4 ^5 U+ Z8 N( {%> , x2 q9 _& d  X. d
  </select>( e% |* E  e( u$ B' ~
</td>0 d8 E& M5 t! e
    <td>5 B' c, N: j2 `7 P1 [
  <select multiple id=city style="width:150;height:200" class="bgc">3 K. V* n0 h' O* z/ J+ t1 k
  </select>8 x# \' J' i5 \( }3 {: f( H2 d
</td>
3 [/ X3 V) l3 E, q7 C    <td nowrap align="center" class="bgc">! {; E3 |& _& m# U0 ~& u2 v, |5 ^
  <input type="button"  value="<<" class="buttons">
7 {) W5 h: a7 o: J0 `7 L$ C5 v! l  <input type="button"  value=">>" class="buttons">
- X/ R/ S" I9 y2 ^& ^</td>
& e; _% T% c( _1 Q( R& q    <td>4 ]# Q- L2 v1 E" z& m) ~2 R
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">, l7 [! |& z' C2 B
  </select>+ [# V( j+ U  ]! V6 c+ B; h
</td>
- d0 U' S9 ^( |( v, E  D. g' _  </tr>9 O/ S; o# a- \3 [- o  S
    <tr class="bgc"> 1 Z: \" y* F  U& q, G( N  Y
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>* r' v( {9 V8 g% v4 V) G" j+ F
  </tr>: t3 }+ l3 V- O; G: P
</table>
1 O& v+ z! U$ w</form>/ p( k; n# e. e) q* L
<script language="javascript">
  \0 ?% ^9 g8 d, F; c5 x/ x//人名移动* C2 S, ^* [$ K! y
function move(fbox, tbox) {
5 L* j* v& t1 `8 kvar arrfbox = new array();( J5 W2 d5 I* X: L; n
var arrtbox = new array();
% l) T  G0 [5 Bvar arrlookup = new array();
! f2 \' B7 T& p/ Evar i;: O# I0 _) X) E% X. b9 y4 T8 u
for (i = 0; i < tbox.options.length; i++) {
1 g# b& t+ A! b7 L  Jarrlookup[tbox.options.text] = tbox.options.value;
+ o) j5 W. }3 Z' w2 J5 b6 carrtbox = tbox.options.text;1 r' V- |; Y' C. Y- ]% r- @
}, i4 D- y. Z+ O8 L* ^' f& z
var flength = 0;
( ^/ i" N% B  C, I/ Gvar tlength = arrtbox.length;- i  V, K9 J7 ]" C5 W$ E
for(i = 0; i < fbox.options.length; i++) {% y5 w6 `* V- E& g: l+ K0 g' R
arrlookup[fbox.options.text] = fbox.options.value;4 x, n6 R9 L! G+ \4 ^' V
if (fbox.options.selected && fbox.options.value != "") {
! a0 W* H( p9 W3 M: q% r( Xarrtbox[tlength] = fbox.options.text;
7 L. g& h& V# [3 htlength++;5 N; E# P' _2 ]  M( Y* [
}
% |1 b4 t2 V! m0 a4 E" Q, J* B! E; Relse {
, z0 \- N$ K# K5 |& [arrfbox[flength] = fbox.options.text;1 S" U$ H8 Y* b: I
flength++;3 ]# g6 g% i' ?2 T% F
   }
9 |: e! X7 F; F9 b0 r, y0 Z. W0 ^- Q}
9 H' b5 h  |9 Uarrfbox.sort();8 H7 m4 f/ k  I/ E6 ~0 u
arrtbox.sort();
  P2 I0 Q$ [$ q5 M. N: `/ Y
4 c$ Y3 d) _2 P/ n( Mfbox.length = 0;' ^& r. Y, A* ~7 T5 |/ W7 d
tbox.length = 0;2 u# x' ^# b4 r( }3 O% s, F6 I! I
var c;9 N1 A2 |) S0 g8 h# ~
for(c = 0; c < arrfbox.length; c++) {
" N( h" `4 g  d% a/ H2 qvar no = new option();8 K) a0 m" a7 a( [2 b4 ?
no.value = arrlookup[arrfbox[c]];# w7 y: X+ C% k7 ~. Y6 L
no.text = arrfbox[c];4 z* E5 K# i9 s" [  b
fbox[c] = no;
3 J& t" a9 e1 p# j- U+ m}
8 g& |! i* X9 j2 p- g: u9 xfor(c = 0; c < arrtbox.length; c++) {
- B. F, F/ Q, ^3 nvar no = new option();" @9 O( @2 i; }: f, B
no.value = arrlookup[arrtbox[c]];7 r3 X" o% q9 k4 O$ D% D3 B
no.text = arrtbox[c];
! r3 K4 h1 F) ]9 a# Etbox[c] = no;+ k2 i: S0 ]6 V% x# P
   }
1 Y; u5 R" d8 V/ f8 e! {6 r}
) [$ q4 I- f7 B, k</script>
( A" ]4 A; l* b) ^' P</body>
; B& Q9 j: U/ q

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