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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"9 f$ ~; T- K$ n0 E) r- K2 H: P3 R, R
         c pageencoding="gb2312") j) V8 Y+ y% f
%>
- q) ~! u$ x! i" \* ~: B<style>' D6 K3 W, ]6 c8 r7 B9 S5 K
.f9{ font-size:9pt; }
3 D0 N, ^4 t: O! D3 |.bgc{ background-color:#aecaf9; color: #0033ff }
# V2 Q1 O) R/ v% o' T. D9 v.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
; q8 V4 |  O9 |6 W& ]& d  border-bottom: solid 1px #4e7dc1;. ?$ K: r( b: b% }
  border-left: solid 1px #aecaf9;
2 ^5 ^; ?7 }! f, P  border-right: solid 1px #5679bd;5 M5 S3 x( {) J0 d7 E
  padding:1px;
' Y+ U# z) q7 `) R  margin:0px;}
& O1 c5 ~5 l  O  k</style>
8 Y4 ?. p7 \% z<script language="javascript">
- e8 ]8 A  }/ x% B<!--3 a: D2 e  I1 j  w8 A
function rv()
- H8 H) h2 ?7 X( G{
' G( L" w2 q- O  var val="";
' q9 \1 v8 {2 G) y6 t  for(i=0;i<combo_box.list2.length;i++){- m: w$ e% f( o/ \
   val+=","+combo_box.list2.value;9 X/ v) E0 K' c( m
  }
& L, [6 F5 Q0 m1 j  if(val.charat(0)==","){
6 _8 ~7 W1 R0 [   val=val.substr(1,val.length);
6 B/ {' @, H2 l  h( y" t* C0 h; _( F  }
' j% a; b# ~% h  opener.form1.frecname.value=val;6 s3 i5 F1 J, U8 e
  self.close();1 ~& r& O" I1 t  W. h6 ]
}
* b0 P, m4 q4 O/ C, H//-->
  f5 {/ @" Z% i( `</script>
! s" H/ V$ B" |0 O% N<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
& T: ]$ n7 u6 D0 E6 S$ m<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />$ m$ z. V% Q% S* E* j: Z; C. D$ z
<%
0 `0 v& k/ G8 T* [3 s* J$ y2 Y0 c2 k  cdatasource ds=new cdatasource();  //数据联结bean实例
7 k6 C2 c$ Q. e  java.sql.connection conn=ds.getconnection();) a3 a5 p( s0 Z! X! b2 T/ Q
  java.sql.statement stmt=null;
' D2 U1 f* x( m2 B. x2 e% y  java.sql.resultset rs=null;( U$ v/ y$ H3 K8 T1 S& G/ t3 {
  cdatacheck dc=new cdatacheck();
2 [1 j/ ^3 M% G$ q9 \%>$ K+ ], L/ ~1 s& \9 z; v
<%# ]4 s5 h( K  |2 @( F3 p9 o$ Y
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";
; @' G9 \5 f/ w& b+ m1 S2 [% tstmt=conn.createstatement();) p  f* q: ?! `: D' c
rs=stmt.executequery(sqlu);9 a; T2 p1 v3 U6 E1 T
%>2 k1 s8 e7 i- W$ Y
<script language='javascript'>
9 b7 i- z* L8 u1 f: d! ~arr = new array();/ l3 O/ |3 R% L5 R' ?- v
<%  int temp=0;
& n6 I; V7 l! q% v7 R. H7 Wwhile(rs.next())6 d" R$ [; {+ Y! B4 a3 y7 y
{) h! j! @  Q; Y/ G+ G7 Q) J: |
%>$ C: f+ s" w. @0 w
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
" m1 z( Z# j" w4 k, R5 X! V: o<%/ g2 ~3 W$ A& L- P' s
temp = temp + 1;! c. h. v$ I/ ]/ W6 p# C
}( v( M9 I, Q8 K" A* X, X
%>
' ?2 s; K, f9 H2 e$ r  ztemp=<%=temp%>;5 {' b# f! ^: r" L+ @/ J
function changelocation(id){
3 g: w! g8 H# S* Z# f. m& o9 w: fdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 ( c  i( L2 [" u
var i = 0;
8 [' g& n, x2 `- m9 cdocument.combo_box.city.options[0]=new option('-------','');
: b/ i5 U# M9 Y) rfor(i=0;i<temp;i++){
1 \/ N. m* Z2 i0 `' n( l: uif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 5 Q, j4 H# ^; g; p
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
0 [& i! h1 Q- k/ ]9 M3 o# u' r} " {3 r( c+ H* D4 N: o
}
( M# V/ S$ b5 @} $ c- }  q( G* s0 i; H* U9 p' v
</script>
% h. n$ q. X) c0 |
9 e: H3 p: u: l2 K, F<form name="combo_box">: y1 |+ T# ]7 j' A7 u
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">: z/ s/ B) N: v
  <tr height="24">
+ Q2 V2 v/ S& ^3 b/ R    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
/ Q5 s9 K/ m' U    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
. b2 g+ i: {2 E. T    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
* {+ X7 B4 P  s' J1 _, S8 v) H' B/ X    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>/ u1 e0 g0 h5 @% n
  </tr>4 @' I. z& q8 A- n2 D3 A) b; t) X
  <tr> 7 ~( Z3 ]' v; g1 w
    <td>
) q- n8 F7 m8 B( }. f; s5 U+ @  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
  T! J5 _7 i5 J  <option value="0">请选择部门 ---></option>
& q8 L' a! O4 t2 C6 L" \5 D<%8 X8 U0 {6 X9 ~- g
    string sqld="select * from tdept";
" R# ]# `: C+ B" R( Tstmt=conn.createstatement();0 \2 N- |$ o- c2 v7 P3 \9 y  B, R0 k
rs=stmt.executequery(sqld);' V  m- F& \' p1 M' i& M  t
while(rs.next())
5 f* z( d- F+ @: ~- U{
% h$ d5 p4 A) y  U7 x" ?5 c- q%>
! H  Y+ q! L7 C6 @  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
$ ?% {+ d& t, o% a1 N8 K9 W<%8 i2 |3 e0 E: U' j: t
}
; P8 C" h% r; i7 t1 o%> 3 u3 C6 C3 h7 M& W, R$ B# z
  </select>
3 C% g+ o9 A2 p/ \</td>
$ i+ o1 M: `' n+ R5 J% q- `    <td>
& R. Q9 w9 I5 ]  H, ^- H" t, v0 g  <select multiple id=city style="width:150;height:200" class="bgc">
( p) K0 b2 _7 ?$ X) t8 C  </select>2 J$ X3 K/ a" _; S" U
</td>$ M+ G. k: T, E  p$ w5 P2 X& r
    <td nowrap align="center" class="bgc">4 _; X* Q4 w2 S5 H3 [, {% r, `
  <input type="button"  value="<<" class="buttons">, u: F, \" a% F# x) C- S
  <input type="button"  value=">>" class="buttons">
6 W, P6 a$ p% `+ b& R( I8 A</td>$ r5 I7 a. A/ V" T# s
    <td>
4 f" P( _/ W! E2 w, F  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">% f, A+ K. X% @  Q1 D
  </select>* [  N, [( ?! O4 f8 h
</td>+ d. p( w1 r. P* @8 X* Y
  </tr>* Y' P( i. y2 O& v: c7 S7 X+ x& a
    <tr class="bgc">
/ H8 K3 i& h3 g; |$ a! s    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>& B" B1 L: v* D
  </tr>' ]4 Z# S1 G) |8 u: s
</table>$ `( M3 f9 n. Y: K
</form>
! d% m9 L1 ^! W! H+ a4 I<script language="javascript">
* f- Q+ {. G* F2 ]9 n: }8 t//人名移动
( \! v: K5 T5 k2 u; Tfunction move(fbox, tbox) {. ^- m$ D* ?# r0 F2 n+ J
var arrfbox = new array();
7 N5 V# K: Q( a9 u+ O4 _var arrtbox = new array();( `3 n9 Y4 b* C
var arrlookup = new array();
6 h  p1 |3 T6 M# `8 p& {# [1 ~var i;
0 n5 `4 Z4 ~" B% }5 w1 J/ Tfor (i = 0; i < tbox.options.length; i++) {: X. j* z: [2 _1 k  s* g
arrlookup[tbox.options.text] = tbox.options.value;% d6 A6 M' U2 w
arrtbox = tbox.options.text;) k# F( ]% c  i; Q4 t  o
}
+ }: k. H- S: e- tvar flength = 0;; y5 S; ~7 U& w% F4 Q
var tlength = arrtbox.length;
  l: \1 p4 x  r) r7 Jfor(i = 0; i < fbox.options.length; i++) {
  S! Y# Q/ G6 u3 f) tarrlookup[fbox.options.text] = fbox.options.value;
8 Q$ L! @3 s1 gif (fbox.options.selected && fbox.options.value != "") {+ b; @& C  e( r+ D
arrtbox[tlength] = fbox.options.text;+ _! f2 A8 ]: A: l1 m9 N
tlength++;4 i% ~: |6 j. q# X# R) R
}' d" b/ m5 ^, S1 X: Q6 r' p9 p
else {
' ]! H( i) s" U3 r& p% Yarrfbox[flength] = fbox.options.text;
3 w6 E% @! U4 D+ e6 Iflength++;
% J3 E/ [0 y- w9 i: W0 C6 u   }  I6 A$ Z. q- o% o$ g
}
- x" w4 W9 T2 Larrfbox.sort();( V0 G2 k0 F( T
arrtbox.sort();
7 V6 @2 o- @/ T. W" Y4 F4 }1 J+ r8 j$ B, G
fbox.length = 0;
# |* H; B$ f* [/ y- T" Ftbox.length = 0;
5 T, Q  o1 A6 ~. |: lvar c;) w0 n: x8 W, W5 V# ]
for(c = 0; c < arrfbox.length; c++) {
1 M7 X3 E6 z" f; v- K# ^8 L+ Xvar no = new option();$ ]) Q9 Y" W7 }) h+ K% w) L# ?
no.value = arrlookup[arrfbox[c]];, @3 i0 s* Y) n, _, v5 r
no.text = arrfbox[c];
1 U' t0 W. r5 P1 `; Y# n3 \( l) Efbox[c] = no;$ p' ^8 I2 T/ r$ X8 ~, R. K
}
- V& R. D9 t$ U8 Vfor(c = 0; c < arrtbox.length; c++) {! I, H$ r5 t# n7 W2 C& [, x
var no = new option();
. m* O% r/ d$ f! |2 g$ p* jno.value = arrlookup[arrtbox[c]];' V3 V& Q' \8 j
no.text = arrtbox[c];8 {% k5 E0 H) Q" r* v" ]
tbox[c] = no;2 B5 h; k5 N4 O! H7 k
   }  i/ D# m9 {5 Z0 C" {; x- {1 p
}  B# e; G7 T1 D
</script>
, h/ C9 y& p. @+ f$ ~+ b</body>. F6 ?+ \* [8 s( p" c  [

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