返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
1 H: D" F1 m7 F& e         c pageencoding="gb2312"; T9 j- C; L( }: R) f
%>" P( l( ^) d+ A4 S' u' A
<style>9 c) e- m5 G2 J6 a/ o( q2 R& P
.f9{ font-size:9pt; }1 p+ Q( H# T- w$ h; [& [
.bgc{ background-color:#aecaf9; color: #0033ff }: [( b8 K9 w  U- ]
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;$ o+ w2 T2 j$ j/ G+ i
  border-bottom: solid 1px #4e7dc1;
3 ~1 Z8 t. o9 ?' W: q  border-left: solid 1px #aecaf9;
( T0 [; [" ?" k' b  border-right: solid 1px #5679bd;
$ B6 l  t$ F. m$ C8 ]  padding:1px;
$ [! y0 i+ r  m  margin:0px;}
" Z1 ?6 X7 r; Z</style>0 o( P, [7 m/ N' G2 G  ~
<script language="javascript"># E4 P) K. p. C' H% r9 g. \) E
<!--
, O3 q: f7 l( q: sfunction rv()
6 |; s; N1 o6 l- M{- `) t; ^. j& f% _* n) R8 ~
  var val="";
- n# O$ q9 a  {/ ?1 A  j  for(i=0;i<combo_box.list2.length;i++){% P; _6 w8 b: u$ h( H' N
   val+=","+combo_box.list2.value;) m  [/ R# Q/ d8 k7 o! j, T% u
  }0 B4 N- z9 f1 ?5 z
  if(val.charat(0)==","){
- V% M; Y( {; U# _3 R; V: p   val=val.substr(1,val.length);6 F) Y8 N5 b9 ]) d. I3 s# I
  }
- p* z: g1 t4 l) ?( ?6 q  opener.form1.frecname.value=val;
6 H  X- W$ y# Q* s$ t  self.close();
* h, M3 a5 o, i% l1 V}
& q" u+ I# S# _& j//-->; u6 L2 i* y3 ]; u, Y
</script>! z8 P1 P+ v' G( ~3 o& f
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
+ \  |% i7 z+ F# X/ l& w<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />2 C% ~  |) M" q% ~, W0 b! w8 x$ H7 k- m
<%
6 W% l* y: ]7 Z# s( P) [  cdatasource ds=new cdatasource();  //数据联结bean实例
5 k  V% k8 t+ b/ b  java.sql.connection conn=ds.getconnection();
/ R- a3 G$ c, `  java.sql.statement stmt=null;
2 ?$ }1 w9 C; E  K$ |. @* Y0 D  E/ T  java.sql.resultset rs=null;5 C# w+ x" O3 Z# W
  cdatacheck dc=new cdatacheck();+ k- r" D7 \2 l, [4 N- d% J  @
%>( e) c/ y& U7 `9 y
<%
0 v! F& [! q8 i+ xstring 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";: y/ y+ S$ ~! L8 E2 a
stmt=conn.createstatement();
" p/ @, x2 l. y/ b% hrs=stmt.executequery(sqlu);
- l, T! W( f5 c* |* s& S) j%>
( m2 H1 i' \# @<script language='javascript'>3 D' @  T9 `* G
arr = new array();: e( v6 w* [7 Y
<%  int temp=0;0 O* i- ?( y  O$ A. f) @. E1 B' D
while(rs.next())
/ u2 _  `& q* a4 F{
6 N3 S& h/ V9 U%>
% A/ N; A( F9 V% y7 ]' s1 @% n9 N1 qarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
7 c9 r% z, V' d5 b<%8 D1 ?* s5 T6 c7 W: N$ j
temp = temp + 1;
% A2 G" v9 [3 G; m" L$ v) N}/ [2 O" v' ^; H' |3 y3 Y5 Z4 k: F
%>
+ j8 e. C" q% m3 V  ttemp=<%=temp%>;9 }* `# f: D# N8 b
function changelocation(id){
) Y4 w! `- G  ]6 a6 v' bdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
4 H! T0 o7 s9 Xvar i = 0;
: q. _7 M: i, m2 [: idocument.combo_box.city.options[0]=new option('-------',''); / F& _: W& {- U
for(i=0;i<temp;i++){
) L7 D: O; n9 B; p4 n) @. kif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
+ c& b1 ]8 I* l, G! q1 `document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); - i9 [4 P# W2 V
}
5 F' M# \8 ?1 k4 H" X3 C} ! I4 K( L) w0 Z  J* `2 N
}
9 o* q7 T, s5 E/ [  q</script>. q# U1 e+ n% B- \4 s5 M. [+ i

( i4 h( u# J! }0 s; U2 g- n0 i. j<form name="combo_box">
" }) p: M& ^* o3 E$ V* M<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
2 k5 H: t$ ^. ~, M0 u+ K0 M; ]* `  <tr height="24">1 b& o2 q8 p4 x# j
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
) r* |" A* e4 W* G) b+ w    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>; j2 n3 {, J, p# O3 B. N5 b
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
2 q4 q1 a6 ?2 z; U* v% B  B    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
7 O; ]: @8 ~& z8 z1 ~: z  </tr>
: U# d$ K3 Q$ f8 a  {# E) k, f4 V- A  <tr>
" g  u' p  h+ T    <td>6 C' [% T% D% h' i- A
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
  g- @- P) K' [  <option value="0">请选择部门 ---></option>; A( H9 i6 p2 a) g
<%
: Y2 ~5 \1 b+ p2 R    string sqld="select * from tdept";. t% k9 x1 g9 X
stmt=conn.createstatement();
3 Z$ z* r8 q; B1 `1 {  Yrs=stmt.executequery(sqld);
; ^# Z0 V: A6 l7 M. T5 q; _4 qwhile(rs.next())
3 Y3 D" B0 w( B* h' C/ z* Q{* Q0 E' J/ ?: p! _" Y4 X' O5 S
%>% B1 g, ^: V6 c& ]2 V+ n& C
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>: @& @% d5 [; T3 g2 T
<%
+ u% Y, e  D4 t, @}+ T7 q2 I& I, o; o2 |
%> ( ^1 C" @& n  |# A$ q& a3 a
  </select>
5 A9 X6 ?0 i1 C: E* G</td>: Q/ G% E2 K. s) U9 l# z
    <td>
1 U! J+ ^3 l/ ?' c  <select multiple id=city style="width:150;height:200" class="bgc">
# q6 C2 e9 Q9 q% `  </select>
8 v  v3 P5 b2 I! X8 J8 y; A</td>
* H5 c7 r, `& X# f3 j4 R    <td nowrap align="center" class="bgc">
2 A( J* U3 Y: O# q  <input type="button"  value="<<" class="buttons">/ S- V- w% Y% c. m
  <input type="button"  value=">>" class="buttons">
# y6 C# J& u# s! z: X+ _# s</td>! V4 j/ ^2 }) H# [5 b. P
    <td>0 m. B; |; r! C* a
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">! \, u: R% ?' ]& ?/ y4 h
  </select>
' P( ~4 W, p# p" m/ T5 b. G</td>
4 n/ |4 \& r& N  </tr>* z4 Q/ @/ F# n! b
    <tr class="bgc">
$ l. Z; s( H1 h3 \, K; ^7 F' G    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>- K% r' _) ^6 v. W5 {/ [' P
  </tr>
5 m$ G& K% k  h4 M8 Z' V, o, R- F: n</table>
8 S$ L! ]3 X  o</form>
" m( ?+ t: T& |8 X# X* V: e<script language="javascript">, b6 s" S( `. s: k
//人名移动! g: |2 G2 |1 J" @9 k
function move(fbox, tbox) {) m: ]' m$ D/ O
var arrfbox = new array();& r0 a- D  |$ r6 R. q5 |) @) h
var arrtbox = new array();
: B( W0 E4 e1 Lvar arrlookup = new array();
8 G4 I2 u: ]7 t% S* {! W+ x+ Vvar i;" l5 c9 L0 F* }, n* Y
for (i = 0; i < tbox.options.length; i++) {
" F5 a+ b: u1 h/ barrlookup[tbox.options.text] = tbox.options.value;
; z5 R- X8 c7 E$ e0 r9 \; marrtbox = tbox.options.text;; v3 |2 Y. @6 y# L3 V
}5 n. C) d( f$ w8 S7 c& Z
var flength = 0;
" }0 O2 X( Q) svar tlength = arrtbox.length;; R. H, e# g4 h8 w$ m3 _. p
for(i = 0; i < fbox.options.length; i++) {
, e$ q6 ^" ]0 T: u4 q' D9 E4 p- jarrlookup[fbox.options.text] = fbox.options.value;
* a: G# H& C# {) N8 @$ |if (fbox.options.selected && fbox.options.value != "") {
4 B+ E: ~7 \3 y6 z6 r+ Varrtbox[tlength] = fbox.options.text;* }0 P& |, |; r% e8 V1 Q% o
tlength++;
* L# n# F1 P. r$ C}
( l$ O. s$ a3 p; o  e" ?6 S5 M+ Eelse {
! U. |! u! o/ Y; T* [7 H3 l% a( {arrfbox[flength] = fbox.options.text;1 r7 w' A+ R/ s, l" e, u
flength++;7 j  H! \2 @6 s
   }
) L* a! C! L# b, Z/ t}* p; G3 F" s4 w! I  c" X
arrfbox.sort();
% v! a; f( x7 {% W, f: |# z# [arrtbox.sort();
4 C% I+ c8 E. @4 k
# {1 f5 A6 [; v2 w1 v0 Hfbox.length = 0;6 ^0 P" u$ h) V: o, n
tbox.length = 0;. z3 ^- m+ D- g- o* b! L
var c;5 n- n3 A5 o- \3 X  n! O' E
for(c = 0; c < arrfbox.length; c++) {
* v) q: r' T. q9 E. `- c) e5 ivar no = new option();! Y& g) _% D/ Q. H+ ]
no.value = arrlookup[arrfbox[c]];) ?1 d" }8 V6 e' s8 Q
no.text = arrfbox[c];
+ L# u( y8 c5 }fbox[c] = no;
; k% q" t, A0 x! N9 S8 ^  k3 k}
; P1 P% c, ]$ ]6 e8 f6 ifor(c = 0; c < arrtbox.length; c++) {/ q* d" M/ I# A4 k% o) f3 K, `
var no = new option();
7 G9 N5 F( ]/ q) O0 Vno.value = arrlookup[arrtbox[c]];$ g, t4 d, F( E- E
no.text = arrtbox[c];) ^* e  ~5 P/ k* Y1 l, f/ D. A
tbox[c] = no;
* f& o& H, _- h4 C# o2 _# S   }
4 g' A: l7 A" t7 G5 M}
* @" h9 Z9 C. @5 O% H  t, X</script>5 \0 f7 E% X4 R: ?$ Y2 R0 [
</body>
9 R' N+ W; k6 w/ r/ Z& @

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