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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"( R' a$ O0 }& S) y) u
         c pageencoding="gb2312"
# u1 J" D( k* d9 x2 ]$ r4 q%>/ K/ R; Y$ z( ~" K) A
<style>
7 u0 ~% _# @8 J: b4 C8 i.f9{ font-size:9pt; }
1 e& Z+ L1 G& j& k  u, O* H( ~.bgc{ background-color:#aecaf9; color: #0033ff }  Q) y' ?& B& x: P' h7 B1 m0 s5 q
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
. Y: ?7 r9 g( F7 j& M0 V  border-bottom: solid 1px #4e7dc1;2 F. Q$ V) S0 [
  border-left: solid 1px #aecaf9;% ^$ x( N1 U( |- B, E) r3 T) S
  border-right: solid 1px #5679bd;
  m  {8 U  o; C% o, S! u3 e1 d  padding:1px;
2 z1 x/ i% \* x9 K; t: K1 b6 Z! l: t  margin:0px;}  |1 {* e8 v/ _/ F: j
</style>; h  Z/ i; A4 r$ E
<script language="javascript">
8 |+ {& m& Z, t* }9 J1 t<!--- U% L0 R0 ~  x, f2 f
function rv()
0 B. @. x" `& i. [8 n+ {$ V$ N6 h/ ~5 C{/ o; }' u) m% A
  var val="";
- c7 U9 T% l% z5 p% I6 `" B  for(i=0;i<combo_box.list2.length;i++){
$ W6 G- e2 U1 L' U* G- O' B8 I   val+=","+combo_box.list2.value;
) \: |$ e/ `: L' v4 h; ?7 {- |  }
, h' C/ @! X1 u, }* B; L  if(val.charat(0)==","){
# s& j1 W* S; W, T# L, }   val=val.substr(1,val.length);
/ l- f/ T) L; }* H* f& k  }/ y3 F& _1 G" |' ^2 N
  opener.form1.frecname.value=val;3 K/ X- B9 c3 k4 c! E( g
  self.close();- \* O6 b3 u8 s' R3 }
}
, r. Q( T+ d2 h3 {: j+ a6 g//-->0 G0 l" W7 o' t* D& H. H* X+ p
</script>
4 U7 Q/ g% |4 ^9 `/ g6 T! u* H<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
, e; t! X* T3 n8 d' A* {' J/ r<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
) r3 x; `+ @$ P) }9 |<%
+ @% Q  Z8 d4 L- Q# {) L$ N2 {  cdatasource ds=new cdatasource();  //数据联结bean实例$ t. L+ f4 u/ T& R; H! g2 [' N3 m
  java.sql.connection conn=ds.getconnection();
7 v+ X  D1 V4 _! t  java.sql.statement stmt=null;
: A( j8 k4 G! B3 h" ]  java.sql.resultset rs=null;4 p" f1 R# ~5 U, p0 W" }* p
  cdatacheck dc=new cdatacheck();
; \7 I7 ~0 c) j$ S8 Y6 h%>
9 W( l4 T; g1 \3 {! E<%% r" c, B# O/ [9 b5 g5 J  k! ]9 M
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";
" q1 ~" }/ x, I) S' zstmt=conn.createstatement();$ z' `3 X3 }2 e2 t* i& c3 R$ A
rs=stmt.executequery(sqlu);
2 Y& N) f- N/ C1 H( n" a%>
' w0 g! s: E- Q<script language='javascript'>  f% ~% J0 s7 I% L2 l0 |; e$ @
arr = new array();. \6 v5 x. R0 r/ @+ R1 a
<%  int temp=0;+ c! u! c7 k$ ~" L9 e& [& x9 A
while(rs.next())
& P5 u" `, K, }% x- x( E{1 E- i* U. w- U. h/ b  E0 ]
%>
7 j, {! Z2 D+ narr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");; {, D) a. g  p% A+ Y2 {' D3 q
<%
& I& X: `* f! @$ n# Qtemp = temp + 1;0 r7 [1 u+ \4 J( l* I3 N( R5 f! [+ k
}
  w5 C9 l0 A6 o5 G2 R* t0 C%>8 e  e) r: L- q! V* B. M4 E$ V
temp=<%=temp%>;
4 q2 e8 X+ F9 K7 |- g) Y. r; Zfunction changelocation(id){
( |8 I5 ], H( \# X& [9 y5 x2 Ndocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
7 z( @( M' P! i# j2 tvar i = 0;
# F% ?: H$ [5 q$ s/ {$ udocument.combo_box.city.options[0]=new option('-------','');
4 @2 }  v  q$ T' D3 Kfor(i=0;i<temp;i++){
/ C5 @& f3 x3 W! dif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
  U; }2 a5 s! G5 B* udocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 7 l9 M! s. I" K. q! r
} 0 [' B% q, }8 m! O4 t" r
}
- v" g, {! f/ s+ S& z2 }+ _1 |. G}
, W9 z+ P! {4 g4 g* |% O</script>
3 J7 O, D9 s) v1 X, Z$ G! }
: m! H/ B- `% @* \) s% S; y<form name="combo_box">, X# y' j; K+ U' W/ `
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">% W/ I' X) Q# q
  <tr height="24">1 ^/ C! p" D7 `) F% y' l
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
) W: y3 P- m7 f* Q7 D$ W    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>8 s/ S9 V7 V& N( N) t0 u* G+ B6 ~
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
6 }3 z7 o7 W) \. T) b1 e. W4 D    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
0 L) }0 g3 |# Y! h2 C  </tr>/ F  l9 o. v+ ?/ \% b& C. `
  <tr>
  r% n) H8 R$ m+ v$ E3 W    <td>
