返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
% S  t% f. J* A) G3 J$ u& U3 r         c pageencoding="gb2312"
. z8 ~4 T- }- [4 ]! M2 ^%>
( _( a+ P+ |! w# @: m<style>3 s# \; u9 R7 a. B4 G  e4 V  F1 J
.f9{ font-size:9pt; }# u" E% h. g; Y- B
.bgc{ background-color:#aecaf9; color: #0033ff }2 |  o/ g) W& v* j- \- H
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;# G  D: p; `! L' F
  border-bottom: solid 1px #4e7dc1;
( R$ F% i6 V) W- Q' o4 |0 x  border-left: solid 1px #aecaf9;
- k6 d. F) ~8 S% g- B  border-right: solid 1px #5679bd;
4 X% b( I7 e/ N5 A" o# v5 j% X  padding:1px;7 z. a: M/ V' a' D: ]* L
  margin:0px;}
6 t6 \& }+ H+ t4 V; J</style>
1 u/ D" U) U# c; n$ q<script language="javascript">
; X8 j9 x( K  t5 g% i<!--$ p6 h6 J7 R  b- h
function rv()
9 ~% E) Y. v3 p- T( Q{/ u! Q. \; Z9 J' M# j0 F
  var val="";
9 i+ H6 O  e9 A( A6 k  for(i=0;i<combo_box.list2.length;i++){
+ D3 E% K# r; v   val+=","+combo_box.list2.value;
) E4 S: v9 \& Y  }5 z+ A# N( w; F5 W$ x1 a, ^8 Y
  if(val.charat(0)==","){
! C- H) ]& y: ?9 Q   val=val.substr(1,val.length);
. U& V( E' v# r. r8 Z  }
: R$ w0 }' ~- _6 c4 i  opener.form1.frecname.value=val;
5 h, e" h  V* V  self.close();
6 o4 ~/ z- Q: W9 f! H}
) A" x/ e& b5 \5 d2 Y5 E//-->
5 x3 J( ^$ `# b1 g$ n$ `</script>
, X/ u: i% t0 b6 y. N; T- E<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
5 v# x9 _) M8 |<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />! M/ l# h7 ]( h1 A3 j0 f
<%
9 c" G7 ^7 y- q$ s. N, t' L( X- `& D  cdatasource ds=new cdatasource();  //数据联结bean实例& s9 C$ X" ]$ {
  java.sql.connection conn=ds.getconnection();
- y9 ~) ~) D4 O; U  java.sql.statement stmt=null;
$ O4 l" W8 d; y2 O' U  java.sql.resultset rs=null;
# \. B3 n4 u, R* w$ u4 ^! j% W  cdatacheck dc=new cdatacheck();
  N' ~: T) w) k5 p9 W6 ]8 g%>
: }) z' e+ ?; h& J<%+ ?6 a/ a# [4 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";
) i: S' m) Y1 B6 H/ Qstmt=conn.createstatement();2 n+ M3 o0 J/ h4 V( a0 r
rs=stmt.executequery(sqlu);5 Z! Q( y1 z/ h! D+ k. U6 A% n3 |
%>
* U# Q; |- {! h" h<script language='javascript'>! F" @1 n: ]- t" u+ O. V7 O/ Z
arr = new array();
, Z2 N# \. s) x/ u<%  int temp=0;
) j( a, l1 C! C, T8 t7 ]while(rs.next())0 X: ?+ R; J- T+ Y+ ~2 v0 [. h
{
! D& z5 P7 O( N% B) d%>+ _* n; v) p$ m% c; Z1 h
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
- S) A! |' z; ^' e% c& M: d<%" P, }/ n/ h! Y( i4 J& r4 @, _
temp = temp + 1;7 X0 w  u! C* N
}% J7 c5 J$ q2 r# g
%>
/ C! \1 K, g2 c& r7 h/ V  ctemp=<%=temp%>;
/ a( d% `4 ~0 U, Q) Y9 ?* Ifunction changelocation(id){ % d# x, J+ o# M; s/ Y
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
" \6 D+ L* ]) O! z: Dvar i = 0;
5 G3 G9 G. r6 f0 |( jdocument.combo_box.city.options[0]=new option('-------','');
, g6 ]# f: e" N4 I, j& U! mfor(i=0;i<temp;i++){ 0 o% j7 W+ S# h% ^% X# S
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
) G( u9 c" Z% X4 z3 e* p4 xdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
; |/ F7 C) _7 v! j" g# B}
% o/ j% _3 V' o6 @. l}
7 d% ^* \$ i9 E6 ~( `7 k} 5 t" u3 C, M$ @/ {- V( x1 Y& B
</script>- D- ]2 @; g  `4 h; @

; s& f$ g$ s+ n1 n9 f  F<form name="combo_box">& a& U, a4 d" E/ h0 v# H
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
  d( X3 b' r" t4 P  <tr height="24">' T4 W- x8 ]8 G- `# F5 C
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
: y: C+ r1 O7 U; b) H6 G    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>% J7 B9 Z" C6 m
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
: x1 x( f5 R% V% v2 ?# E1 n    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
/ m0 U1 K8 U0 d# ~% u  </tr>
- N* @; y! n$ D8 _- i  <tr>
; ]8 J# ~9 ^4 U* T! Z" I    <td>1 [6 W( ~3 U2 O) m7 S
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">, z. o% K' q" h2 r/ y  |$ U
  <option value="0">请选择部门 ---></option>
