返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"4 K% g4 C- i  J% {9 t) M9 ~
         c pageencoding="gb2312". J3 L/ D4 h# D4 I3 n. _. Q5 `
%>
5 a9 @' e3 C/ L$ X8 c  S<style>
9 b4 g; z) A- j; L  D- H3 F: ?.f9{ font-size:9pt; }' ]* ]4 p+ X. P8 a* j4 m0 X
.bgc{ background-color:#aecaf9; color: #0033ff }
# {" y8 K) J2 @% V3 c8 x0 f.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;3 M* Y. Y$ \: m7 {+ ]6 ?2 V4 z$ V
  border-bottom: solid 1px #4e7dc1;
. G* M5 t# y) L* g  border-left: solid 1px #aecaf9;
5 S1 t. T) E  E  border-right: solid 1px #5679bd;3 O$ x% {( [5 n$ h: o; z
  padding:1px;! s4 k+ \. \9 N5 h: J3 }
  margin:0px;}
2 z9 J" x  b( o5 Z$ W</style>
$ j' Z% w$ Z1 @% W* e3 p<script language="javascript">
+ l2 p( J# J3 C/ _, S4 [% J/ z; j$ b5 J4 j' n<!--; |1 B4 ~; C: x  A3 f; ?8 D
function rv()
" J0 x( U  k  g( F, E! G# _/ A. I; u# S{, X- n9 u7 }+ a
  var val="";
. b+ ?% j( v/ J  j0 O8 L. ^  for(i=0;i<combo_box.list2.length;i++){, ?9 n" I. O8 q9 y9 [" q
   val+=","+combo_box.list2.value;8 k) r% Y0 O- g. N
  }5 W9 p0 c1 v# y* w
  if(val.charat(0)==","){
  M" X2 s! ~2 I   val=val.substr(1,val.length);, g: [  O4 l0 H+ a4 ^
  }4 H- V6 m3 p' h) ?/ I4 n* A. X
  opener.form1.frecname.value=val;
) V7 k( S" ~& \% x  self.close();- u# w$ i% B' O' z6 K
}* O7 E" ]- v. l) O( n
//-->0 l9 r( d- `" t) Q
</script>
2 V; m9 I2 G) ~- W" b9 R<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">8 P$ _5 o, X4 K- n+ L& `
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />: Z! J; @- O% U3 J
<%7 D8 \" V7 W6 |7 H
  cdatasource ds=new cdatasource();  //数据联结bean实例
8 c5 ]* {9 F" E) m4 @( }  l6 G  java.sql.connection conn=ds.getconnection();3 ~: z3 {3 ?6 K1 v. W) Q
  java.sql.statement stmt=null;
4 c0 s8 x# ~" m. Z  W+ [7 h  java.sql.resultset rs=null;
7 D0 Q$ Y6 N0 S) B% x5 m( R  cdatacheck dc=new cdatacheck();& a' h* \2 S" w
%>
3 m- _6 e. U- \1 `5 c<%/ |6 y6 ]- B- l% ]4 V
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";
; f) ~/ V7 x' Q9 bstmt=conn.createstatement();
& B( v# k2 W. E7 c: H6 Urs=stmt.executequery(sqlu);  y& M4 D8 u' y& W
%>
5 L7 s" t7 A. O' ]! Y7 A  v3 E' S<script language='javascript'>! t/ [6 z+ }/ M5 ^: ~" w4 G
arr = new array();
7 t! N  i! G( c( K  d/ p  N<%  int temp=0;
2 y; `+ D2 k2 B! m, Vwhile(rs.next())
5 R* M6 z6 Q6 m1 k{/ `- {4 p7 i7 h/ K
%>
3 L3 G! n% L: L- rarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");% E9 g& n/ _+ R, x- ^- b
<%
- P1 E8 @8 O: v9 T* R5 O5 P. Itemp = temp + 1;
0 ~( c' f$ l: ?3 p1 G- R3 _5 w}
2 g( j  d; k" k3 b0 F+ j%>
" A+ D! S* {- ^temp=<%=temp%>;& P2 o5 `  h* F6 G* D2 L
function changelocation(id){
* s+ M/ \7 m% _document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
' q! {! O# d4 ^6 [% S$ Yvar i = 0; 7 y0 n; q! L( b
document.combo_box.city.options[0]=new option('-------','');
" i" E0 d' B8 {  z- I4 Wfor(i=0;i<temp;i++){ 2 r, i6 Y: T; C( x0 d2 T, k
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] # F2 ~& l* a  i9 b& J
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
$ f* ]% e! Q0 u2 I$ _& a} % C' U/ K0 p% L9 H8 z" }" ]
}   }! w' S, L7 _8 b4 E; x
} + @. ^% W) ^4 u/ h; q
</script>
, C- V8 E/ g1 n! e+ E' n7 E2 Q/ A' z: ?8 W4 q5 ]: p0 E9 x
<form name="combo_box">
3 g& \# u" E, r<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
4 f( u& R" ~6 d- r1 _& j4 M3 f+ e  <tr height="24">9 e. l$ [" L" V
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>, ~0 z4 b, Z& \7 H' R* s
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>& K, {. s% z! `# ~; I6 T
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
2 U7 `8 r$ E* k, g, U    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>: H- E4 @/ ^1 X' n
  </tr>3 G  G' ^. R7 d/ F
  <tr>
! g/ n0 |" D# y    <td>
% I, [" L& t; v3 W0 `: ]2 q  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">, u8 L+ I; s: I7 P2 r
  <option value="0">请选择部门 ---></option>
7 K( T) M3 y8 q<%/ {  u4 `0 H2 C0 R* Z
    string sqld="select * from tdept";
) w3 i; b8 {( ]7 C0 E' |stmt=conn.createstatement();
" K8 q" V# r) Y0 K: {  qrs=stmt.executequery(sqld);2 X: i# Y: m4 i3 W* q: t
while(rs.next())
3 v% J% u$ {% X( M3 p{
, ?% A9 }2 ~( ?%>  O- \- S: ^$ j$ U0 o3 f
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>2 A- N7 j' N' c5 h9 @8 x5 n
<%
# j/ y' z( w6 A}2 v% ?% F" m5 U4 R+ T) n
%> # m1 Q" N+ l; y; o9 \/ K
  </select>
/ A( ~+ R% _( g! ^</td>8 O, x- V0 G% e/ T6 l3 U& ~" j
    <td>
' d9 N0 L4 G0 N! B/ w: [  <select multiple id=city style="width:150;height:200" class="bgc">
+ J; n; V  K" z" k  </select>
& F6 \0 t3 c) T% {/ E</td>0 T( ^# F$ e& S5 ^3 S
    <td nowrap align="center" class="bgc">
- o, p1 l, w* U, v! q! V! ~  <input type="button"  value="<<" class="buttons">
: e' z$ \: L1 X  <input type="button"  value=">>" class="buttons">
. j5 O0 k# z( I6 C# a</td>9 B, p/ z. O  P
    <td>
4 M- Z3 G4 n# T$ J) l' s' i' r  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">) J1 }  p/ f+ Z% Y
  </select>2 J' R- ^0 d% h7 \. W; N
</td>
# L/ \8 }2 w; e+ ^, H3 f  </tr>! x- S- m4 r4 G* H5 D- L# K' r4 ]
    <tr class="bgc">
3 @( j5 f; m0 a* l! K0 K    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
( k' [1 [2 q: k  </tr>9 R0 ]8 e+ }& v5 {  f  A
</table>
5 l8 P2 o/ g' N2 H* p</form>
4 L$ `9 F; ]+ }' f9 R3 ]<script language="javascript">2 p$ n$ F- N1 [# T( h
//人名移动
- b+ |0 j% z5 H& Pfunction move(fbox, tbox) {
4 M  ?' Z9 ?  h4 A: ?4 r0 bvar arrfbox = new array();
; |$ n5 \3 n: p2 g# jvar arrtbox = new array();9 f; F/ ?; V$ [
var arrlookup = new array();
: @6 r. a8 w8 \) pvar i;
- C% Q0 ]1 a& v5 `for (i = 0; i < tbox.options.length; i++) {8 S# E$ S& w& x2 V6 |
arrlookup[tbox.options.text] = tbox.options.value;" y" f5 q8 h3 y  n4 H# f( H0 [
arrtbox = tbox.options.text;- l' r- S4 q5 b+ c- E0 L( N5 k1 ^
}
: ]5 y( ~! W1 u. C5 F1 D  `var flength = 0;& z0 @- q/ F  @
var tlength = arrtbox.length;6 l" Q! J1 X+ J( E
for(i = 0; i < fbox.options.length; i++) {
8 o7 n6 d; V- i& S! A4 w. iarrlookup[fbox.options.text] = fbox.options.value;
# j2 M" e6 x- _& T3 r% c7 D0 ^' ?if (fbox.options.selected && fbox.options.value != "") {
7 ?2 M- j% V; k4 H  f2 }+ `arrtbox[tlength] = fbox.options.text;
* O# |: f# u# B& G; k$ E. K* Atlength++;
5 G* \8 `( Y$ N; d( `}
' |4 n- a( r3 k6 ^5 Welse {# Y5 L1 a8 }: M) H. k4 G) l: I
arrfbox[flength] = fbox.options.text;
; y" i% d5 [5 j  |4 ^! @' I8 Mflength++;
2 p; v6 N$ G0 x  }+ f- _   }: c& m0 Y8 e8 |, G( Q
}
' U( \) d2 ]% ?4 r. g2 karrfbox.sort();
4 h$ H0 e: Y0 o1 l3 barrtbox.sort();
. h5 y  c# O7 B" ^' z5 v: U% F! n; n6 \2 }6 }/ _, ~
fbox.length = 0;8 q  l. ~% R( w4 }, h
tbox.length = 0;
) y# s0 f+ v  U3 Q2 h( k! qvar c;) K3 Q& v8 l% F) K) U% j4 a" D
for(c = 0; c < arrfbox.length; c++) {
1 Q9 F' Y  l# O. cvar no = new option();! y' r" ?# S: b
no.value = arrlookup[arrfbox[c]];
) r% B$ o& @% d6 X. W8 t# X3 o; t) {1 Lno.text = arrfbox[c];
' A2 p8 j/ `6 rfbox[c] = no;
& i7 q3 k6 ?+ q) `. c}& c* m% ^* |( @
for(c = 0; c < arrtbox.length; c++) {
( D$ M" T8 l2 y) n0 X9 T9 A) Xvar no = new option();2 ?  z8 `1 {- l1 u. [6 E
no.value = arrlookup[arrtbox[c]];
0 K" K8 C6 e9 Z1 _$ k/ U, @# qno.text = arrtbox[c];
# L: _; E3 Y- w* g; `) Ntbox[c] = no;
2 _: P! Y5 O" K% ~: K, n   }
+ r7 q/ B' |! ~' [}
1 ?7 z  ~( Q5 F4 [8 D2 f0 v</script>
5 v& E0 e1 k( X5 Y</body>/ l8 M  F" F) C& ~

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