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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"- Y$ R1 E0 n/ C! R& L0 ^, F
         c pageencoding="gb2312"
$ u5 }, @$ }& l# y. {%>
& B2 t( w% j$ g1 b+ C6 `<style>
9 \% b# g$ t( x0 l- H6 M! Y, A* v.f9{ font-size:9pt; }/ }( Q9 w4 t% c7 B
.bgc{ background-color:#aecaf9; color: #0033ff }  p$ k; A* J; H
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;  G! `; p7 w* q8 s$ a3 h  U: O
  border-bottom: solid 1px #4e7dc1;
( i/ f5 P" `# A2 z2 w  border-left: solid 1px #aecaf9;) {' x$ U- U* |" N, U  c, @4 `8 R
  border-right: solid 1px #5679bd;
! j& X0 K% z1 E) K4 d2 s  padding:1px;
* |1 ?+ r# g' t5 C2 _8 \. G  margin:0px;}
8 f- j+ f4 J, J7 P( U, A4 c</style>9 N6 [, ]: \6 o1 D/ O+ g
<script language="javascript">% S9 ^& h6 H+ c( k/ c4 P( n# H
<!--
( m) q+ G5 J$ t. @+ |function rv()
4 l  ^$ p: O# r& Q0 i8 u{
  Z7 R6 Z8 [' P  var val="";
4 U3 c, Y' I* b* F" p, ?; z  for(i=0;i<combo_box.list2.length;i++){: V+ p! D  r% ?
   val+=","+combo_box.list2.value;
+ {' V6 S: ]% v' Z9 g' c. @  }" k: E1 `0 I) q9 h3 `5 p
  if(val.charat(0)==","){+ v; {+ c1 [  W4 A6 r: X0 I: c3 d5 k
   val=val.substr(1,val.length);
+ o/ t+ G. G$ \8 |1 ?  }* F5 c  P' ~1 @0 J$ N8 q) \
  opener.form1.frecname.value=val;
* V& d: U2 ?0 V/ n: o  self.close();1 B8 C7 @. l8 r  ?1 a1 M$ `1 B
}
; h' `( o% A, p2 o//-->) r& C, T- y$ |9 D- u0 ~2 U
</script>
6 c4 g3 N: z( `- n0 X  g0 x<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">9 l' X) |4 D4 V3 Y
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
3 @* ?+ ?/ X0 e2 j/ j<%
, A2 b& y, o  m. @+ t; `  cdatasource ds=new cdatasource();  //数据联结bean实例
! [& i) k0 M5 T" o) g  java.sql.connection conn=ds.getconnection();+ }* m  O, D3 d' f
  java.sql.statement stmt=null;* r" O" e; v7 z0 h9 l, b" @, o
  java.sql.resultset rs=null;
4 d- R* Q  x" }( A8 c/ I' s* V  cdatacheck dc=new cdatacheck();$ W9 q. i' {+ Q3 e! k
%>
) t9 [) e; I+ L: Z2 H" `8 U1 _3 n<%; ]! N3 A# B0 r9 K' k
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";' }, c$ g1 O* ^, J# k
stmt=conn.createstatement();: S! |8 I* ]; N2 ~: ]# k8 a$ W
rs=stmt.executequery(sqlu);
6 S8 x6 [) q7 T' ~& c" H%>
$ p* b! A) c+ T: P( Z<script language='javascript'>
9 i; G5 Q  y' j% p7 b- \6 o8 f; jarr = new array();
6 V* S+ t. y: Y; B<%  int temp=0;, y, d$ {; @* H, D
while(rs.next())
" X; r9 I8 p( g: }9 [/ \) q6 c{7 }) |, G1 o; z, `" M
%>
5 ]; F# f: K, G4 warr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");0 |/ u. v' L+ m: S9 \& S( P2 v; ^
<%8 v$ x, [; A% j8 q) M6 _
temp = temp + 1;* {& d/ A% S' v* D( e2 J0 ^4 P
}
" f7 L* }* Z$ X5 m( ^3 H, j%>+ P; y2 Q' L" B' J0 F# l
temp=<%=temp%>;9 u, n; v4 M9 ~6 S2 Z' P
function changelocation(id){
  u0 X# ]2 m; @0 p, D1 Adocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 , Y) s; N% ]% d4 k
var i = 0;
- K/ t3 G8 Y- k; v* ~+ [9 l9 V9 bdocument.combo_box.city.options[0]=new option('-------','');
5 s- [' S( f/ T8 rfor(i=0;i<temp;i++){
) j" Y0 ?8 S$ N5 Cif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 8 L7 A* A5 n$ j5 q
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
* y: w: L6 l; a% a* A6 _( C} - Z+ K( M$ I* ]/ F
}
+ K5 x& ^% s5 _1 y}
8 v/ i% H5 G4 J6 l% S</script>* j4 ^! V, N& x: G

  A! \. _# g9 Y7 y1 w* k  n0 X<form name="combo_box">5 `. F! E2 g- \& B4 R; e/ |
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">* y: S* s, H7 m! Z1 A. B( n
  <tr height="24">
' g) w9 z9 U: }$ d, M) X) k    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>' n" c5 L% f. m' i( `6 Z- m. N. B
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>3 R" c7 g; _# }; Y3 h. v
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
% H4 {3 T7 ?0 T# k% E& V    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>) ^- `. g9 s: \+ G" l
  </tr>
7 {7 A; L8 F% m$ [9 {  B  <tr>
& g5 Q% P- f8 [8 {# x    <td>
8 S' P6 d3 h6 U, h% s  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
% z) l/ x* c5 Z6 M( S  <option value="0">请选择部门 ---></option>
2 ]1 G2 N7 z, M& E1 E& l2 |! X<%% R; h0 t" s9 S6 D1 j
    string sqld="select * from tdept";1 `3 V& t% K( h5 `/ I: _% ]1 w# M& @
stmt=conn.createstatement();
3 V- e2 ]2 q  j; _3 hrs=stmt.executequery(sqld);
4 @4 y' J0 ~! M5 z3 N4 \while(rs.next())
6 F0 R5 ^3 d4 y" S' F{# s  I* f' Y$ [/ E2 u* {
%>
, h. I! j7 k* h5 s8 C  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>8 J! V* i1 D( m4 D4 ]9 V6 k
<%2 d- l! }% j: f) P3 d
}
. a5 P  W( P# g, u% o. U' E%> 1 ], p, S6 K( d+ _$ K
  </select>" m. k0 s5 ^/ u/ F
</td>
/ s# \! M2 N) [9 ?# |1 o    <td>
# X6 J" b+ F# t9 L  <select multiple id=city style="width:150;height:200" class="bgc">7 B6 k# H* p& H7 i5 g# B! w
  </select>
* J& z$ Y# b1 K$ e; J/ n# p  `8 K' {& j</td>8 N8 D) V, z6 `  F( S  A
    <td nowrap align="center" class="bgc">( C! c% r( {1 d- V4 d7 h: g
  <input type="button"  value="<<" class="buttons">" i" m& a1 q- @7 O- B+ c7 W% O) M
  <input type="button"  value=">>" class="buttons">( ~1 R6 z4 Q1 M' {7 }$ u$ _
</td>+ N' y6 p6 h5 D$ C
    <td>
5 O0 X- F& A+ B  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">* o: n3 L# |% _4 Y. W+ k
  </select>) {6 h, H; w  L
</td>$ t" m* D% s  X- v  Y8 m( w/ H
  </tr>
' m# A% T) T7 a; ~3 n    <tr class="bgc">
& Q. N# I* F  l; O+ X/ z  [- l# q    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
, d0 e; Y0 T+ u* D8 m) A% D  </tr>! h) ?  \0 d5 z$ [& U. i! d8 |* J2 y
</table>
3 N+ L8 p/ n4 A7 p% k8 u: U, v1 F</form>
' k. q% A: U$ n( S( z<script language="javascript">( f: W+ F0 Z9 {" e3 M4 O5 g" H
//人名移动. Z) n6 u1 r7 H5 m: k1 K' B$ C; u
function move(fbox, tbox) {7 x' y% L, L" A: J) I) @, m0 v
var arrfbox = new array();
8 p: [' r' d" S/ M$ y% dvar arrtbox = new array();5 V) o$ n9 w% Z& `, l
var arrlookup = new array();. a9 U# q  }: L/ H0 h; _
var i;
0 ^2 R/ r. ?6 ]0 A5 @6 `for (i = 0; i < tbox.options.length; i++) {
5 G8 c2 Q9 d$ U* B# F7 }$ L; ?8 zarrlookup[tbox.options.text] = tbox.options.value;
8 }+ H  h% f  S  ?arrtbox = tbox.options.text;
/ b+ K+ D* F5 F" C}' v/ f7 [  u5 `8 r, \
var flength = 0;
1 i; r$ H6 \8 r4 P# z; ivar tlength = arrtbox.length;8 y. l! }  D7 T$ ~' k; F& E
for(i = 0; i < fbox.options.length; i++) {
- e* x2 j! t: d+ uarrlookup[fbox.options.text] = fbox.options.value;
7 }. e" u" I4 I( {) Vif (fbox.options.selected && fbox.options.value != "") {8 ?; i, F) D2 @$ }7 k6 u
arrtbox[tlength] = fbox.options.text;% Z, B7 D+ H2 H$ n1 ?/ e, a2 i! C
tlength++;& Q; y. y, N) ?0 [% s/ b# a. u
}
. I% d5 J* \; Delse {/ V' l; r( m+ ^7 ?7 M) {
arrfbox[flength] = fbox.options.text;: y& z3 r4 @" a: y3 e( q4 B
flength++;
* B( q  ?; z+ ^4 \  E! d# A- X   }
' }4 R0 m; ]6 V! V. \) A}
/ u7 g9 h2 t: U5 ~arrfbox.sort();" Q7 Y2 ^% S! x+ a2 P1 L4 i3 |7 t. u
arrtbox.sort();. a# b( g" j' [/ N

. W  N3 \# m, W5 N+ G% Z% P8 `* Jfbox.length = 0;
# M! a+ K/ ~- q  K9 xtbox.length = 0;
% n! h1 f0 \9 H7 v7 y- o# w* Bvar c;! l3 C" E5 x- v4 w' I8 C
for(c = 0; c < arrfbox.length; c++) {( z, O* F# H0 A3 A9 E9 Z8 ^+ }
var no = new option();
0 U5 u3 |# A; Z, Jno.value = arrlookup[arrfbox[c]];
$ c4 m9 e1 }; ~3 |8 s% \; q1 |4 pno.text = arrfbox[c];6 f+ g2 o1 q# t% S8 j
fbox[c] = no;
4 }9 d+ e- m9 g! Z# F}% q& I# l9 O! z4 w
for(c = 0; c < arrtbox.length; c++) {
2 ]% \$ D. v- V* @( B! ]var no = new option();4 g* P) n. ~0 J" a# O2 |2 `1 y
no.value = arrlookup[arrtbox[c]];* U) {0 c7 w/ @! _7 O8 q: I
no.text = arrtbox[c];
8 d  U7 _7 z' O& Vtbox[c] = no;
* F1 G" G& C  H) P" x   }
3 F8 T! ^0 K, q* r- ^4 r}+ `2 Z( K, ~, `  U
</script>. ]  b' ~# l$ X6 ?, G
</body>
9 _& N5 E' s+ }/ `, d7 E

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