7 A8 Z: Y2 h7 B3 X7 W<%( E. f1 {8 O, e( ~& }1 d
    string sqld="select * from tdept";
7 {# w9 Y" F6 c( w1 Rstmt=conn.createstatement();1 q+ c1 B! {% k+ r) w; z3 `( m
rs=stmt.executequery(sqld);" M1 K; r! ~3 O7 L8 i
while(rs.next())
* d! \& e1 q6 z$ I8 |) b{
+ g( A, o+ d5 h$ r2 O; c/ d%>* E0 h# M% O5 J2 u4 S- F
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
# J% c6 O( M, L# V<%* r: G( r7 N! n) e( P% x
}5 A( {9 |8 }( U2 T0 \0 _0 M. L2 P
%> % y- C3 q. B( x+ {/ X+ ^6 v5 S
  </select>* e: I/ K' `3 L! V9 E$ L8 d
</td>
& d, D$ e9 v8 s( B8 t0 H4 ]3 u    <td># V$ F! u+ H- q4 w) [* p) g7 A
  <select multiple id=city style="width:150;height:200" class="bgc">& Y/ a5 }7 {# b
  </select>: F. {' r0 j2 [
</td>
  o9 A4 e1 B5 u, b    <td nowrap align="center" class="bgc">, {, L$ Z- A% ]# U; e: ?9 d
  <input type="button"  value="<<" class="buttons">
/ H; S: q% J& o' }3 |' e' ]  <input type="button"  value=">>" class="buttons">7 m' R, {% C( b
</td>
7 r  S! a% [8 X1 U3 ]    <td>( y: s% O3 y* L3 v1 ~, G4 k" c
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
* ^( v% b1 P! j% Z7 R  </select>' Q& _, [2 s9 K  c$ g
</td>
3 c0 L5 ]" K; }  </tr>
# A, e% C( s. h# i    <tr class="bgc">
% L2 Z& o% Q  k  k7 z: q    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
& t# ^" V0 ~/ T0 u  </tr>8 j/ w" ?# ~% y
</table>6 z9 C' h' Z' W( m9 k
</form>
& J# z$ A6 v& m1 T0 k<script language="javascript">4 e8 ^: ^' h; S0 U
//人名移动
. ]" x1 h  O1 U6 Bfunction move(fbox, tbox) {
# F( U3 M/ d( N# E# y8 t; avar arrfbox = new array();
8 O: k2 \" h; avar arrtbox = new array();
1 y7 u7 a7 P9 ?var arrlookup = new array();
' U6 }) d$ v9 `6 z( B( mvar i;
) ~4 d! Y  J* B! dfor (i = 0; i < tbox.options.length; i++) {, Z* a0 _8 A# \+ ~4 R; a$ _
arrlookup[tbox.options.text] = tbox.options.value;1 H. g/ g2 C9 F( [) ~( r
arrtbox = tbox.options.text;
! s$ Q8 E6 f; u* z}
" Z; ?& a; H# ]% Z  Z5 ^* C+ \3 Jvar flength = 0;
3 x' V' |5 Z$ s9 D% qvar tlength = arrtbox.length;- k0 c, b% h; y9 I
for(i = 0; i < fbox.options.length; i++) {
. G* W$ j3 d; v# n4 R4 Parrlookup[fbox.options.text] = fbox.options.value;1 _& [& n, |# ^  r; K6 Z
if (fbox.options.selected && fbox.options.value != "") {
" Q8 [1 O9 E* _5 S3 F, narrtbox[tlength] = fbox.options.text;$ m# B$ @' l' C5 k/ U# l+ \! {
tlength++;
* f" S' b$ F& }* G, d3 y}
7 \8 Y' m* @) |5 zelse {
3 M) A% {6 l/ J" ^arrfbox[flength] = fbox.options.text;& z2 z  S2 J7 y- H2 z2 y2 s! \
flength++;
+ j# c2 C$ h' l3 c1 i: u+ i   }& k; l1 C! Q7 `& L7 B, v
}
& H! B- J! W, Y3 k, z: barrfbox.sort();
5 ]. d2 a( x- @. F7 l7 p' o7 {$ B4 earrtbox.sort();5 k. `. o* k1 ]1 Q

! G. i) U* t8 u7 Y5 Wfbox.length = 0;
7 V3 ]. Q; K9 J; G7 ~9 f" F; K8 ntbox.length = 0;
' _6 I, V! p7 W& Evar c;
6 B& ?+ w' I/ U7 Nfor(c = 0; c < arrfbox.length; c++) {
. ?( Y; T1 J& ~/ g5 z1 A0 g% kvar no = new option();0 Z- y0 m& z: x4 l- {0 z8 v6 F
no.value = arrlookup[arrfbox[c]];
- d7 p. k7 c; G. d7 n9 J7 xno.text = arrfbox[c];
% L' X7 u( z& j, b$ l6 B# V( Ufbox[c] = no;, O& Q) m& @6 C& }  R
}
' n. H3 u* |9 S5 l$ x5 j2 M3 s, mfor(c = 0; c < arrtbox.length; c++) {
9 y( ?$ A6 f! l$ ?/ T# a3 d  h/ Wvar no = new option();0 f- [: B. v3 x# W8 I
no.value = arrlookup[arrtbox[c]];1 t8 f" E( X! L7 X9 W
no.text = arrtbox[c];% T; V+ C- I) g" q4 {
tbox[c] = no;
5 t0 W* W9 ^. \6 `% q- W7 t7 l   }! `6 b# {8 Q  _& @/ O7 W7 c: \
}5 H6 e- d1 u- I0 D% c2 c9 m
</script>
& E$ @7 P- g9 L# C) p* b* @3 Y</body>  e& W* ~8 `5 U3 w; @8 D

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