6 E. _" w3 \/ N: Y5 W  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">$ L4 n, \3 z. `& S7 w- n( X
  <option value="0">请选择部门 ---></option>" R. d% O2 y3 c# U( a- L9 _. p
<%
5 Y! h( [9 N3 r3 T    string sqld="select * from tdept";! w; M( c) k. ^8 \6 m0 g
stmt=conn.createstatement();
2 ^2 l( l  w- Ors=stmt.executequery(sqld);& q7 u2 y% U, S- s5 |
while(rs.next())- q1 c+ T+ l+ i% E* T. Y
{
% E5 H& r4 M  t0 q3 F% t+ A%>' j& ~1 ~; o( }% @) K4 ~. I) m
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>3 P0 R1 B7 g4 [
<%
0 m! \4 m5 m# k; W; D}
# i' _' X* w# @& A1 f& \%>
8 k' S8 d' o+ S0 ~- D5 f& m; u  </select>7 c$ h! Z5 g; q3 m8 |- J& [8 {
</td>& s7 R: r8 K' w  z0 t7 Q; j% }
    <td>
: i- ?0 S1 m# G6 f  <select multiple id=city style="width:150;height:200" class="bgc">0 q2 N& J# ~5 V1 \* p
  </select>
! S# N3 b: X3 p( p0 z2 d: N</td>
; @- a1 |6 u. y1 e9 p5 E8 K    <td nowrap align="center" class="bgc">
5 d4 _9 I$ L9 ?6 m& _! s5 B. U  <input type="button"  value="<<" class="buttons">
. b1 W6 Y' {9 c' a, E2 `  <input type="button"  value=">>" class="buttons">
7 {# c' Q2 y! @) e( O1 k</td>
# w7 ^3 D3 H, F. a5 R& g    <td>7 {# Z: Y0 [* L7 N
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">5 h, z; q1 Q, s& c* L( F
  </select>
: F' ^3 E& V, K1 g2 b</td>- t! w& S  }' H, T7 i- E
  </tr>
" q7 Z; y8 Z2 K6 P4 O' W    <tr class="bgc">
0 I* @$ M6 Z& L+ }" D: Q    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>8 H! ~2 E6 F9 D) `$ d8 S
  </tr>
