返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
! `) e- G/ V# _& }         c pageencoding="gb2312"
& \, @( F, [* \4 O) R# ?%>$ D  X* l) Y1 s4 h: s+ N& n
<style>- J  |3 v: w; O- }
.f9{ font-size:9pt; }3 D- q8 I* ?' o! d$ W1 f
.bgc{ background-color:#aecaf9; color: #0033ff }
. n$ e% z7 ~( t.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
+ _4 N/ C7 f- A$ U: I* x' Z/ u  border-bottom: solid 1px #4e7dc1;7 }0 t4 L4 j) C" ]: l% D5 f- f
  border-left: solid 1px #aecaf9;  l  J) U) y3 L
  border-right: solid 1px #5679bd;
8 m% t+ R9 S1 @+ U; b. m, [, [# F  padding:1px;; ^! B! Y8 E! t" o$ `4 g/ h
  margin:0px;}
0 u: L, f2 u' p& c8 P8 w</style>) E* G6 h: T. n8 ~- a' V5 N9 w! I
<script language="javascript">3 [- D' l  D: r; g" E/ B3 Q- k+ p
<!--. J! O9 g) V/ L& l7 _9 e! j6 ]8 Y
function rv()
/ ~+ Z9 E9 ^- q2 G7 e{# T8 Z2 }3 M$ m$ k
  var val="";
3 Z8 k! m# A. f2 A, O# X  for(i=0;i<combo_box.list2.length;i++){/ _. w. d  t/ S- ^% b
   val+=","+combo_box.list2.value;
' @/ t, |1 V+ {- _& e+ g4 x  }6 I7 G1 W* M4 V- w
  if(val.charat(0)==","){
. `8 a4 l( f; E& Z8 j7 {) a4 v   val=val.substr(1,val.length);# P7 j$ G9 K4 p
  }
6 I' @' f8 U! Y5 u7 z  opener.form1.frecname.value=val;; P' f% o9 ?! q7 b* L: h5 r$ Y
  self.close();
+ f  _, s- {- D}2 \& [- y& N* |4 i  i+ n
//-->! S$ D: S& Z: c7 R. ?/ N6 `, w9 F
</script>7 `* [& z; N( t( O7 C% D9 I5 l
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">+ g( t, }) {7 _5 \$ J4 y4 [
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />& {; @  ~, I. n) b
<%
! A$ L6 e: c  S8 E  v) w; _1 {  cdatasource ds=new cdatasource();  //数据联结bean实例
4 r# `: L6 z" d0 x8 n3 a  java.sql.connection conn=ds.getconnection();
& g, j5 w( @( ?+ v, S  java.sql.statement stmt=null;# d  F! p$ ]3 l! h! X" _
  java.sql.resultset rs=null;3 o. N: K. ~- `9 j
  cdatacheck dc=new cdatacheck();/ }2 K1 M% i- ?3 U+ l
%>
; h+ R  w1 X* T8 N" l! o<%0 D6 c7 T7 x5 p1 g: h
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";
; R. B2 B9 s% c+ y7 k0 }- Z: Kstmt=conn.createstatement();
1 j7 J+ m$ V8 K3 J& e) c; L. l1 qrs=stmt.executequery(sqlu);
/ f( @, n; y! K( y! n5 i%>; l( C- W$ x0 L
<script language='javascript'>' C4 g9 c, z% n/ [9 L
arr = new array();
" Q/ M3 {" b7 s8 y$ q<%  int temp=0;
' y: ?' Z3 r9 }  e8 p" S6 ~while(rs.next())
% Y( c' X  ?+ A2 F, a( w4 v{
, f6 _+ H0 E  X1 K* E%>
3 O- B8 `4 t' Y  m2 Z/ F: E1 \arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
0 g! D8 Y" g4 U! f" H8 I<%$ [" X, h# t  ]9 f! Q' j
temp = temp + 1;# N) v, k( M% x0 A
}4 s9 r5 v1 a2 }. N4 W3 |3 \$ X. J
%>& L5 v' z9 g1 {. d% q* p3 m) d
temp=<%=temp%>;) `7 A' Z- R3 v, ^8 p( n
function changelocation(id){ ( V; A, [8 i# Z) _' v
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始   c4 ^3 I3 ~3 J( }
var i = 0;
6 o8 x1 ^( u) L' \6 }) K# ~document.combo_box.city.options[0]=new option('-------','');   f0 f% J8 ~( }" e
for(i=0;i<temp;i++){ # e) e( W0 q5 P# O/ h
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 3 m" X; E( k% ^
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
, r0 r, T5 l$ `9 ~2 j0 V* ], C}
* T6 x6 B9 ^& C2 H' {}
: Q9 t4 B( `4 z( E2 n' Z} 3 H0 M% R( P$ i; _% O% w2 S
</script>
1 ^5 g# O# A) G% K2 C' i9 ?- b( R. e& ?2 K
<form name="combo_box">
5 u! Q5 |" H' W7 v<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">: y7 l. {' G' C/ [: ]$ W6 A( W
  <tr height="24">% C! d6 d7 ]4 }7 a$ I
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>% r& x5 O1 o' U
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>. E  s/ \8 i: G6 K1 c! i3 T$ i8 {7 ]+ H
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
  _' o9 r2 I% f" P$ O6 H    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>% d( R$ T& M1 M$ f. K: m2 b# C
  </tr>$ Q! A; k; D1 r5 B7 Q
  <tr> 6 X1 L' l+ s/ ^
    <td>
0 w% f% M. ?, Y: `0 |  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
6 c$ a" a( }1 u- x1 m  <option value="0">请选择部门 ---></option>
2 I6 m6 A! \# _<%
; E3 X' c5 u. p+ N, |. A3 ~    string sqld="select * from tdept";
+ ?5 e( `% A: Y9 z# k0 h- Ustmt=conn.createstatement();7 \7 J0 W' a, U1 Y/ \
rs=stmt.executequery(sqld);
9 v) B+ Q* i. N* `# @0 C. hwhile(rs.next())
' [. n. O3 ~; s' r7 P{
6 I# G( U0 P9 K' T8 O5 p/ ?. o1 }%>+ ]! w4 ~& u  `+ P& Y" W
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
/ N/ M# R1 `; m) L<%( `0 Z5 v% I' y
}; A4 x( V# P0 `! M: `
%> ! z1 R" R7 @: B; d7 t) b
  </select>, u; a0 K- B% z. t  L" c5 f7 I
</td>  J8 y( A3 A1 Y* M+ M& i
    <td>
7 A6 o, I& u5 d+ C  <select multiple id=city style="width:150;height:200" class="bgc">' U2 z  s# K, f5 R, J% N4 r( l0 h
  </select>0 ?/ x% @& i. y* t
</td>. b5 Y' c# C- k6 ?0 p
    <td nowrap align="center" class="bgc">  K2 z) q, v" a: r
  <input type="button"  value="<<" class="buttons">
; ~0 w7 m, `- B' b  <input type="button"  value=">>" class="buttons">
. y5 g' B2 b1 s9 w5 I) c; B: r( B</td>  r6 E- z- N& M$ L1 U$ V' D3 f
    <td>5 ?& t6 |0 a0 u: U* q1 z- b  B
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">7 L* M4 F1 `) \; c! F1 D# F& U
  </select>
9 f" J) S1 \9 Y- a$ z9 S( Q5 ]</td>7 b% t- [. t  G+ M0 b' b  f; D3 ?
  </tr>) e3 q' J& o$ [& n# E% W
    <tr class="bgc"> 5 {5 a: p4 y3 d
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
, e: ]& T8 E+ ~& B7 H  </tr>
& j( _! L2 X& R$ u  D</table>1 X2 a8 x. d, \1 G2 l7 C- o
</form>
/ Y- r) _( B/ E# X7 \; G<script language="javascript">
$ c! i8 d6 Q: q//人名移动- p- [4 Q0 H$ X! X% ^. c* y# d
function move(fbox, tbox) {
+ l9 m% m& r& t4 ~9 ^2 F0 t9 dvar arrfbox = new array();
' K9 a# b' n0 J/ q3 u$ Z4 |  Vvar arrtbox = new array();& h% n6 O+ _( _9 H3 @
var arrlookup = new array();
& e1 n3 W4 v2 }* G7 ?7 ]var i;' C: g! b$ l6 g+ q$ c, V
for (i = 0; i < tbox.options.length; i++) {
' \, e, y) I5 x$ k8 o% l. Aarrlookup[tbox.options.text] = tbox.options.value;
6 M& R, W1 C; p8 `6 T0 @arrtbox = tbox.options.text;# ?% N/ Y5 K- _! ~7 L
}
" C% c4 S7 X  k! P) _  Rvar flength = 0;
' ^$ w- O/ f/ G1 Dvar tlength = arrtbox.length;/ K  p% ?0 b0 V- l$ x
for(i = 0; i < fbox.options.length; i++) {3 A  w1 `( y8 Y$ d5 h& t
arrlookup[fbox.options.text] = fbox.options.value;) }( W% x6 @# [6 y
if (fbox.options.selected && fbox.options.value != "") {5 H% v1 S% y4 ?0 q" _" z1 g( v
arrtbox[tlength] = fbox.options.text;3 N) j8 ]) k8 t* |7 N& h
tlength++;7 N2 {8 V, }1 V) p7 d6 i
}
3 S: [# E+ v  c* R  V9 Selse {6 ?" u& E4 W5 x0 w: ?
arrfbox[flength] = fbox.options.text;
: h  ^( s6 m; ?6 l' Cflength++;1 ^+ T# M% k- i5 _- H# d
   }# O3 S4 C% T, V) B& H
}- l9 l: A5 V* M7 F0 v' q" @7 x
arrfbox.sort();# b* G  M( v1 k2 B. W3 ?
arrtbox.sort();$ o0 G8 h% Z2 I8 J* D

