Board logo

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

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

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"- d5 t8 W8 g' @6 Y
         c pageencoding="gb2312"
- Q% s$ p$ Q2 ^%>2 h+ \  a- Q6 X2 \+ B. B& @
<style>
+ b, f/ D* x" T4 |$ F.f9{ font-size:9pt; }
2 X. F% i; L. |2 ?1 ^6 ~: D3 O% S.bgc{ background-color:#aecaf9; color: #0033ff }! M! b3 K) T& R4 K3 K  d* {
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
: Z5 X7 u9 ^* L6 `8 g7 Q  border-bottom: solid 1px #4e7dc1;
" P) H% Y9 M" x, `5 F3 J+ u  S$ t  border-left: solid 1px #aecaf9;0 c; r, E, d1 S
  border-right: solid 1px #5679bd;$ ?( G% K7 k% N8 x6 `' i
  padding:1px;
( W8 R! P+ O% A' j6 Q. u  margin:0px;}& `+ x+ f* t' V6 ^* `/ O
</style>4 r) G* u: t7 x4 |6 l
<script language="javascript">8 y$ a' p3 d9 x" L2 c5 K
<!--6 q4 p8 `7 J. }
function rv()( b1 y! G2 _" O  z" }
{# y; S- n3 o1 `
  var val="";
9 i) A0 r% B7 J' D6 G6 M7 j  for(i=0;i<combo_box.list2.length;i++){
8 u; L3 {0 a: I$ v2 N   val+=","+combo_box.list2.value;+ F/ l( T+ l0 w9 K4 Z
  }+ b, y1 u; I7 v: P% s" L
  if(val.charat(0)==","){
- h7 H5 o4 V* p+ r& l   val=val.substr(1,val.length);
! I4 K' i& y/ O) w6 g. k% s  }
5 p4 h' w+ J* n  opener.form1.frecname.value=val;
  H$ G. i0 E2 Z! }+ |- o$ c  self.close();
( t- b$ c8 L- H0 q( f. v1 ]+ v% s% d}
6 z2 v* c" Y9 M' `3 W8 Y+ J//-->2 G' N2 \% E5 l6 c; r0 {
</script>
% \' w! \  Q: t<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">+ B; _, v7 ^5 ^: F' I, i+ q4 C: t
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
9 c$ H! [0 X; l<%
! |, ]* B- [$ i1 O4 e2 M4 J  cdatasource ds=new cdatasource();  //数据联结bean实例
; a/ z, H# n4 }7 k" W$ `  java.sql.connection conn=ds.getconnection();
$ ?6 N8 a1 }2 M+ x" X  java.sql.statement stmt=null;
) j9 b. u1 X! y- P* P  N- P  java.sql.resultset rs=null;
2 G, {8 ?' ?0 B  cdatacheck dc=new cdatacheck();
7 p( Y2 _: {' E2 r9 a7 J! H" n%>
' e3 \, ]! C* X( Q7 [<%% p: Y* }- e$ n
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";' {$ \+ O- ?8 ]" Y. Q
stmt=conn.createstatement();
% Z! P+ n+ }* {; S6 R, T' S: vrs=stmt.executequery(sqlu);
. t" t. d% C. w- z* C%>3 K9 ]: J% r3 q3 {
<script language='javascript'>- J* f7 M6 [: T: m
arr = new array();" Z  d# C- O2 {9 y# [, f+ h
<%  int temp=0;
9 Q8 ?- k3 W" t3 N4 Z, Qwhile(rs.next())
# M; b# w7 |2 ]" v{0 L8 \2 L5 ~9 V# s
%>
, t( P8 x1 _! qarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");/ E2 z) x9 q4 _( l6 [3 G. h
<%
1 P6 I4 r, C. ~# `' k6 J- V, i" btemp = temp + 1;7 r. \8 Z  \6 [0 L! L3 b1 U, J
}
; `- V& ~+ y+ C7 T% Y+ q%>1 v3 F# |1 p. c6 K! \% p% w/ V
temp=<%=temp%>;7 l/ |4 R. f) G- O' v
function changelocation(id){
/ a' {1 V( j; i& |document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
( B& n& z, t0 F8 Svar i = 0;
+ r( [: U. t0 K  ~, odocument.combo_box.city.options[0]=new option('-------',''); , c& [, \$ K8 h" h
for(i=0;i<temp;i++){
9 ?0 p# E. |  \9 }: N9 Pif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 6 h, G" |; P: `" K! B
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
/ B9 m6 F8 a, h' w" x4 f} 1 \" B' m% o$ v- U
}
0 I" v/ a' K! p6 m} 4 t( N0 g" k3 \- H! m$ Z# F
</script>0 ?2 V; x$ x2 c% b6 [
0 y7 v: D+ p7 \6 U% c5 b) [* b
<form name="combo_box">9 }& l# N! _) ?* E6 S# i% b
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
, z# G7 W* A/ z+ L0 m3 @# w  <tr height="24">
3 k- D& h9 h! c8 ^    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>" T0 Q3 q& U; d" y- {
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>/ l. E  X$ _  f, `3 w6 ^0 D
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>5 p' p; @3 ]+ D+ K4 f
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>% o+ M9 {8 V- T0 O1 u" e! A
  </tr>* M$ r0 j; u7 Y/ t+ h2 P
  <tr> : I+ d7 k5 }) V8 h! a3 M+ N, n
    <td>
# R7 M' _" J! `* [8 M4 Q  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
  d5 |7 E6 d4 S9 h) R: i4 N  <option value="0">请选择部门 ---></option>
: P  A& C" k2 e  O$ @<%
& k& A# r# h' x1 h2 ~" O    string sqld="select * from tdept";" Y8 {0 n! ]/ j- [% P7 k
stmt=conn.createstatement();! C5 T% R+ z' x2 \- a2 N
rs=stmt.executequery(sqld);1 @- {7 x5 y: j4 n) z% M! b8 A
while(rs.next())
0 d7 x1 I# L; ?9 Y0 R{" j- y" w, ~% a. j# e/ O2 s- l
%>
! Q9 n/ b- v' [2 Y- u. e+ V  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
1 E" G+ I! @9 q5 N- c- |<%* r: N) P& \8 ]
}
6 u$ l$ v3 `4 c0 `1 `%> ! Q* F1 ~! R! {( @" O
  </select>
7 |, u5 @$ P: l2 D+ ^</td>. i" m' z) ~+ Y5 |
    <td>
* ]1 [6 g6 P% V$ a! e  q! G  <select multiple id=city style="width:150;height:200" class="bgc">
& c( q5 k; `; F7 v3 g' I' L  </select>
. s6 E+ B3 o: r+ C</td>9 D7 A7 w2 \* g& D" i7 i4 T& R0 |! {
    <td nowrap align="center" class="bgc">6 ?: s1 o0 u: r7 U) }# F
  <input type="button"  value="<<" class="buttons">0 E$ `; t# L( d) B% @8 u
  <input type="button"  value=">>" class="buttons">6 ]5 H7 }/ k& B3 K& J- |. r9 |( ~
</td>
0 [' l* b: p# j  }    <td>
0 h/ l  W+ v5 A3 W' D6 `  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">8 S7 [7 Z0 I, M' k6 @' E
  </select>! Q. y3 [6 Q% A8 Q, z" y+ R
</td>
/ ^: X( N3 D1 q, t% Y6 c/ k+ Y) z  </tr>/ x! `6 s8 N8 ~& _
    <tr class="bgc">
0 R7 Q; w3 [% c    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
$ r8 ]' {& ?) v  R  </tr># L4 b4 H, X$ H, ?' d. D/ O
</table>
) y0 i! b- Z7 J  B3 l</form>
& S! k' B4 M; T$ _* p% e<script language="javascript">
' M; r* ?) o5 u//人名移动( x* t7 s' W# ^( v
function move(fbox, tbox) {; }1 L! C; X; Y* [/ t) v
var arrfbox = new array();* E5 w% B& p' W3 }2 m  m3 R( A5 ?
var arrtbox = new array();
7 d# ~1 N( J4 a4 L! T7 Uvar arrlookup = new array();7 }+ i6 {0 b. b# m
var i;5 p8 n3 u0 c7 y2 }9 ?
for (i = 0; i < tbox.options.length; i++) {+ Q4 g4 W8 u1 ^* |0 z, V
arrlookup[tbox.options.text] = tbox.options.value;
5 {. N& f9 L8 N, k* V8 ^2 Xarrtbox = tbox.options.text;
5 c; r# ~' t& v9 X}" z. \7 ]# U7 h& ~  y, g7 s
var flength = 0;) w+ ?2 }& g* p/ p1 k. r7 A. D, Y
var tlength = arrtbox.length;
$ @( `' A, |) Z4 {for(i = 0; i < fbox.options.length; i++) {
; Y6 |. l" s* _* |arrlookup[fbox.options.text] = fbox.options.value;
1 M$ T$ M' s  l* yif (fbox.options.selected && fbox.options.value != "") {
6 u0 F9 k4 S2 J4 }; D6 karrtbox[tlength] = fbox.options.text;8 Y7 y" V6 W. Q) I( u% W& e/ V, y
tlength++;+ S5 B- k5 P$ F3 z! m" }. ^
}
& Q$ F+ H( y& _( E. L! Welse {8 R* s) c, D; ^1 o# {/ V8 _
arrfbox[flength] = fbox.options.text;' Z& l$ j" U6 f2 i# `- C
flength++;8 j* ^1 u: P& j
   }
) F9 e9 v/ q/ \: _6 L7 G}
8 @2 n8 U, k, h7 Y: K  Q2 Varrfbox.sort();
3 n! S7 ]  m! D& [* r- Garrtbox.sort();
! s, Z. R- ?7 T  f) |7 |0 N( q' S6 r2 @3 V, V
fbox.length = 0;4 S+ X. W4 ?* D$ u( r. J
tbox.length = 0;
( O- S3 U+ |) O5 |0 u  r& X+ _var c;" r! |5 v3 W& j. V
for(c = 0; c < arrfbox.length; c++) {" k9 {& J. ], J% M! R
var no = new option();
0 E) P! ~( K4 Nno.value = arrlookup[arrfbox[c]];
1 a+ {- m1 B6 L9 vno.text = arrfbox[c];
4 `6 E" q; Q& A- Vfbox[c] = no;
- T6 X5 S! n7 u, p6 m( @}
9 ]2 I% A/ m: W  S" hfor(c = 0; c < arrtbox.length; c++) {: a/ }( z+ c2 t1 x6 t$ ?
var no = new option();/ l/ t( b4 W# a/ H% ^0 l
no.value = arrlookup[arrtbox[c]];4 Q" b; M/ f: ?+ s# h4 g
no.text = arrtbox[c];8 J0 G9 \) e. V  c
tbox[c] = no;2 z& s3 {, w9 D9 `7 t5 D5 D7 Q1 j
   }
+ n2 W, o  _1 u: b2 u, _}
' _! w+ H* C" Z9 s2 D0 I5 M</script>
& R) T* S; @' l$ ?( C</body>
+ T( l9 G4 s* R- t( }# S5 ^( ~+ @





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