- J! n4 f7 c/ |  D- u</table>: n0 M% ?; |2 J0 g8 T
</form>6 I" O! Y; Q5 g9 l5 O+ j; l6 h
<script language="javascript">
3 o7 e% a) L. ^8 G0 [//人名移动
7 d: I1 e5 X8 F# Gfunction move(fbox, tbox) {
6 s9 m) e$ `% h3 i' tvar arrfbox = new array();6 f" [# o8 P; Z2 W5 E; [, Q
var arrtbox = new array();
  k; `5 k- _$ H. z# Ovar arrlookup = new array();) D2 ~8 [! [2 n3 B# h' ]5 x2 M
var i;3 H% z% N/ W) d2 b  V, F6 V
for (i = 0; i < tbox.options.length; i++) {
* |/ G( o7 B  V: R  [/ D& j6 qarrlookup[tbox.options.text] = tbox.options.value;0 J4 U- u* [- a6 q
arrtbox = tbox.options.text;
3 v: X' V  G( t8 q: q}& J' E% z  |) g" r. P% T
var flength = 0;) i5 m; n: w4 f/ ^. X/ P4 q3 a6 A
var tlength = arrtbox.length;
$ r9 c; n- N! u* o1 k4 vfor(i = 0; i < fbox.options.length; i++) {6 J+ e, j$ }  N) U9 ]2 ]
arrlookup[fbox.options.text] = fbox.options.value;
2 P- `, o, ^( x2 Z. V" k2 h1 k# F0 zif (fbox.options.selected && fbox.options.value != "") {% Q- `$ X8 l, G5 d, s: `
arrtbox[tlength] = fbox.options.text;/ |. I3 |  M( K+ s, a/ C
tlength++;* ]4 o: w+ S1 j# H; f) Y- q
}0 f2 m/ U+ `" ^8 c8 n- P- ?
else {  i  ]5 u) K8 d1 H. S. d
arrfbox[flength] = fbox.options.text;0 ^! X6 ^* n; {+ }$ h5 b
flength++;( V1 j# D5 n- ~6 f- B
   }
, w! @1 T; L' ~' k: b" q}
4 _8 r! _5 R% D  c7 m" B' ?arrfbox.sort();
3 M  D9 Z# `7 d: K% Aarrtbox.sort();8 j4 U1 s' o( ^: W# ^! |7 S
  F. |1 B6 K% c4 q1 L4 e+ {: `
fbox.length = 0;
& w) X% X7 }4 B' [0 |tbox.length = 0;
+ w9 q' G5 ^* j& w1 V' \" Yvar c;- u# s3 e0 C# J. g. e" g  J
for(c = 0; c < arrfbox.length; c++) {4 U* U- R+ v( {# C, b
var no = new option();
4 r  l- t  o) h  E' b6 _no.value = arrlookup[arrfbox[c]];
# C6 O% T* o" [! m. Lno.text = arrfbox[c];
6 r7 v( [3 M2 q5 K/ e; Dfbox[c] = no;
; m1 D( u1 u0 W* J- }2 B}- R+ _& c' B# h
for(c = 0; c < arrtbox.length; c++) {, T; I; Q1 U! c7 K
var no = new option();
2 r2 _( j/ v6 L  l$ ]2 |no.value = arrlookup[arrtbox[c]];2 r: u( g: d+ c
no.text = arrtbox[c];7 s$ j0 D3 w9 m- N
tbox[c] = no;9 P$ L0 x! I8 n* v1 O
   }& L& v5 x5 L1 R% ]& Q
}
% [( T( J9 C! l/ x, P</script>
6 D' S' M- O7 P5 a2 |, `</body>
# o1 E7 i  n/ ?8 F3 S' ]4 w

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