' ~+ f0 L7 n- _5 f8 ]+ c" Hfbox.length = 0;
" b0 p( E2 I$ |+ C& itbox.length = 0;
1 k. {  A' }+ O. C  U. c* Cvar c;
* }! I' b/ U& I" ufor(c = 0; c < arrfbox.length; c++) {
# R7 r% s4 b! }2 ^; z- Z$ c, L) ovar no = new option();
/ j$ h5 x8 [0 _' Jno.value = arrlookup[arrfbox[c]];* {4 ?+ E9 y% E
no.text = arrfbox[c];5 D& o# ~8 z" s3 Z9 S
fbox[c] = no;* [% W7 f! S/ V) L: P, q0 z. D) |8 j
}- q) |: u4 Y  j3 _" q3 F
for(c = 0; c < arrtbox.length; c++) {7 ~, \( s* J. u. {
var no = new option();8 ]! L$ O4 S7 b9 y! y
no.value = arrlookup[arrtbox[c]];
' G2 m5 E& t6 b' L% pno.text = arrtbox[c];
3 P, {# Y% h7 t) C7 }; d$ Vtbox[c] = no;) G' K" M# q  Y" ?3 x
   }
& k+ P2 c! s4 n/ ^}
9 T. P- k0 v9 s7 }8 ]- U7 M$ z</script>4 Y! p: W6 ^; w! z. X: }3 i2 J
</body>
3 _) k, Y. n1 w5 c& _. s$ h

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