返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
$ m6 X7 P) ?( U1 a. Y+ v6 f         c pageencoding="gb2312"$ a, d0 T- g6 Y! O' {9 C- j
%>
6 }& G' ]9 x1 A/ f' s2 F<style>
( Z5 B# ]$ Y! D! b2 |9 `- J* {.f9{ font-size:9pt; }9 q7 y/ n6 Y$ t2 e' |, c3 ~
.bgc{ background-color:#aecaf9; color: #0033ff }1 K8 y8 t' _. @( j! l* {& \
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
5 P( n. f4 _" A3 w$ |3 r7 n  border-bottom: solid 1px #4e7dc1;4 L" b, o! F# A1 o4 X8 H
  border-left: solid 1px #aecaf9;
5 h: ?4 Q& x& |: c  l' N  border-right: solid 1px #5679bd;2 P; ~/ P: B0 |
  padding:1px;
4 M) v0 `! f+ b# s& t! H  margin:0px;}
% k" E, R! Z6 R+ c7 ^' U4 H0 A7 ~</style>5 t0 `3 \+ p7 i# A- W0 y/ Z7 W. S) d
<script language="javascript">/ g2 |( Q8 F8 @2 [8 v
<!--' K1 H9 a4 E, y2 U
function rv()
% O/ v9 @) c" [! x; V$ H: [{) x8 h2 v& N% y5 l
  var val="";# H. i- [3 ^3 I( Q) N8 c% d* X0 F
  for(i=0;i<combo_box.list2.length;i++){
+ p; r1 r5 X0 }- A, q   val+=","+combo_box.list2.value;
& E; |$ A3 G: K! |5 \; T) ]7 P" g, h  }& |* N4 f7 V: t& n, W( @5 \0 O
  if(val.charat(0)==","){
  w0 i" {% F; f0 `$ J   val=val.substr(1,val.length);% i6 c0 s0 L- v6 z2 }' D8 Q
  }
2 o5 n9 H% T' _9 x  opener.form1.frecname.value=val;3 E( m0 q+ t: ?- J5 j  g" X
  self.close();
+ u, ?4 c  f( M1 k9 X) m}
1 h! Q, n. f9 r9 j/ `$ F7 d//-->* U0 w1 l: v" q+ @6 ]8 o: H& |& ?9 Y
</script>: P4 U* m  d% \2 C
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">& [0 W- a' t9 X* f( v9 J6 r! {
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />- L: E% X# x- k. D4 K# H6 x! ]" @
<%( d& ^" y& Z1 z
  cdatasource ds=new cdatasource();  //数据联结bean实例
( W( E/ p) \/ U" j  java.sql.connection conn=ds.getconnection();
; ^! H/ R! l* b$ G  java.sql.statement stmt=null;1 @4 e/ N* r" b% R  g5 O
  java.sql.resultset rs=null;" F3 N& V5 V9 g
  cdatacheck dc=new cdatacheck();! c) |% U( Z7 D, {
%>/ p0 \  K  ^* u
<%# s* T( V6 C* m2 ~" h+ m1 l
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";
1 s( ~6 N" `# r/ W: Xstmt=conn.createstatement();* X1 M- I3 m. m" m
rs=stmt.executequery(sqlu);' y/ h0 g3 `5 H. D
%>
3 c4 I: {; q9 a<script language='javascript'>
; ~9 w1 M7 x8 T  F/ z! iarr = new array();
% P( K1 w, s0 \/ i3 i<%  int temp=0;
6 E$ r  `' {4 p; J) b) G, Z' w- V$ Vwhile(rs.next())
" `9 g% S: P  U# `{+ a( ]9 X* P( U5 F( H6 `' E' P( g
%>
( }$ y- g. n/ w0 g( t* O7 C3 `arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
5 r1 G9 Z8 G" p0 m: ?<%; K. {$ R+ I7 q# t; V
temp = temp + 1;' S9 ^& L1 }! f# d& ?
}5 I9 F7 M5 t5 E; x! I3 r% B$ Z
%>
5 l1 b, f3 f0 r$ L) Ttemp=<%=temp%>;
6 r9 T, J7 `: E5 Ofunction changelocation(id){
4 A* i+ i: i, z- tdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 / \' s# `# w+ P
var i = 0;
, K/ z3 o" g/ ]5 ~document.combo_box.city.options[0]=new option('-------','');
+ @5 m) e, V3 H) I* X4 Xfor(i=0;i<temp;i++){
* r) P: E+ C; g5 n2 J- Z: _if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
. h0 U' H/ p: y" r9 H6 S( M0 ^$ Edocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
+ Y. i/ L1 w" f1 C! k- c8 o}
+ x: _* g- t0 `% d$ v  q  y}
( V+ C0 q1 o! t. k1 _& V9 w$ ?}
3 ?; [4 G; x8 Y! I/ j6 W</script>- I- R2 \$ O/ [
2 E9 _+ {* d- ^, I3 m! j
<form name="combo_box">
9 O' A3 O+ Y+ ?( q7 T. }1 A3 Z6 \<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">! f2 V0 [& l; J# q
  <tr height="24">* A4 f5 H3 H( D- M: d1 r
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
3 [+ v9 B+ n, S) O    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
# X& @: I" T1 a$ z+ p3 c. u8 H    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>, U9 S2 ^, M0 k& e( W
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
/ M' d9 J4 R* r$ P. \  </tr>
8 d3 [4 t/ N* j* `( S6 w  <tr> - M% n" k4 F) N! ]) c" ~: Z- ]
    <td>
+ c2 r: z/ `# o7 S9 \  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
3 y4 Y: w( T* l$ d  <option value="0">请选择部门 ---></option>
% v* I" x; z. D* Z# H$ U<%
6 P# d8 [6 s9 r5 k! w$ e& M6 T/ n5 J    string sqld="select * from tdept";
9 T3 N0 _) U4 gstmt=conn.createstatement();
% s+ r3 u( Y. O% n' u% Crs=stmt.executequery(sqld);
) p4 V* F) G  w$ m% \% T/ @6 Hwhile(rs.next())& a3 }$ V$ G2 |; E5 ]
{
0 e& Z! w1 f, |) m! F3 k' l%>0 m/ Q0 N: R: O4 j
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>% \  E9 E6 ?7 T. L0 L  r# C
<%
6 I& _; ], ?+ y, y; l}
: T9 _/ X# h/ \/ y  m  U%>
4 z4 s8 x+ r0 v$ F( ?  </select>! ?% U' z. R& W4 _3 v% M" r+ U
</td>
8 j; S9 f, F6 o/ S    <td>& q  e0 v% A% k3 a
  <select multiple id=city style="width:150;height:200" class="bgc">& h, Z1 i. V: w6 }5 w
  </select>1 d% v6 v; B, z; u/ ?8 U' E0 |  l' Y
</td>; ^; a( i+ v+ B- G+ D% M" |
    <td nowrap align="center" class="bgc">
* w% y, i, ?$ D% f! b& {  <input type="button"  value="<<" class="buttons">7 p- F# o" I$ H$ K
  <input type="button"  value=">>" class="buttons">6 H/ X* K: Z7 B( \/ Q- [- z- ?# v
</td>
6 `+ r5 X$ T9 }4 o    <td>
2 ^  P, G# w( N  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">/ w+ u3 i5 \8 m3 _$ u
  </select>& ?7 e0 S- ]3 K  J/ G" k& z' T1 Y. A
