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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"# A7 \6 Q1 `6 k) d
         c pageencoding="gb2312"
9 ?" e$ g" Z: i5 W! S* I%>' ^. d  T" h+ c' s
<style>
- F; }+ E5 v( x) c" }6 C.f9{ font-size:9pt; }! k' f2 @* h+ l* F- P
.bgc{ background-color:#aecaf9; color: #0033ff }
% d2 X1 R0 w9 P.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
* O! i/ A# n# f  border-bottom: solid 1px #4e7dc1;
# p. n7 s4 O  k" B9 \0 k- l& {  border-left: solid 1px #aecaf9;, M6 o! Y0 X' p4 R, q. t$ \
  border-right: solid 1px #5679bd;
) F  m4 ^8 k) j0 O. M  padding:1px;
6 Q: j9 Z" j, @4 b- C* {: M  margin:0px;}
  l8 W* ^; v: @% ]</style>) }4 ?4 u8 `8 |" V/ s% A$ K# H5 o
<script language="javascript">
) w) A; p( L3 W# S" m" k% m  V<!--
8 y! d) l- A7 ?) b1 q: V) R; Rfunction rv()
* k1 a+ G+ {+ [2 r7 W/ v: O1 `{
& l! X  @6 q& Z$ ?8 t8 a  var val="";
/ u& Q, ~' F6 [  for(i=0;i<combo_box.list2.length;i++){
7 D( k3 ^8 G& S! V8 W& x% s5 g  k  v9 y   val+=","+combo_box.list2.value;
, H% ?1 N9 ~. J/ ]& O  }* \$ f6 \# m/ k! e3 H
  if(val.charat(0)==","){
+ q3 B8 _$ B. a6 ]. ?: c   val=val.substr(1,val.length);) a, C! w. ]  _& @* @) j7 p6 i
  }3 K' C. d1 E* Z6 \9 I* X+ }
  opener.form1.frecname.value=val;
