Board logo

标题: jsp+javascript打造级连菜单 [打印本页]

作者: admin    时间: 2007-12-5 17:43     标题: jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"" p# a8 B1 _, \0 E. B
         c pageencoding="gb2312"5 e, z/ f$ l, t; G5 [6 P
%>; Z/ ~, T8 B0 r" O+ _. E
<style>
: A" q0 `* c2 \.f9{ font-size:9pt; }! q0 @/ g' n8 ~# _. O
.bgc{ background-color:#aecaf9; color: #0033ff }
; k3 Q6 x/ y' e" ~4 b.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
) P2 g; G' a$ h6 l' {  border-bottom: solid 1px #4e7dc1;
( R6 g. {  Y+ a1 [. W1 G. K4 w4 U. L  border-left: solid 1px #aecaf9;8 w. F( d; ?5 n
  border-right: solid 1px #5679bd;
1 c/ h$ w6 L4 {6 Z0 }+ {/ A  padding:1px;6 h  i8 S1 t( ?( a/ a# W1 n
  margin:0px;}
5 [5 e8 U: K5 D: r( X3 d0 O6 g</style>5 s( u: t$ W& |6 D0 g
<script language="javascript">, T9 h, Z+ l* f6 R0 W3 W
<!--. ]4 u' m0 r- s1 b( w( |
function rv(); ]# R; S' J  F
{
5 V/ v" ?. [$ a  var val="";8 J* O- P) v; e; z
  for(i=0;i<combo_box.list2.length;i++){
  i' t# v  U& z. M% V1 Q; U   val+=","+combo_box.list2.value;
: ?+ _+ j% D  x# }( r  }
% @. A- p. n4 o2 `  if(val.charat(0)==","){
5 P9 H' }3 c- X  L1 z4 h& m" \. A   val=val.substr(1,val.length);& V& @" l# z+ i! J1 o2 Y  g
  }3 H# O# f, @" K5 O
  opener.form1.frecname.value=val;9 u% T% ?" |: s0 k% c' u8 Y, f
  self.close();2 ~" {* R! m' |+ S0 J4 x1 Y
}3 Z- y% {4 J3 M0 E& {# p: t
//-->
0 p: q6 z# _, Z7 P8 a- J</script>% j; y, y! L4 w, K, G& M3 J
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">- \$ b1 C, I, a$ C; H4 n
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />* t& w3 F: Y. t  I
<%) d2 {% V  Z) n( g
  cdatasource ds=new cdatasource();  //数据联结bean实例4 X1 {; \& t, `9 _) F
  java.sql.connection conn=ds.getconnection();2 C- _, m8 D' P8 m) D
  java.sql.statement stmt=null;
9 d/ g  F/ g. ?* {$ {4 I  java.sql.resultset rs=null;1 f$ N, w, W( E/ u; e5 b- r
  cdatacheck dc=new cdatacheck();4 A" |4 |* z( s( g3 Z
%>
( T& K2 I+ ~' G9 z# G" i. S- y<%; U$ s+ G8 ?1 Z' N; D) W  x
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";7 v4 m' y( B' e& C1 V
stmt=conn.createstatement();% S  |8 b" z' V' f
rs=stmt.executequery(sqlu);
; w. [7 y/ i; L%>9 Q3 T; W' m+ |/ N1 M+ j- k
<script language='javascript'>
4 `. f+ E' M5 C. L- [, G( c8 H" |arr = new array();0 Z& ?% @5 y$ f
<%  int temp=0;
) ~, D6 ?- m7 k9 v! a2 ^7 Wwhile(rs.next())
; ^; y8 b  u0 Y  |2 y% m; Z9 W{
% {9 k  R, d) `$ j; M%>$ X: q( w+ D) B0 e3 L
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
7 m+ a/ t) O5 n; o<%
( q# N! ^8 h( V" L8 s- t# o. ?temp = temp + 1;& N  ~) @9 N; F- f& m. ?+ m" K% w
}
0 v! g8 g, X0 K$ G+ }%>; a) k! W% j. x1 `( S+ k( ^) _* f
temp=<%=temp%>;9 E" n3 u" O. \3 P# g+ x
function changelocation(id){
3 X( Q2 ?' d% V4 u# e; R; gdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
( P7 }+ x: }1 M5 A* m2 W. J* |6 mvar i = 0; * a8 U5 T% M/ S, |- r! X
document.combo_box.city.options[0]=new option('-------',''); & \; q/ L, o+ g6 z$ @7 D7 J$ _
for(i=0;i<temp;i++){
- H( p; l/ G+ n) U2 kif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
& c5 W1 f1 D& {/ P  s, W+ E" ]$ tdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); ( m9 m3 x6 m6 j9 L
}
9 [' u- f1 u3 a- Z+ f% T+ o$ _% c}
& f3 S0 K! |/ a$ G}
" W' R9 ]  q9 ?</script>) O4 r& |0 W* |8 P5 l# P

) {+ o# F( t1 A( B! y5 ]<form name="combo_box">
$ t) z+ l/ R( W" O+ e6 ^6 Y<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
: I) `8 K! e- H- ^( Y' _$ I  <tr height="24">* |! X4 Y9 q: I
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
) F: y  L+ Q0 z: r: o    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>; u- s6 Y; v' j+ `' h  D" D/ _
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
4 B  H9 {2 I$ A+ P) A    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
% P0 V* l  ]7 n( n" `! O& \  </tr>
6 @8 a5 Z1 L5 c+ L  <tr> . z# G( ]. M( B4 U2 s* f7 B! U
    <td>
/ q4 l! \2 \4 c' K3 k' M  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">( l' S6 H' _6 W4 R# }  x
  <option value="0">请选择部门 ---></option>& Y; o+ B" }1 A  x  [
<%
$ p# \$ }! z, N- E0 n    string sqld="select * from tdept";1 A% U) a5 F! j; S; l+ u# E- X
stmt=conn.createstatement();
+ ^& {8 a0 @3 z6 [, ~rs=stmt.executequery(sqld);/ q% V8 K+ T8 g
while(rs.next())
3 F  X0 `  [+ _* I. P{
6 ^9 b- H# [$ g4 c%>
) L/ k9 ?1 [" K. U: z9 I4 o4 }  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>. u" u* ~/ h1 d& }% m5 i3 y
<%
& A( a; p4 j$ s0 m}! a: y& Y5 Z( @! F. o% n) F0 `
%>
# [3 |/ o6 |) W  </select>& _3 r6 g" L: q* Z" Y2 m9 j
</td>9 ?* n  t9 R9 C
    <td>
( T( \7 H6 @" n3 y  <select multiple id=city style="width:150;height:200" class="bgc">
0 Q7 k2 I5 H4 @/ i, _  </select>
6 ~+ R, D5 g  `9 h2 ~* I</td>
; w0 b% G  W4 K3 G    <td nowrap align="center" class="bgc">
6 l6 {) {2 c( @- U: ?  <input type="button"  value="<<" class="buttons">7 J$ F( |2 @+ D  K4 B: a
  <input type="button"  value=">>" class="buttons">2 X3 w9 A% Q! J6 m1 F0 l: u3 z9 V7 @
</td>* ~, ^; i) Y. k# S, B  W9 a
    <td>
6 A- ~( g( ^! l  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
+ D! K5 b* U, q+ f0 k" o) }4 A  </select>3 Y  r3 S( z9 |/ B: d; w
</td>! R: h1 J7 W# ~
  </tr>* s; N  y* O; w1 M' F8 @8 F
    <tr class="bgc">
1 U2 N4 g+ |3 b4 k6 E    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>' y, D7 j/ J9 f
  </tr>2 n( x( @+ E5 _
</table>
- G$ _- x7 W! j! P& l; T</form>; U0 e9 |, n9 p) d+ w' ^& l% ^, y
<script language="javascript">
0 v5 I0 r. S( g, Z/ d0 l3 U. @0 R//人名移动) H+ m" v) [; Q  L
function move(fbox, tbox) {3 j) @7 ]3 E, X: w/ O6 c8 E
var arrfbox = new array();7 D3 O: d$ M4 f! L- Q* [
var arrtbox = new array();
6 l, l8 X. M7 x; d; b% U; ~var arrlookup = new array();2 d. a; L+ F- Z# C. z7 q3 Z
var i;+ {, \: ?, r/ N
for (i = 0; i < tbox.options.length; i++) {6 U0 ]: v, _" e* c
arrlookup[tbox.options.text] = tbox.options.value;% B, |( Z: R# @; @* \4 V$ B  u
arrtbox = tbox.options.text;( w2 `" p1 p: X: h& I1 k. J! Z5 X
}. p( t/ f) W" F0 h1 F/ W
var flength = 0;
& d/ T; k8 c8 tvar tlength = arrtbox.length;
  P7 M" T( t; z9 k  ifor(i = 0; i < fbox.options.length; i++) {
7 t  B  v' W# j3 g4 T" iarrlookup[fbox.options.text] = fbox.options.value;
8 J, G0 N. z$ F' dif (fbox.options.selected && fbox.options.value != "") {' N0 w& p+ @! {& n' I* V8 o8 }
arrtbox[tlength] = fbox.options.text;
. L' Q% |; ]: {# d2 Ntlength++;
+ t+ Q$ i! S7 U& M- Y5 t}# q  N6 f6 [# \# x4 E" O; D
else {
8 {% G; B/ o+ f" ~- e4 Y6 e% Parrfbox[flength] = fbox.options.text;. {0 N4 K2 I6 T1 O2 _3 }$ D$ p
flength++;1 m5 _# Y/ d* U/ m
   }& M0 l+ a  X+ Q/ _3 D' ?
}8 s1 n& E8 _: {" o8 _& |
arrfbox.sort();& g% R) Y2 l" M. Z& ]2 d
arrtbox.sort();
# h6 C  s! _/ A/ ~" P; [0 r. H9 I: B" n) P+ K& o& L9 t0 H
fbox.length = 0;
! j" W" g0 E' ]7 L' [5 h) K& m, dtbox.length = 0;& \8 W7 r& S8 Y. M: o2 g
var c;
2 ]1 p" u* i- n. t6 T4 ?3 `for(c = 0; c < arrfbox.length; c++) {8 f- d, h) `9 z$ W2 `8 V6 q
var no = new option();
, C; ~; X2 s! ]2 _; ]; dno.value = arrlookup[arrfbox[c]];% s- r; n/ O0 ?* s& H% Z4 ?' W
no.text = arrfbox[c];
3 G. C; P% H% ?fbox[c] = no;
- G/ ]' O& p) g) k, V}& \2 m2 c1 f5 v+ L( x6 X0 R
for(c = 0; c < arrtbox.length; c++) {
4 u. `1 M2 ?, Tvar no = new option();0 M( _" \# N! h9 ^' B
no.value = arrlookup[arrtbox[c]];' R& M- O7 U/ L1 K/ U, R
no.text = arrtbox[c];1 g& l0 W! [' b! d8 g( P
tbox[c] = no;& K- r% C* T) O: i( ]5 s3 L: k
   }
/ d; C3 [3 j# G7 u+ T}
1 y; r* S8 c% `" c5 V</script>9 t+ a% G" z: R( Q
</body>
  O# M. A9 ^$ Z) |3 o% q  Y





欢迎光临 捌玖网络工作室 (http://89w.org/) Powered by Discuz! 7.2