</td>
* M+ S+ I7 n. W2 S: v* G  </tr>
& x7 N$ B9 m0 O- H4 K. X/ l    <tr class="bgc"> - j# w8 O: F- h9 V9 Q1 P  F
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>( ^6 ~3 _: k7 z) u; g
  </tr>  N. O3 h, f# r. j( `
</table>$ Q: m2 h+ u/ z! i) V1 S
</form>
, X6 \4 I, m: a' ^<script language="javascript">) t& q. [! S- Z3 I" J
//人名移动$ k4 M9 c2 u$ S# J  V. t+ J
function move(fbox, tbox) {
* {7 u" n3 b3 {3 J1 H& qvar arrfbox = new array();
9 E/ `4 g# Z  ~* C5 p, ~) z( jvar arrtbox = new array();  k) [& P4 o- `; ^! }
var arrlookup = new array();, n4 ]; P: l4 P2 W# E+ {& h: T$ s
var i;
8 w3 E2 c. v8 u' u/ ofor (i = 0; i < tbox.options.length; i++) {
9 U! Y. N  e$ G/ s8 D7 earrlookup[tbox.options.text] = tbox.options.value;
! K3 O8 F2 j9 W+ C2 h) Karrtbox = tbox.options.text;
! }2 E$ s1 i+ s4 q}  [& u; c3 y6 t6 o- g
var flength = 0;( g; u5 P& X8 ?% O/ _
var tlength = arrtbox.length;8 o  t# ?, N9 e8 h
for(i = 0; i < fbox.options.length; i++) {
2 e7 x- Z4 s  t+ zarrlookup[fbox.options.text] = fbox.options.value;8 X9 B$ e; C2 ]5 X
if (fbox.options.selected && fbox.options.value != "") {7 [# T! F# m) p- @, h) q
arrtbox[tlength] = fbox.options.text;
2 Q; W* F8 i# S& g. Utlength++;
" ]' [) g( |5 a$ n$ R& n  G4 U4 K}
, ?2 j, {: B2 W3 |" jelse {
. X4 l% q. |4 V& o( b0 T5 n5 A+ m4 Karrfbox[flength] = fbox.options.text;% u1 |; G6 ^$ r5 C$ z
flength++;& x1 D: u7 u) g- t; ^$ O& ]
   }# w1 D4 M1 ~$ y1 j
}
7 T- _( k4 M2 c1 i. parrfbox.sort();# P/ P4 q; T7 U
arrtbox.sort();
  x+ k7 j1 u& a
  E$ G; p' D9 m, o0 Mfbox.length = 0;* w2 |* {8 Q- V- R9 X: N
tbox.length = 0;
' B3 r! j1 T# n- |: Wvar c;$ @9 O' w" q0 P, K4 I" R
for(c = 0; c < arrfbox.length; c++) {
. {- h3 b; {/ s6 b: Lvar no = new option();
& E  m/ u+ `" v& K" G7 D" Qno.value = arrlookup[arrfbox[c]];: s7 j! U1 D: `* I. |+ y9 S
no.text = arrfbox[c];
6 b0 B. i. R1 L  y/ E3 `fbox[c] = no;" z: Z" b: t$ x2 Q; \, b# y2 {
}, v. ?$ T6 F  q9 m6 k5 Z# I6 ]
for(c = 0; c < arrtbox.length; c++) {1 f! H8 l7 q# N% Q
var no = new option();/ d. a+ E( Y( [/ Y
no.value = arrlookup[arrtbox[c]];( j5 x4 f& ~" W: O" C+ u
no.text = arrtbox[c];+ g, A: j# a/ g
tbox[c] = no;, f' ^, g$ T+ B) S
   }8 y9 w/ w2 \2 F
}
9 k; ?0 R; q# H0 Y5 ]$ T</script>
. @1 S  l9 y& F8 f$ |. f- R- f</body>7 B7 P: c1 M% s2 M7 [

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