返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
; d  ^. W  _% L1 Z/ [6 K* \* f         c pageencoding="gb2312". f- U% |, W% [2 q' V& c
%>0 ?; b! j: Q& k+ y' L% W1 ~
<style>, @6 V' S- S! H- A. o) V
.f9{ font-size:9pt; }( @5 U, ?; B2 T) {# J1 K/ N+ [8 {, z
.bgc{ background-color:#aecaf9; color: #0033ff }, R4 ]) h% j) d1 M0 i( [
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
9 G0 Y6 B, P% {  border-bottom: solid 1px #4e7dc1;3 ], V% d9 D) U- s5 _# `
  border-left: solid 1px #aecaf9;+ W  ?# Y% Z2 \
  border-right: solid 1px #5679bd;
3 c- w: L# s# F$ E  padding:1px;
$ N8 W6 q& w% j5 a5 c' e( M' t6 b2 J  margin:0px;}
8 d& H# I5 H0 s' s7 N</style>
) v# U: Y( Q1 u9 T<script language="javascript">4 g8 g) ^8 n9 t& \  z( q+ F* o
<!--
" o5 E8 j- A9 h8 v, |0 g! e) c  xfunction rv()
$ ?. z4 V+ r& U% h% |: X{
6 ]8 ?1 z5 Q) U8 Z/ e  var val="";
1 q" i0 H4 g% R9 y  for(i=0;i<combo_box.list2.length;i++){/ n& ~" f2 E& y' d, [  r+ J
   val+=","+combo_box.list2.value;0 l! y. r' b( h- b" Q, F
  }4 m- u* o( n- o7 \- b
  if(val.charat(0)==","){
; [# O  e1 t2 T5 `   val=val.substr(1,val.length);" n0 k: Q0 e* w& X+ B2 }
  }
( m7 ?/ B7 `4 K) _+ L! {5 I% H  opener.form1.frecname.value=val;. E3 M6 Z$ H8 C
  self.close();
8 i/ s% D4 T& A3 T4 @}+ u. G% w  w5 Z) K; @3 n
//-->2 I1 D8 R: N) `9 n, v! t
</script>
3 W& y2 T8 u; h: O2 g. \<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">) v. k8 x, ^6 @4 |3 k
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" /># m) m. h- q5 L- X* e& ~4 h
<%' W2 T5 S$ N" _9 o  P* U
  cdatasource ds=new cdatasource();  //数据联结bean实例
+ u: Z  {" c( s2 m$ B& L  java.sql.connection conn=ds.getconnection();" e; f" e+ G$ M% Q) s
  java.sql.statement stmt=null;# m9 e4 J* e: \
  java.sql.resultset rs=null;
7 R* m+ |+ n% F3 {  cdatacheck dc=new cdatacheck();9 W4 o7 J9 K( j, Z' }' @$ O
%>
3 u! {% f6 c; I: G- P<%6 H) `9 u( Q# i8 h/ ~" c$ Y
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";, z# H1 |; D! F6 E* w
stmt=conn.createstatement();4 u) H% L: N* c: l6 [# S
rs=stmt.executequery(sqlu);
- f. ^1 z, _" c% Q: i- {7 K%>
5 L" D4 R+ H& d4 f7 f1 p7 V4 {<script language='javascript'>8 p, q( D4 ?' M; l/ B" d
arr = new array();, M( H  B% f% [& C/ p
<%  int temp=0;& ~4 J: \* O' e9 P# O
while(rs.next())5 [3 ?" A6 N* D2 L7 |8 X
{
8 z2 P$ n/ _5 V! e( ?+ s%>
. V; L3 R6 Z: `+ t' Q* a: Farr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");; u) u8 a- y$ d: {$ p
<%& M! E3 _! C8 f& z4 s0 N9 x
temp = temp + 1;
) _$ i# S0 ?0 z- u6 L}
7 m4 Y' I1 z/ E* K%>
' r  |: G5 D5 u! i" Ltemp=<%=temp%>;: t, p: ?, ~, x5 Z, T: m
function changelocation(id){
# z& L& q) K+ F! }5 @document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 $ c7 m1 A7 D, V7 Z# o, J6 z
var i = 0;
! A" A: U+ l& }8 E0 Mdocument.combo_box.city.options[0]=new option('-------','');
0 k1 J' @$ Q' tfor(i=0;i<temp;i++){ 0 W" }9 C9 V  M5 D! _3 D) F
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 4 ^" J- F, j# D! _
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); . _$ J# u( V2 B5 ~- h# C' e+ B1 C7 S
} * V3 g: p6 p( r$ W, j
}
' ?/ R5 R3 ]& T- Z. C7 `}
, Y: d5 }0 z1 `, a$ B</script>6 I& p: S. {1 I0 a
" \7 H; W1 h: _" Y* U  M
<form name="combo_box">- ~( @! a" R" M
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">) W0 ~: x( {. N9 M3 Z# s$ X
  <tr height="24">
0 _1 z4 l+ x& ~7 `, g    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
4 K/ M# h3 J/ Q9 @3 [. Q    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td># i6 ]7 s4 W3 W$ h/ `
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>4 O8 {+ D* Q) o' N* w
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
8 S7 o3 f9 v8 a  </tr>
! r6 I$ j5 B' n7 f  <tr> / k( K; a) x0 ~# l' Z
    <td>
6 n* v  q2 I8 y3 p" p  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
5 x( P0 ~9 Y6 R/ I  <option value="0">请选择部门 ---></option>0 [9 l# Q4 h# l" [4 f: ]
<%
2 Y# y# S: j; b- T. f" ]    string sqld="select * from tdept";
; o. c% Y- P( M0 Ustmt=conn.createstatement();
1 M" Y7 m! ], s) \: ]; Z$ ~1 irs=stmt.executequery(sqld);
0 G+ E- P9 i6 f0 n# n0 f/ r' L: J: kwhile(rs.next())9 s$ P; k0 _; G
{
: V1 Y. D2 b* h4 F%>
. U% s: n& V  g" y  Z0 x1 d5 s  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>0 ?# m1 C$ z8 D8 i8 }: k# ]
<%4 N. v2 O0 Y  f9 ]
}% H, X, F3 a) u
%>
0 f7 @4 |0 @8 _; q$ d: u  </select>7 R+ i2 r0 ^, m. v2 G
</td>5 J, Y1 ]- g: O$ ?
    <td>$ [9 o- m# ^2 J' p: V
  <select multiple id=city style="width:150;height:200" class="bgc">' o/ U& s& c3 A- Z0 h+ h
  </select>9 K6 D# P' R  k) R4 r
</td>4 f1 n0 C5 U' ^/ e) p8 Z% s
    <td nowrap align="center" class="bgc">
0 u6 P& I( {4 L4 n" [. `8 F  <input type="button"  value="<<" class="buttons">
7 `# S" v# ~; Z# @1 X  <input type="button"  value=">>" class="buttons">5 p4 @# T3 l1 w& A! I* B. N
</td>/ J) Z# L; k. c6 f, E) q, m/ N! e' J
    <td>6 q% ~- @& g) {4 J1 `3 F- R
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">( c8 A$ `5 w; r3 i' L# T! g6 O1 a' _0 X
  </select>2 h5 P* o8 n1 c  p: `+ l2 K* E
</td>
1 A5 E& q- j+ X& i% b8 f  </tr>
5 {6 a& k2 |: C1 o) ~    <tr class="bgc"> ' V  I7 q% \2 ~' A: z1 f3 X- \
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>7 A$ t# T$ A: i# J4 v+ I6 w' b5 i, _
  </tr>9 z6 I1 O! K7 T6 _# t' t
</table>
! Y! t- Y* B) |/ t+ I* b6 C</form>
1 u4 A* ]3 t3 o/ M( R; U<script language="javascript">
! h) ?- O# Q. L) f//人名移动
, Q. Q3 V# X3 F! nfunction move(fbox, tbox) {2 l# c5 Q: s: @& r. s4 D
var arrfbox = new array();
# q; ~# s0 t2 }2 K! c* ~+ N$ Qvar arrtbox = new array();% g4 X; P& I' c% X9 W8 r
var arrlookup = new array();  n8 o# W- `  ]& x1 ~
var i;" U6 s: X( P- @" R
for (i = 0; i < tbox.options.length; i++) {
4 P# g8 @: ]5 i6 E- [% Darrlookup[tbox.options.text] = tbox.options.value;
1 f. X& s: O, X" y0 P6 |2 R$ \9 D) Q$ Yarrtbox = tbox.options.text;+ L) @7 h; L6 T# E! d( C, N( w2 [
}
# G: z* Z; c* q6 Y- O. j( Dvar flength = 0;
+ w5 S. T$ K0 Bvar tlength = arrtbox.length;! e% \  V! x( d1 `3 u5 @
for(i = 0; i < fbox.options.length; i++) {2 |8 b: f7 |" k3 A2 Q) [
arrlookup[fbox.options.text] = fbox.options.value;4 C5 H1 ]8 o) z9 Q  @- A9 E
if (fbox.options.selected && fbox.options.value != "") {7 f( b# K. O; w: U- J
arrtbox[tlength] = fbox.options.text;
% H- }1 S" H  z3 a- utlength++;
* t+ T* g4 J8 M; b: e}
( z$ X( C5 v8 A! E% n' Y) Belse {2 q% n. _2 Z0 d
arrfbox[flength] = fbox.options.text;
: J9 @! `, H9 }% E4 G$ aflength++;
. J! Q1 `' [9 b8 ^4 p8 y0 @   }/ w6 d; j- H5 O4 v% A0 {
}3 {8 _" I9 J8 z
arrfbox.sort();
# A* V) ]9 G. j$ K( w7 rarrtbox.sort();" x7 l' }, h1 S$ i

1 W6 |- `8 U% f. l0 \# e: q8 ofbox.length = 0;
6 N- [' ~  P- U  f8 n8 `& P# J0 [tbox.length = 0;
' S% w, `. S4 r' r" F% k* Ivar c;* F( v8 w! ?  t% t1 ]4 l4 `
for(c = 0; c < arrfbox.length; c++) {! i9 z9 G( n  n( M  T
var no = new option();
2 G3 u1 ]: ~- }8 ^no.value = arrlookup[arrfbox[c]];
# t, H1 s2 C! J3 Wno.text = arrfbox[c];
7 m- |- M9 a) ~1 V1 Ufbox[c] = no;, b/ X  i! |8 v9 P9 O1 D% U% q! T
}
' {. ?/ G7 B6 Y0 X) ffor(c = 0; c < arrtbox.length; c++) {- ]1 f" ^4 X5 E/ L% z
var no = new option();2 C9 s  L. ~& u- f) y
no.value = arrlookup[arrtbox[c]];
7 P* n) r* u# ?( d5 sno.text = arrtbox[c];: H2 U- F$ T$ \
tbox[c] = no;. w$ N( K  T5 A7 s% _
   }9 s/ e2 z' D' Y# [9 ~% t( f: g
}' p0 g* \- \% i* y3 Q6 v! U* _8 g
</script>* [. [' M) W) K! g4 V
</body>
( Z: F9 n  C/ k7 u

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