返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"$ X: S: i* o/ X& k
         c pageencoding="gb2312"
* P6 ~* a+ _; ]  X  i( k%>
2 X0 F$ \! H, x( r5 \<style>
! y( J# t3 V% K5 F.f9{ font-size:9pt; }
  g) s8 e* z. H6 k# {.bgc{ background-color:#aecaf9; color: #0033ff }
4 g! ~8 D6 c' a: \5 `.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;( L9 t; u9 J3 P3 _8 Y
  border-bottom: solid 1px #4e7dc1;. P  L8 c, h* ~8 Y
  border-left: solid 1px #aecaf9;" H0 O9 |3 V1 V* s1 s
  border-right: solid 1px #5679bd;
& s; H0 U5 p7 r  padding:1px;
  C, J3 Q- F. n3 Z  margin:0px;}
/ n  A7 f3 i! |& z, V) [  [+ Z" p/ W7 L</style>
: |2 \6 z( y9 G% C* ~<script language="javascript">
+ `$ [' {( z" s0 W9 l: P  S<!--
- l1 p6 s/ c  y, A+ [: n4 a( Q& Vfunction rv()
7 f* n" k6 k* u) U{* r* E  `% V0 ]& \+ Z3 N" D+ f
  var val="";
. l2 r7 F  X5 J8 |# ^% s8 [( w& ^  for(i=0;i<combo_box.list2.length;i++){
( l; M& D+ T, v9 H. ~! U# Y: ]   val+=","+combo_box.list2.value;
2 Y4 d; E. q2 x# y: O: U6 k' ]  }0 J& f, [* n6 h% O5 Q0 _3 b* E) U
  if(val.charat(0)==","){# D$ i9 V% l3 W, l6 r( E6 C8 O$ M
   val=val.substr(1,val.length);, k  T0 Z3 w5 z% v. m0 n
  }
$ S' I, H3 g% x) ^1 I' g( w  opener.form1.frecname.value=val;
1 @' J; P- L0 W, ^8 [- M  self.close();
% e1 S- P& c+ u9 j9 s2 C$ p, _}
* J9 n! E+ J. L. {+ o8 D4 G9 t//-->9 L5 V" ~/ ?/ M0 S4 m
</script>( c4 g; k7 L" g" j/ ]
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
. O& P0 D8 y8 t4 |) Q1 ]<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />. h9 u0 z$ d+ W  ^3 V
<%
9 d) y# o- W+ o& ]! C- m, }  cdatasource ds=new cdatasource();  //数据联结bean实例. t- b' j3 r, S* p' M) k8 q8 e
  java.sql.connection conn=ds.getconnection();
& x# J  m- C9 \5 k  java.sql.statement stmt=null;' q, l, A( W" q9 Z1 U9 y: }1 h
  java.sql.resultset rs=null;3 n  _5 p9 e+ D  I! t2 g
  cdatacheck dc=new cdatacheck();
2 O3 H' u' h- I' `! P%>6 o! l! b/ z: S) A0 Z4 J& K) P
<%/ v8 Q$ [0 N) P+ e+ G3 I
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";
- q1 T; B" \7 \3 u- {stmt=conn.createstatement();+ g- z; l5 l4 G' b* o
rs=stmt.executequery(sqlu);, V0 ^' D( O& }
%>4 L. \( c( l" Q' h! ~8 Q$ Z/ q
<script language='javascript'>! ?6 c& D8 x! H8 @5 E# r* D! y; L0 f
arr = new array();
% P) I- h3 C; v7 t0 r9 {0 b<%  int temp=0;( |0 a* U- ]4 c* v; V
while(rs.next())5 N* I: b1 n1 K( \3 i; j
{. g8 f9 D1 s# p1 J/ F  `0 d
%>9 |- g$ u" p% w: A6 @
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
& {" P0 P( x$ {  P! V: [' E<%4 Y" e. ^7 k% s8 ~0 R3 v# R; ]
temp = temp + 1;
' j9 q5 Y* x' F0 t+ _}
& b8 b# ^" e* i& h%>
' \1 S  Q: A& B+ g; O: z5 W3 |. wtemp=<%=temp%>;% ~9 k6 _- s3 n) m# b$ g
function changelocation(id){
# T, ^) v  `! _$ j: J8 wdocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 6 h* x. ~) W8 p2 g
var i = 0; $ q- @) d3 u9 N
document.combo_box.city.options[0]=new option('-------','');
* q; ^+ e6 s  k5 W1 W3 P$ Dfor(i=0;i<temp;i++){ 7 e5 ~9 C' q% x* r9 e
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] 8 {- z* M5 Q9 \% q/ `
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
; ]8 ?9 j2 p* B7 N}
5 s9 p8 e% H" X; f- m/ z, t}
' z( i+ _9 V7 x}
: S- |9 f2 A2 _( S  R# B$ N; |</script># l2 l' v. C4 i; R
8 o- h7 ?+ p% E
<form name="combo_box">
" N3 G2 e$ a. @; B1 W- {<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
7 H; a- ]* n7 @- m  <tr height="24">
, e2 t2 y; @% h; O1 b    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
. O8 ]& o$ f, ~' l( H* G; c6 Q0 ]! p    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
& ]* B1 V. t# |" z% \& J    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
) u) k$ |; g) b5 D  B' F    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
7 \" J. Z) s" e) ~1 R) u  </tr>
6 }* Y7 W" `0 y8 m+ W- h  c/ L$ E  <tr> ) [& ^4 o# j7 K* p- m+ F
    <td>
" K' p, V* S3 \! J! ~  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
# q: F6 E1 ?  O1 x7 T  <option value="0">请选择部门 ---></option>3 ^1 c2 q- w( r1 y2 x
<%4 h+ O4 D5 I" k# {" E$ @2 l7 f
    string sqld="select * from tdept";/ e, x$ n" d) }5 \! b9 N9 h" y
stmt=conn.createstatement();
$ s7 i" X* Q  z& p6 l4 t" J1 M: E9 drs=stmt.executequery(sqld);4 k( c2 b: e/ d# c# D1 D( b/ y# r
while(rs.next())
/ J% H6 f" q$ Q, ?, h{1 R6 x9 P2 ]. o3 I- @: N# \
%>4 b" O* U3 W- X4 s8 ?
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
8 P- u! h: n) {, B<%
: b0 O& v* z+ v3 ]  u5 A0 U! q, R}
5 S0 D9 Z1 \6 v4 R9 I( `; |%>
) F# u& T: [+ ~4 D5 P  </select>
! M3 S( K* r# R, z</td>  c, ~5 k& Q8 G
    <td>$ [5 p+ W- |# m2 H8 [9 d2 b+ m4 Z
  <select multiple id=city style="width:150;height:200" class="bgc">! `- Q3 J2 k: F: S/ B, L
  </select>  Z* g% t0 K% Y& N) t
</td>
+ [0 c* B5 q0 O- D2 ^    <td nowrap align="center" class="bgc">
2 T. r1 d" Q. A8 [" V2 F8 X  <input type="button"  value="<<" class="buttons">3 p- m: @; t5 ]! A5 I6 m$ O2 b: L( x
  <input type="button"  value=">>" class="buttons">
. u$ s5 |3 G/ G8 l( ~8 C8 C</td>/ @, L! e, j0 C- C' V
    <td>% M  w; h8 M+ _
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">% z; t2 H6 ]4 \' O4 ~3 P
  </select>
. R- [- f4 W% `, y' N</td>
4 I# a% i* M# F0 N& a  g  </tr>! _" S% U6 ^& }" Q- m% l! k
    <tr class="bgc">
4 S% a1 T+ L8 q( e6 L    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
$ e- `7 y% I! J1 Y  </tr>0 F# c. f3 R. F/ |
</table>2 g" w5 D" S& w: q
</form>
( H$ g3 L, l4 _6 l<script language="javascript">
$ U2 j5 o. e' l7 u/ Y//人名移动
3 k6 u9 P- k2 c9 d3 F: _function move(fbox, tbox) {# c! J$ `8 {$ b+ Z
var arrfbox = new array();5 Q( f+ F$ w: B- K$ x3 \
var arrtbox = new array();2 x8 [% o$ H0 i, n0 O
var arrlookup = new array();  C) i7 l& i8 Z
var i;7 c% g9 b% x% l, F8 S+ z/ _7 T
for (i = 0; i < tbox.options.length; i++) {
/ u7 y5 y) \3 r& `- R4 p7 O3 E0 Tarrlookup[tbox.options.text] = tbox.options.value;) j& V/ D  u  I$ U! D: Z- q3 F
arrtbox = tbox.options.text;
& m& m! O0 E$ @& a! W6 T3 k/ X}, a9 m. j3 _  @; @
var flength = 0;! R4 P. Q- A- C  _* b
var tlength = arrtbox.length;+ H# ?8 A7 J0 h4 |
for(i = 0; i < fbox.options.length; i++) {. G' F: `3 p- q/ e# d6 O
arrlookup[fbox.options.text] = fbox.options.value;1 e& D$ @4 x4 Z$ H6 Z6 E& K* l, o
if (fbox.options.selected && fbox.options.value != "") {
7 h* b8 z. p9 _9 [3 c( narrtbox[tlength] = fbox.options.text;" m! C0 s2 D: f9 \9 k
tlength++;' ^: y" H# {. C" S' F, S
}
% c3 e1 C1 r# selse {
) `$ z# V1 K0 sarrfbox[flength] = fbox.options.text;5 C2 v& p# k) R/ m$ R5 ]0 V* U) T
flength++;6 M7 Z5 |* W) o1 Y2 {. w* |1 Z. G
   }
/ {/ W. K+ f* r( e+ D7 p}
3 g8 f( B, L& J( L( q1 `- a7 Varrfbox.sort();
$ Q' a+ d7 q3 Y! oarrtbox.sort();8 L1 B, ^+ f, x
( u6 l0 ~" u  r. E* t: a. q
fbox.length = 0;
/ u/ x% N# X+ D- H0 t1 R% xtbox.length = 0;0 k: D: m& A7 _: w6 n& x
var c;
- R+ Z+ F0 ~6 K2 M9 s7 G" J* d' zfor(c = 0; c < arrfbox.length; c++) {6 s0 Z2 n2 J7 Q. c& I
var no = new option();+ L/ \7 E7 m# m. T$ P
no.value = arrlookup[arrfbox[c]];
6 i1 x: X' W% M& Jno.text = arrfbox[c];8 X; W6 a4 w# P- |. F
fbox[c] = no;
! _% b3 D1 ^& ~6 s  k}% |1 t( B0 B9 g( `, [% y7 }
for(c = 0; c < arrtbox.length; c++) {
- r! V3 i' A; O: h7 _( G, Mvar no = new option();
" U2 ^( M: D- q7 q7 |3 vno.value = arrlookup[arrtbox[c]];' L# }! R$ I# I
no.text = arrtbox[c];
1 B1 ^1 a6 T" |. ]; X/ C1 ^) qtbox[c] = no;
2 m% |" \2 `& D3 v; K' e' @   }
& }! a- e8 N8 }}( U% `2 T0 _% k( |4 D2 \& b
</script>
% s2 D1 A; ]9 y</body>: m9 {6 K& l+ Q/ r- p3 Y

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