获得本站免费赞助空间请点这里
返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
2 y+ X0 }+ \5 a& _4 S" D! [         c pageencoding="gb2312"5 W6 ]3 {6 W4 I' D- ]/ J* r! L0 C. m
%>- g/ Z; F1 K) S) M  w7 E* Z2 ~
<style>
) b+ u  a! v' G  E4 g.f9{ font-size:9pt; }
1 B6 r& h8 q: Y4 E7 m0 J- [2 m.bgc{ background-color:#aecaf9; color: #0033ff }, `  I: S" v' f+ z' G
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;( h6 m6 E* @! Q1 l* o: J
  border-bottom: solid 1px #4e7dc1;5 u* p7 a' O' t; G: ^
  border-left: solid 1px #aecaf9;2 |* j! P" z  n2 f
  border-right: solid 1px #5679bd;' w7 J; l" H2 y6 b  J% D- F3 d
  padding:1px;
1 q3 N2 g3 T4 v8 ^+ e  margin:0px;}7 q/ J5 b. b. C' y0 u+ V
</style>& f+ ^( c7 g# `0 b
<script language="javascript">
# \7 ~$ {7 G, F! R<!--
( J$ P% V8 i" s' mfunction rv()# f, I: A. m9 M% g- x; M4 n
{
+ F5 p+ }9 H0 V  var val="";
  B( H* `2 C* U1 m8 S$ y  J$ J  for(i=0;i<combo_box.list2.length;i++){6 j  v% S3 [' k3 C5 k! Y! x
   val+=","+combo_box.list2.value;
- _9 d+ W- e, o. e" u  }1 M, h- |; [2 }  c# m
  if(val.charat(0)==","){
5 h7 V  W( H& D2 |  q   val=val.substr(1,val.length);
4 n# g& {" i* d  }
: z- ]* r; ]3 f: g5 M! j  opener.form1.frecname.value=val;0 y7 y5 C' G5 c; e
  self.close();
& U. s: |1 e7 {+ R}7 M5 x" S% F' P  @3 G
//-->
, U8 e% z* i; `) S; i, ?</script>
/ G/ G7 ]9 N+ e( F9 \4 @<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">  v6 B1 n6 z, g/ m1 ~/ o
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />% o8 {1 Y8 ^6 [6 {! h' J
<%# z1 F4 m' Q) p* ~- r
  cdatasource ds=new cdatasource();  //数据联结bean实例: ]  w9 ?, }' ~( N) ?
  java.sql.connection conn=ds.getconnection();8 T2 X0 r4 h0 c( H0 `6 ]5 w3 {
  java.sql.statement stmt=null;  C. c! I2 |" c! O, p7 _8 J- L  ]" o
  java.sql.resultset rs=null;# O: b3 X9 y, `' t
  cdatacheck dc=new cdatacheck();- x- z2 w! z: O# b  |1 Y
%>3 C1 S( H; G& J  {
<%
5 p% X9 A8 s% q+ D3 J; Sstring 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";9 n" H8 @) v2 s2 u
stmt=conn.createstatement();. b7 @( @3 Z  L5 p
rs=stmt.executequery(sqlu);
% [" m. |9 B: E. U%>
9 R, n  ?$ \6 z; _<script language='javascript'>
" B/ ^6 @& o- J' G4 x  P7 |arr = new array();3 ~+ Y8 C7 w$ [3 x9 W/ d0 w
<%  int temp=0;
& k+ C7 e( L, w: K. ?# U! Swhile(rs.next())
+ P8 e% V; r3 X# M1 s, o{
# ]4 ~$ i# _8 N%>( d' r2 e# t2 Z) @" q# s
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
5 c4 }; ?; D+ C: F! ?5 T( ?<%$ n7 Y  y* J0 ~
temp = temp + 1;
6 _: U5 I% |5 u- L7 R- C}& I, h/ J( \) p5 Y6 c
%>, I; h8 Y: w9 g+ k0 \6 C
temp=<%=temp%>;: y+ N5 N7 m6 D$ ?8 `" d
function changelocation(id){ 4 H) }3 l5 ]: C; r5 a
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
0 Y* q( F! _! r$ uvar i = 0;
- f  u6 y3 S8 bdocument.combo_box.city.options[0]=new option('-------','');
" m& }- ~7 @. j8 d9 x% X0 Mfor(i=0;i<temp;i++){
; O) j' T9 M5 t6 sif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
6 x( G; T: X' i2 M7 Cdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
* Z+ K6 v- `4 |$ ^: D} & g7 V4 n9 M7 B/ Q
}
7 o1 G  {4 d0 s% _1 J. H4 }. u# c}
' I( ^7 I0 N, f0 d; m</script>! o9 p+ Z# j4 _; w4 G2 x$ C7 ~
7 B! j& w: F, l
<form name="combo_box">
  F" T# F$ N: S7 s: J+ K<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
( m& h% ?: w+ g& a" a( [/ }3 i1 y. v, X  <tr height="24">8 L8 [  _! f7 D0 I6 `) X
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>* l" i  _: h& e# z6 C
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>/ ~' e5 y. e; t& c: q  H
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
' [9 J8 X8 ~. `5 _  Z: P% M    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>2 M! k! w  f3 ^9 h6 a
  </tr>- V8 _9 b/ H7 y1 `2 I' x8 n! H  o
  <tr>
& H* D2 w( \, |( g1 n1 m    <td>: i" }1 @, i: D$ \9 x
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
6 ~' g. k- Z8 W+ e; a& k  <option value="0">请选择部门 ---></option>
3 A& {- t( P: H9 \<%
6 L& R, W  `6 g+ @( ~, F    string sqld="select * from tdept";
6 S' h% l/ p( E8 l9 ]stmt=conn.createstatement();
9 O$ a( o- w- c9 I% a9 [rs=stmt.executequery(sqld);
" X2 h$ Z  L, t2 w( vwhile(rs.next())
1 e9 `  e1 Z+ i6 B" p2 ]# B{
: G+ v# ^- R2 C0 f# L' U4 e%># J; X, j' o6 I' O' ?# p  w
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
* P9 Z, p& G) l* H8 f: W<%% L/ t1 f2 B6 Y8 b6 I' [3 e
}
: H7 ?/ ?8 @; n. E5 T0 [9 J& G%> 5 d/ M* a6 b# ]: Z: x8 Z, t+ a, V. E
  </select>  L  T& E4 G/ v7 x+ m! q
</td>: u! |1 T4 e' V& g
    <td>* y4 }( B$ h: \" }
  <select multiple id=city style="width:150;height:200" class="bgc">& _+ x+ L* f$ Y0 i+ d, ?
  </select>
$ `$ w! h1 J% Q& q8 K+ J2 F) O: j- c</td># n9 s/ a, F0 i, L
    <td nowrap align="center" class="bgc">
. i7 I8 v% I* L- y0 k  <input type="button"  value="<<" class="buttons">+ V' a# V7 c! N* a
  <input type="button"  value=">>" class="buttons"># R7 a; z3 U" R, D8 v
</td>  \* F5 k" r5 N5 I
    <td>- K5 S) `; G# c
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">9 F0 R8 l0 Q) x! h1 H9 x
  </select>3 P, b5 k* T1 \4 j: B
</td>/ {% ]; t) V  K  ]- c
  </tr>
4 J9 H' ?% S7 `' w7 \- F) I  \, x    <tr class="bgc">
  S+ F0 s# U6 ~    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
$ I' b1 m- J( k7 Q) P" p' m  </tr>
4 T$ I2 |! G& s9 D</table>5 t* [7 ?: G8 N4 T1 E1 }
</form>4 m6 I+ C  _; W7 `8 j6 d
<script language="javascript">" I9 _) d. j9 J/ X
//人名移动
, C: x( g3 [& Efunction move(fbox, tbox) {) F9 q2 i  K7 |+ Q$ y
var arrfbox = new array();
8 O- |( X4 J3 h( _var arrtbox = new array();
# u8 g/ y# T: Qvar arrlookup = new array();
8 d7 Y7 C& ^* v4 ^8 rvar i;' z# z: X6 A' X
for (i = 0; i < tbox.options.length; i++) {
- |* P3 T8 O+ s. D% Garrlookup[tbox.options.text] = tbox.options.value;
" K% J+ B6 h4 ]3 Y- @, `arrtbox = tbox.options.text;
' B. {* p6 B  i/ K: O& [}
! n" u+ y1 r0 P2 M/ R' n4 avar flength = 0;: D- a' y8 g$ q6 S2 @4 t! N1 w
var tlength = arrtbox.length;
" S7 D1 Q$ A. Q( \; Tfor(i = 0; i < fbox.options.length; i++) {
+ z4 Y% Y. X4 o2 f! H& farrlookup[fbox.options.text] = fbox.options.value;3 T8 q; Q7 q0 _! y& \$ n# W
if (fbox.options.selected && fbox.options.value != "") {
) g. K3 ]. T* uarrtbox[tlength] = fbox.options.text;
7 M/ p7 Z4 @9 Y# otlength++;
3 Q. T, t9 P4 j1 h$ R9 t7 ?1 Z  A}
. d- V9 a$ _2 _! `+ {" Velse {( W0 L3 A2 \  h# q7 t, x, P. k
arrfbox[flength] = fbox.options.text;& h( V8 K; |4 Y1 _8 o7 U, b
flength++;
# c6 i: a; J8 r5 `9 ^   }- {% S7 f4 a' w5 u4 V6 V
}( s0 l- a1 F4 ~, ?) a
arrfbox.sort();; X% x( ]" T, N6 B! F/ z
arrtbox.sort();
% X& f! H& P7 A9 F6 E* {
6 l5 E% V1 ], w( @3 s# N% w! Rfbox.length = 0;
# R  E% m; f5 G5 M9 B) stbox.length = 0;, p) v) X* p. R* U+ Y1 j3 w$ N
var c;
( g$ Z$ o, P# x8 s  z8 g& J3 C) g  Gfor(c = 0; c < arrfbox.length; c++) {9 Q  V/ I5 q( }6 j8 l) G
var no = new option();- {' c2 l( P7 c3 X
no.value = arrlookup[arrfbox[c]];2 S* Q% I6 {+ q. S6 W
no.text = arrfbox[c];) J3 i0 I: E, ~  b+ d) J
fbox[c] = no;
, x& M# r/ \! `1 u  D; m8 b}
& a" \% O4 X% K* afor(c = 0; c < arrtbox.length; c++) {- \3 v2 Q( ?5 v7 b, }7 B3 K
var no = new option();2 A" Q1 T* [- U, B" b* v
no.value = arrlookup[arrtbox[c]];
! h) _4 X$ z0 K% _4 A1 H' e0 v1 Zno.text = arrtbox[c];
- V( e4 @( C5 x" W7 E" x: c* ntbox[c] = no;
. N% g- ?# `; _   }5 T' |3 g. ~& l
}) p  p; g3 C3 ~  L. p  `$ I1 n
</script># ^/ x# }( E, X4 I! \2 N
</body>) k% }3 Y, E1 B$ [! ?& N

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