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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"8 l/ k' C: ^. H8 b5 |. \
         c pageencoding="gb2312"
! @& p% s: `0 M* ]$ h" v%>  U5 N8 M* @0 g( K! }3 C
<style>
+ v6 k5 [8 T1 w.f9{ font-size:9pt; }
8 E" ]  L% J0 a$ B- x* |.bgc{ background-color:#aecaf9; color: #0033ff }
1 \$ e5 A" L* n0 P. N5 J.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
: R; i- T4 q6 {8 o! H; g  border-bottom: solid 1px #4e7dc1;
& L" ?0 U( O2 o5 `  border-left: solid 1px #aecaf9;
7 V% G9 [# f$ K' _! Q( o+ X  border-right: solid 1px #5679bd;: i% [- S2 q8 ^+ V
  padding:1px;
$ C1 h$ a2 T& x  margin:0px;}( f$ l9 |# U$ T
</style>
) {( G  q+ g4 A- P: X7 I* X<script language="javascript">, |7 Q7 G( M% c/ ^1 r
<!--
7 U* H- }2 w1 u8 I; Rfunction rv(); }3 \- B% l5 [% f" N1 K% k; H
{/ y+ S9 z- \* Z6 q+ o% s0 y
  var val="";
1 ^( A$ ~. I4 q' U- I6 v: |  for(i=0;i<combo_box.list2.length;i++){% j! l' ]! o/ H  J5 p  n
   val+=","+combo_box.list2.value;
' }1 T6 ~- ?+ Z  }
- X9 s7 N8 b+ \. N$ e9 V' F1 a, |4 d  if(val.charat(0)==","){
: s/ w  ?. R. u' Q4 I/ r/ M/ O   val=val.substr(1,val.length);9 v, M( a4 b( f: y
  }; H9 R; p5 x4 R; Y' B+ x# s
  opener.form1.frecname.value=val;, ~! T: r" Y8 c& ^# P8 v
  self.close();- M$ n9 _$ F/ ?
}9 S2 b' c. _7 U' g
//-->
2 p9 e4 S) r6 I9 e0 v/ A7 N. k! h</script>  I0 N8 z/ l+ X" q3 [
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">8 l, Q1 ?" \4 s. [. w
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />% V! K. E2 n5 D0 h9 J
<%
+ u4 d. A, S* K+ j6 e" ?6 r  cdatasource ds=new cdatasource();  //数据联结bean实例
6 t; S  ~7 n3 ]# |' f  c  java.sql.connection conn=ds.getconnection();" R( ]0 W+ X; N6 r  S
  java.sql.statement stmt=null;; r$ a, o0 h% y7 G# {' @
  java.sql.resultset rs=null;, w: r- {/ {7 _* ^: ?5 K
  cdatacheck dc=new cdatacheck();
8 N4 G) L% G1 Z4 u& F0 m%>
: v: F0 `- b* R<%9 x2 O- T, }0 {
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";) Z9 \/ B; \2 ]  s
stmt=conn.createstatement();
, z0 p2 _8 N! X& lrs=stmt.executequery(sqlu);
1 W2 a5 Z$ F. B- z! O1 X4 T) C%>2 y* B9 Q  H2 ~# f2 R7 y# E3 M
<script language='javascript'>
3 u1 H+ l3 {  |! Y5 @arr = new array();* g& u& X$ b- u3 L/ V
<%  int temp=0;) y7 W* k" c, g! s. o  I
while(rs.next())
4 Z  l" ]# Y: p" s  q5 l) W{* x+ M5 z" p5 o! C2 V9 T; x4 c
%>
. q& ^. F7 F3 o" S, Darr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");, D% d" q0 y8 U3 b9 [8 @+ I
<%
( e" S1 M7 y) Wtemp = temp + 1;
# M  _( A4 w9 _1 R% q5 `}
4 _7 G# t4 G7 m+ y+ j%>
9 e% D" \3 Z- m3 l$ s- Q0 wtemp=<%=temp%>;7 M/ P" o4 _' t+ O; i- C
function changelocation(id){ : t3 z( d; _% a- t9 l: R9 y8 m
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 * k+ v! L6 F5 e0 _- D% v
var i = 0; 1 \9 w& _6 E( V
document.combo_box.city.options[0]=new option('-------',''); ( _2 o+ Y; Q% i: ^+ o; K
for(i=0;i<temp;i++){
: _+ _6 {$ r$ w: J  d0 L9 q* }if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] ( r1 a1 I+ a6 V& r0 L7 k, q
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 6 [7 v: `  v$ g9 K" w
} , w1 }$ ~/ R0 i1 y9 p6 z* J( _
}
' |3 k3 n; s+ X1 q} * N* t+ ?8 r* K# c  W* I: J
</script>
; P( B7 o0 a$ x
0 w' v  s1 u$ N( l" x, ~+ {<form name="combo_box">$ ~5 Y5 m8 C  j2 W
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
8 f+ h& i6 X! N/ W% }$ @& i4 p  <tr height="24">' k+ u! r" x3 F  k4 p! W" a1 }
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
! y* d& V2 d" J    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
7 P6 V; \- R7 B* A7 T( C7 i# ]3 D. u    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
" _9 j5 A! w' R) L' |- }6 ^5 {    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
" k% v( e' O) @" ~; L2 z4 v  </tr>
$ x* C; u$ D2 }$ H3 F- x. G: g  <tr> 5 U, ]- m; ?5 n$ Q: ]  Z
    <td>" B4 u! R7 b+ e' w! g4 \! `4 m- A
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">0 @# L$ \7 k  d7 u
  <option value="0">请选择部门 ---></option>
* m) r( S1 p, o/ U1 L<%3 v' ~2 U/ E, Y$ b. t; [/ G+ N
    string sqld="select * from tdept";
) X. y/ t! P' I* {6 ?stmt=conn.createstatement();' e" T% \% e/ O# t2 Y
rs=stmt.executequery(sqld);$ w8 w  k& l* _+ w4 \& h5 `
while(rs.next())
5 J- H& Y! v: [3 H. r/ Q{" R. Q8 u1 [, I3 n  X0 B
%>! Q0 n$ z) a$ t+ Z" C0 L; @- |
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
# P  r7 ]0 _, t, M; F<%
4 o# _/ J- E% M/ \8 A}" O/ f: U9 c0 L7 ~
%>
6 {; X! m/ z/ I, L+ a6 B1 f1 h  </select>9 i/ x  V1 Y$ O: ^: y
</td>
- Z! J! v3 [( ]    <td>* c2 d/ x+ F9 a
  <select multiple id=city style="width:150;height:200" class="bgc">2 a1 X" G; r& ~9 p
  </select>+ c/ d$ p$ N  R, @; t; W
</td>+ x7 M0 u. U# m, l. K
    <td nowrap align="center" class="bgc">
- b  o: n! ?9 P& m$ v) E  <input type="button"  value="<<" class="buttons">
9 r. S1 T) _) H' N% t3 l  <input type="button"  value=">>" class="buttons">% M) _0 @/ f: \' [- T7 H
</td>
) H' G4 n8 C$ y; Y* G- j1 V7 }) s( K    <td>. ^  L* ^* r. K
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc"># X& a' `. w9 W% c" ]9 I9 o
  </select>: s) u: Z2 c+ O+ }0 Z$ b* F; J2 l" [
</td>
- R- _3 s0 y1 F! f( _; s1 H  </tr>7 W; w" v- ]4 R, e! M: p
    <tr class="bgc">
; E$ E" W% C( w# I  m' P    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>/ a% Q) l% ]! u( p/ X; w7 ~
  </tr>, j3 I1 y& R1 v# l( D1 \; b
</table>9 {7 }; }2 ]" l$ S7 |  L8 T5 r
</form>% P" n# C/ m- ?: s) W7 I2 X
<script language="javascript">
  Z" F  \- w  S8 ?) f  U/ j//人名移动
. A# ^; d" C, i* M7 q. c- ~function move(fbox, tbox) {" t, U8 f5 b/ D5 f, S1 F
var arrfbox = new array();
$ i% ^* N1 T, g1 rvar arrtbox = new array();
. ^% m9 G# |* C' a$ z( pvar arrlookup = new array();) I2 b4 B$ f- a0 S+ C
var i;/ ^- c$ S$ z7 [+ B1 V7 @0 Y6 y' p
for (i = 0; i < tbox.options.length; i++) {
! R  o) O3 u+ i/ r! l5 ]3 Warrlookup[tbox.options.text] = tbox.options.value;  @' ^* u$ y2 w4 Q
arrtbox = tbox.options.text;
+ r6 k7 p& A5 \0 }/ b& f" A2 E}8 M6 w7 Y) T% }" J0 o
var flength = 0;- n5 C+ L: z2 W. l- m" c; z' m7 P
var tlength = arrtbox.length;
0 y+ t3 w9 T. }4 Z2 c+ u, Gfor(i = 0; i < fbox.options.length; i++) {" m2 U: K, F' R5 X# t
arrlookup[fbox.options.text] = fbox.options.value;" ^* C; t0 f1 K# b" p
if (fbox.options.selected && fbox.options.value != "") {
1 p; t; V3 [2 m. `4 V4 Xarrtbox[tlength] = fbox.options.text;
9 j. Y  X( x+ P4 Ftlength++;9 @; r% Q2 d4 j$ P1 y
}
2 ]: l) z! `; i' Uelse {& H$ t/ n+ C+ O9 s  W
arrfbox[flength] = fbox.options.text;$ g( T) C- I# ~+ L
flength++;
/ S* \. Y6 ~7 ]7 O$ H3 ~   }
) c1 k, X1 }% `0 E# w& w$ _* b}! j( r- W: H0 A& Y
arrfbox.sort();
7 I6 s; r# H8 a$ z4 v: r8 E- }+ aarrtbox.sort();5 Q* q2 k" u' l4 L7 y  Q0 C) S

' K5 {% ?5 ^: `+ ?% jfbox.length = 0;
& g# p/ F8 V1 R! Xtbox.length = 0;! y+ X9 o. k! w2 i, y; l( Z0 ]
var c;, h* Z1 t7 m9 z% e8 {' w
for(c = 0; c < arrfbox.length; c++) {8 J. c- R2 W8 y* A9 U& X
var no = new option();
; k- f4 ]5 x, X$ Fno.value = arrlookup[arrfbox[c]];  O$ N5 H4 Y  ]' s8 {, {
no.text = arrfbox[c];
  Z5 u1 |6 s+ e) H' l( Z8 ifbox[c] = no;
0 I9 ]2 {, S5 h5 N  S7 T/ K}
8 L. ^2 d: |2 A+ U) b# i; Wfor(c = 0; c < arrtbox.length; c++) {: r& }4 z* y; J' S
var no = new option();, H0 s& [$ B- ~& k
no.value = arrlookup[arrtbox[c]];/ t) k5 j. f6 ]
no.text = arrtbox[c];1 F% }  H) A; `+ M
tbox[c] = no;# m8 G; _9 I) r3 d  V8 v
   }
, f& L' S( W% H; V}
: |7 x% S/ K( g! `</script>. X8 U0 n- I4 L' [  E6 D
</body>" d' t0 O( m1 B8 p

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