% ?+ z: D* ]$ L& X6 z6 o: }  self.close();4 g' X3 r4 l9 n5 W+ G6 t! u
}$ Z5 c1 p6 }! L5 l
//-->2 R% I+ [3 d* j. i, z& ?
</script>& d4 a: }! D- ^; M; m3 v
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">" ?* t- {& r5 C- b+ D
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />3 X: D/ U/ i6 y  n  b! i
<%1 m1 U9 Y8 Z6 ~- J
  cdatasource ds=new cdatasource();  //数据联结bean实例6 ~$ G  s2 _( a
  java.sql.connection conn=ds.getconnection();; n8 \( R. @! y5 {
  java.sql.statement stmt=null;
9 I1 m/ l- ~* X7 @: l  java.sql.resultset rs=null;; S5 {- q; \9 E( s2 X1 Y+ x
  cdatacheck dc=new cdatacheck();
! s2 X. d& ~* q* n%>, c2 Q) |( @' f* H- @; w9 s$ u
<%
& u+ M' b  l. v2 g* J' Bstring 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";. P1 M, p+ D$ F6 S2 A
stmt=conn.createstatement();7 s! a9 G( D3 L" ?7 R
rs=stmt.executequery(sqlu);0 U- H; s( w+ S
%>% a8 n4 \) f; d8 N/ l
<script language='javascript'>
' k8 Z7 }% Y3 r6 Z- [arr = new array();
8 R& M/ x; [: u& n! Y  o0 f3 j& E+ b<%  int temp=0;
1 U  ]2 ?5 ~+ S# }while(rs.next())
+ s2 q7 R( Q) q5 {0 S2 L% a{
& m0 K7 q7 y* n5 H5 j. U2 F%>
4 K+ ?/ c5 ?2 R0 Iarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
9 C( G* ]' t/ W<%
/ w9 C2 T" d  Y1 P9 d' H3 Z$ `, Utemp = temp + 1;
1 }+ W2 v! {6 z8 {}
  ?6 F5 w0 t% x; o" U% A9 m+ U%>
9 D+ v7 G, g% @# F$ Ztemp=<%=temp%>;
+ Q* U( E; @. _! J% h$ ~+ E  S" c; Wfunction changelocation(id){ 4 |6 G& s3 ?  v- C% C6 ]' S
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 & Q6 o" Q- {. Y4 @
var i = 0;
8 w/ ?5 N) _/ _; Q2 q# Hdocument.combo_box.city.options[0]=new option('-------',''); 3 R" @/ P5 U" \: u  G# `. \2 ^
for(i=0;i<temp;i++){ ' r5 D! s, ^9 }1 H1 Z0 y; ^
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] & c$ R- c# m* R+ [% K
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); # ?( D4 k+ }9 V
} ( |( L2 b& o' n8 m: C  S
}
* R2 z# h9 K3 ^7 f" }}
7 M4 C9 F8 d! y  b1 y. l$ X</script>
" m0 }- f+ `6 U6 p
5 ^5 t( V4 D2 n! Y<form name="combo_box">$ U9 h; K/ D$ d" ], u
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
- q4 P1 M, q+ z; D! y  <tr height="24">" O8 m* N/ k& |( V- ~8 q% i# c
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
+ d  S* r  Z4 k" n    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
5 U+ O# }) m. n0 p    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>: v# i) V1 a9 l7 J
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>3 f( @0 X6 {- ?$ `/ M, ~4 b) P
  </tr>$ i0 m8 ?. F& @' E
  <tr>
% V6 w+ r' j  ?) G5 s, U3 Y    <td>2 O/ K/ Y0 C* v: O. J+ e! ]
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
4 B2 [' \4 e+ S  <option value="0">请选择部门 ---></option>1 L- I2 K/ H- P3 t* ^
<%
' U$ v+ K1 g  m4 w6 f% L    string sqld="select * from tdept";: q; b6 d* K) C( R' @9 ]. N
stmt=conn.createstatement();
* v3 c" s6 ^) \1 o' P0 w, M. \rs=stmt.executequery(sqld);$ q; f& H# h% H1 y
while(rs.next())1 C. `- s3 Z( w, q7 b- d, r4 M
{
+ ^8 z6 w7 B; R( n7 r' O0 {2 e: h%>8 U  ]; d8 }- h& S* S1 q; s8 l; V+ d5 I
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
5 ]+ h, p5 m) l% R3 a. y# v6 d<%8 r0 Q2 r/ q: d0 U# W
}( d* B- W+ u. j3 p6 ?9 D( u
%>
8 I* X$ [8 S. ^; S1 k1 A6 L) D0 O6 z  </select>
7 f) h/ y6 ?- z/ b4 f</td>
4 O! @0 Y$ W* z# o; {    <td>. \  d* R: E, G$ Q) }6 f7 I) Q
  <select multiple id=city style="width:150;height:200" class="bgc">) s" A% n/ g* Y, y
  </select>) H% n9 a' K' `: W- K
</td>
) I) m4 H. J  I    <td nowrap align="center" class="bgc">
7 }/ z! G% f2 U  <input type="button"  value="<<" class="buttons">
7 S& {: |4 U- q. d  <input type="button"  value=">>" class="buttons">
/ v: d2 M: I+ j9 W. c. m% g3 h/ o# p</td>6 V# }5 t* ^7 b
    <td>
- S  H! G8 R1 P( \, U# U  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">! @; D+ E7 Z* G6 x) Y
  </select>6 S) b6 h; b! G, C; Z1 G4 o
</td>
8 A- Z- }! b) V3 b  </tr>
$ }+ p% M% `3 ]1 J    <tr class="bgc"> $ v9 c( x; _: t) _3 E2 }3 T! \
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
! p# [6 C; x7 o6 Z! k1 W  </tr>
  Z2 }8 q1 O9 a2 b$ Z( W2 y5 }" [</table>; t2 w1 g# t8 T' D- I; Z# z( s
</form>
* b. E; v  L4 N: h+ k4 h<script language="javascript">
# ]: \( s  E, _# I5 S+ n" F/ K//人名移动
" C" {6 Q7 G& \2 |0 d& v% \function move(fbox, tbox) {
7 {6 Q& m9 y- v+ Q1 O' `: v  t% Nvar arrfbox = new array();
2 l9 C1 V. o( u& _( H0 [var arrtbox = new array();
& t( Z3 J2 G1 E% h# q7 q' O/ A/ vvar arrlookup = new array();
3 Z% c+ a7 ~. w9 n/ Cvar i;
9 A' }1 K7 o# ^4 Rfor (i = 0; i < tbox.options.length; i++) {3 c- @3 e+ n4 v6 d+ g8 P
arrlookup[tbox.options.text] = tbox.options.value;. x2 X) M! U, z/ ~6 @
arrtbox = tbox.options.text;
8 Q. E7 M- o; g4 s. @3 Y; p7 G- w/ k}
( L+ p& R7 ^3 O9 Z% W1 Mvar flength = 0;
: o/ N- J- W& u# u, pvar tlength = arrtbox.length;9 {8 \2 s" m8 n7 s
for(i = 0; i < fbox.options.length; i++) {# N+ d, e0 Q* A3 \) g
arrlookup[fbox.options.text] = fbox.options.value;
1 [- D8 J& R! [( a6 fif (fbox.options.selected && fbox.options.value != "") {: j: l8 _3 Y. R' B0 {; y
arrtbox[tlength] = fbox.options.text;
7 j5 |$ H+ }) o) j) m/ Jtlength++;6 w, Y/ H, H( l3 p, A
}
: M' k# Z( D! d: Yelse {
: H0 J* [' t( ?7 b( ?arrfbox[flength] = fbox.options.text;
/ Y0 I7 M9 f' c/ l* d' `  Tflength++;# w+ h' W' m" J1 t2 p
   }$ }% W6 U/ U7 F7 s, e- D1 w2 A0 q
}5 P& E% d% T1 H* V( y
arrfbox.sort();
+ H: q  a+ d9 G8 l6 varrtbox.sort();: \2 y/ C7 Y) N/ w# _

0 d5 l/ e% E7 x5 C6 w, R4 [fbox.length = 0;' U6 j( E  d% t5 x
tbox.length = 0;
8 R4 n# P6 c/ `* U, ~var c;
9 a& ^$ m! G2 k* O5 Nfor(c = 0; c < arrfbox.length; c++) {. f; X/ {& X; k" r8 ^
var no = new option();1 G4 K. z8 ?, H) C; Z% C: ~. \* T
no.value = arrlookup[arrfbox[c]];
9 S+ w  h& \) c' j! jno.text = arrfbox[c];0 `" c* q( U) x7 G( W# P
fbox[c] = no;
  @+ f* C' T6 i3 Q}
9 y( J; ]/ o$ I+ Tfor(c = 0; c < arrtbox.length; c++) {+ o7 S& s, H% B: ?
var no = new option();
2 n( K% I" m6 J  u3 E% h# sno.value = arrlookup[arrtbox[c]];9 g& N* A! o4 @0 a+ `# I2 t
no.text = arrtbox[c];7 ~0 S1 R% Z) H4 h. l
tbox[c] = no;- P7 O. _" v: [/ C, Q( U; i. [
   }
) j# ^$ v' ~  w# Z% V}: ^) B1 P7 G0 ]9 `4 T; J
</script>
2 W4 e* R. i9 h6 V! Y3 c3 E</body>
5 [  |3 q9 k5 I! b$ t6 C* ^5 P6 ~4 o

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