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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
1 l2 p$ s2 }! w9 ^         c pageencoding="gb2312"8 D" X$ o# |% D" @. O+ p2 k. b
%>8 O3 c8 y7 i% n/ e* J% Q
<style>$ K: }6 Z  D# o" y4 g
.f9{ font-size:9pt; }
6 W$ }5 V. B% h# s+ T2 x( @0 \7 s.bgc{ background-color:#aecaf9; color: #0033ff }
( E5 E( e6 o9 T% }" M.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;! z4 x$ _# h) d9 y# J5 R5 Y& P
  border-bottom: solid 1px #4e7dc1;9 ^, ~- O- _2 t! f
  border-left: solid 1px #aecaf9;2 y4 @! j1 M* M" R/ a. n
  border-right: solid 1px #5679bd;
/ v6 f& ?" u+ y  padding:1px;
- e1 m9 U% z: b1 r  margin:0px;}+ b7 M+ n% a( w* C, N7 T, |5 `
</style>
' G# ]( w- k& c/ R  k# m. P<script language="javascript">- Y8 Y! a9 y8 g
<!--
: [7 f2 W  W+ T6 v& afunction rv()
; Z. q6 @- t0 q$ [{
4 s9 \5 l+ a  k8 }1 f5 l7 E  var val="";
+ m# w1 n& `3 b. c  for(i=0;i<combo_box.list2.length;i++){' k+ D/ t; Y- h: Z2 m  [
   val+=","+combo_box.list2.value;3 m  H1 \6 H3 g1 Y$ S% I+ G& U7 F
  }
% {0 l2 b( q, h. M* D0 H% c  if(val.charat(0)==","){
3 j$ E4 C1 U6 R8 ?   val=val.substr(1,val.length);! w" ~" z# E$ O$ r" j* x. A/ j" g
  }% [$ Q8 w" l" v& C4 J4 {! S$ d8 z
  opener.form1.frecname.value=val;
/ a1 p3 V' K& l  self.close();
1 L5 r( t, `7 @( u$ I  }! u}
8 a: F. S( _. Q9 ~% X) |7 u( M//-->! c: N3 n; F. `) x" p! t9 ?& J
</script>
3 e3 ]: n. y; k, v# w+ [  e0 N+ m, G<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">  V/ e! D& `6 T' B, ?1 ?3 `
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />% w" `2 \: q5 }, n" O5 F' w* Y; j
<%, n, U+ k* G7 V, ]6 B2 o
  cdatasource ds=new cdatasource();  //数据联结bean实例
3 R: U* m# M6 o1 _6 u" _; k  java.sql.connection conn=ds.getconnection();
8 {7 E# o7 K2 V, Q) j3 c! b  java.sql.statement stmt=null;/ z0 _, s5 W7 [7 w$ O# J" T
  java.sql.resultset rs=null;* B" a! M4 t; m) f& l
  cdatacheck dc=new cdatacheck();
$ z& F( G- m! L$ @  |3 U%>
2 \0 F5 m- p7 w. b<%& y& {, g* g: D9 [. v- [! E
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";. R; V0 _5 {+ t
stmt=conn.createstatement();
5 a* {& n% J$ [rs=stmt.executequery(sqlu);
; m9 i9 t+ x5 I: D; M%>" w9 W) c. Y: k2 S( r( {
<script language='javascript'>8 U0 q8 w( k- T. \# b
arr = new array();. E, {+ ~: U+ n* E; v& d8 h
<%  int temp=0;# u$ ~6 \. |/ L. R( b# s" m# K# a0 e
while(rs.next())
6 B# m7 ]. o# D5 k" f{
  L" B0 c, ?7 |%>
- a0 W0 U- u0 }arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");, d5 b9 V6 X9 S3 s% t% j
<%
+ i5 ~" r7 p" E  Z0 Dtemp = temp + 1;" ?# p' x2 c# ]/ R- U9 h
}" y* R( X: j- N! X/ v0 R4 I. R
%>
- D' l: ?1 m# ?3 B5 `& m6 htemp=<%=temp%>;
. |6 e; l: b+ L- Z! w5 `( dfunction changelocation(id){
5 }  f# \. A6 Q, sdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
* A7 @) ~, `; k# t. uvar i = 0; 2 {. _1 O6 f8 j0 C8 {3 W# p
document.combo_box.city.options[0]=new option('-------','');
/ g" `8 `4 k- i6 ^' ?$ Ifor(i=0;i<temp;i++){
, h: B$ K; K3 d9 l+ m# gif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 2 y3 a1 i8 I  |5 k" E% E: o, m
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
6 l; N( ^+ ]/ q/ O8 G) E- V}
7 c0 j+ A; i/ n8 K$ M4 e2 m}
0 L% W) p9 |" h5 H} * F) F9 {' @! E0 i* m1 f
</script>8 v: n9 E% i" m5 N  O: j

4 g) K/ {$ q4 r. Y<form name="combo_box">
% o0 `3 X6 a7 q6 ]9 [. v<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">0 j8 [8 c3 U( _7 y5 H
  <tr height="24">
; ~1 f' N) t' R6 t- C    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>. Y( \0 Z: c9 U) T5 c6 e
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>) Q: K2 q3 F' G2 t
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>8 ]  l+ U: |2 l& s- Y5 y
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
% O; K; w. R1 B4 C9 Z! j  </tr>: i+ K. J$ ?8 R! V/ A6 _
  <tr>
, }6 N9 V; L2 I4 W! S/ H* [- x    <td>) |% W4 v/ H: w! W4 I5 O
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc"># o' R7 a$ v+ |* O( t2 [, V
  <option value="0">请选择部门 ---></option>6 r- r: w2 B. U
<%3 F; Q! C) G) U: O9 M) @
    string sqld="select * from tdept";9 o- M2 T& b* T/ J, m
stmt=conn.createstatement();/ X5 U3 v3 f% t* N1 e6 e
rs=stmt.executequery(sqld);
; C/ W/ o9 @8 n" y8 bwhile(rs.next())8 ?5 Y7 C# n2 ^& u5 u+ x$ `
{3 N. i$ W/ b7 U0 |
%>
+ p7 R8 `6 @" V# r! |/ |* ~  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
' R0 m2 w$ x! R5 \<%
$ Z1 ^7 L6 i' }& v9 J2 v1 r* B}4 v1 N7 U0 `4 ^
%>
% t0 k2 s, b, B) ?! P$ `5 ?4 l  </select>
/ [" b8 P) A7 N7 J* {</td>, I4 l+ g/ {3 R* |' F' j
    <td>/ v/ n/ |0 s+ P. t. W* S) W! W
  <select multiple id=city style="width:150;height:200" class="bgc">% O, @& h, w) q7 W& s
  </select>, k9 |5 D, D1 S+ {) E
</td>
) C4 b, h) s+ S3 B! ?- H5 {/ T    <td nowrap align="center" class="bgc">8 [0 s; [- T( C. E$ |
  <input type="button"  value="<<" class="buttons">4 k& \% o* y  g: X
  <input type="button"  value=">>" class="buttons">& n* o7 P2 U5 i7 H
</td>
8 V) w+ D- B) A    <td>
4 A' s# {6 y+ W  Q  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">' A, c% f# n$ k6 p$ ^
  </select>- f+ c9 i; H( C. N6 ~
</td>
$ [$ m- D$ M& ~$ i; {% j  </tr>
$ P/ }8 j$ X2 y* n; S! F    <tr class="bgc"> 9 R# O2 }8 A0 Q' ?' n0 X
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>1 N6 l) X. ?9 U; L; V# ]& p
  </tr>; ^% Y0 i( w4 k$ t8 q& v2 [
</table>; G9 @. o8 M1 M7 I, o
</form>
3 c2 E: h6 r' l: i3 H$ g% c9 E<script language="javascript">
( x: d5 O/ ^! v1 ?//人名移动/ o2 ]- W6 s0 P* ?- u1 {
function move(fbox, tbox) {
' E" X( v6 V9 d0 Y) fvar arrfbox = new array();
, g& j# A; e& a1 T0 i) d' n4 Ivar arrtbox = new array();0 `( {; O6 e+ |/ H$ g: ]- D
var arrlookup = new array();) V# L# f2 f$ i
var i;) {4 X, O" O4 ^% i' G! h4 A
for (i = 0; i < tbox.options.length; i++) {
- o( S7 W$ N& k& m* ~arrlookup[tbox.options.text] = tbox.options.value;
/ T! |* ^3 z8 f- F" R9 Jarrtbox = tbox.options.text;
! H8 `2 ]# V8 I  g}( L2 Y9 R7 W$ \" n8 ?% L. [
var flength = 0;9 r. I! z* \; E
var tlength = arrtbox.length;4 k, X( s/ a% z+ L" U  v9 \
for(i = 0; i < fbox.options.length; i++) {
/ a8 N6 t+ y: N! Yarrlookup[fbox.options.text] = fbox.options.value;
2 B0 ~: n: f; Z9 u: Zif (fbox.options.selected && fbox.options.value != "") {
5 A( T# V8 i( M! u* \arrtbox[tlength] = fbox.options.text;
( Y" q) D/ J3 `8 u; ttlength++;
. E2 p1 O1 g/ w1 |1 ^) A1 A}) H7 K2 l! a1 ~; d
else {1 G; A8 x; R8 R1 H( O$ J9 e% H! T
arrfbox[flength] = fbox.options.text;& \9 s0 E. R( e0 l
flength++;! e: b) ]2 j9 A2 i2 x& e1 W
   }/ M* l! Z, {1 V; G& T; |
}
" a  W  R# a$ l# H$ m5 o$ Narrfbox.sort();: t' t8 r2 w, D6 b, M3 E) E- {3 g
arrtbox.sort();
$ F7 M  H$ f  ?8 o+ Q5 t8 y8 a; U% B# Z& i8 H
fbox.length = 0;- _8 j$ n+ ^: R% ]
tbox.length = 0;
1 U+ g! W; V. `7 F, n# d% m4 Hvar c;+ f; Z" t+ {) T- z
for(c = 0; c < arrfbox.length; c++) {
1 T1 ^. s7 I# d" U# d2 C/ h: \var no = new option();+ n% t2 y! ~" _$ F4 h" d
no.value = arrlookup[arrfbox[c]];
" F! ^! w- U0 H3 F, c/ D; bno.text = arrfbox[c];0 l, g1 j7 x6 q- f
fbox[c] = no;
  x" _/ M, @6 `( f}
. G  Z9 s$ v5 Gfor(c = 0; c < arrtbox.length; c++) {
3 C$ _. M& m& [" Q! B4 Svar no = new option();% F3 A2 s' N2 Z, g) U  C
no.value = arrlookup[arrtbox[c]];
" {% ^' Q1 M# K  tno.text = arrtbox[c];
6 N3 k. O" k- C( U4 w7 c: x$ D0 q! B& V( `tbox[c] = no;
% K3 N" s+ b/ s: Z4 G# f+ V3 _: r   }" ?: w! t$ i) U1 G
}
) Q; Q; U$ M9 }; V: _5 X; s</script>
; o6 X. ?- y# a; a. c+ N% A+ r</body>
- i4 e% Q1 m% ~4 s5 a! V

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