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

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
4 t' s& R  H# @7 ?2 s         c pageencoding="gb2312"
( M4 G) p# x" Z2 a( U%>
% p$ G5 `, S- _$ [& r- g% _<style>2 J% Z& C: ?0 q& J- l7 o
.f9{ font-size:9pt; }
: Y7 V% @1 U8 h) [; G* m1 A# S.bgc{ background-color:#aecaf9; color: #0033ff }
- Y, a& w" Z( Q.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
+ P- R8 L! h2 n  border-bottom: solid 1px #4e7dc1;; H  |4 P. Q, V% j; `
  border-left: solid 1px #aecaf9;
" I$ e, K6 L5 ]4 C' s, r  border-right: solid 1px #5679bd;
4 |  o. S$ S. e  padding:1px;  h5 K8 Q! x3 T7 [+ x9 e) g4 a
  margin:0px;}. z6 E  G; |4 Z9 ?6 A. R& n
</style>
3 N7 ^0 O, p4 c+ p: z<script language="javascript">
# e7 e& K% b% g<!--5 e. T# G4 f. C: [, D! l
function rv()
. ~0 o# V% a1 e/ d1 d{
6 [8 s/ e) d( b9 m- {0 P  var val="";9 Y2 ^0 O( v% D) u4 z2 k$ x# u
  for(i=0;i<combo_box.list2.length;i++){
. }6 ]5 U, X/ G$ P& R   val+=","+combo_box.list2.value;! ]7 w6 H. @% Z
  }
2 }0 r4 x/ t- Z1 l  if(val.charat(0)==","){
* q: K( X" f9 \) v3 f: R   val=val.substr(1,val.length);
# B. |- X+ T6 c) p# R5 V( N# A  }
. k- G* V3 N& Y4 C9 P4 A  opener.form1.frecname.value=val;2 y8 j% E, e# E: T% ~; r5 d8 ?5 P
  self.close();9 l5 d3 z: r) y! |7 @, V" \1 B
}; `% U' `) a+ Q- C- q* o, j  L
//-->
8 Y/ U! o: f# y+ U2 Q</script>
# V- `0 [6 z, e/ O<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">7 m8 C5 g- C. _% c5 J9 s/ n+ k
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />9 g4 O9 Z% k* G
<%
0 f3 {- n1 F- i+ e. U% Z! b  cdatasource ds=new cdatasource();  //数据联结bean实例9 o* h! x( v, Y6 h% U! p5 t4 K% V
  java.sql.connection conn=ds.getconnection();6 }( {5 E; A$ W5 [
  java.sql.statement stmt=null;2 ]6 S* p: ~5 F. k+ U. o9 D
  java.sql.resultset rs=null;
3 V; q3 _* B5 V  cdatacheck dc=new cdatacheck();: ]8 K! E4 a$ x6 n
%>
7 i& y1 \. U$ w6 v$ s+ \<%
. ^5 _0 i, r, |4 q6 ]& istring 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";1 M! k- M( P. q
stmt=conn.createstatement();2 `8 b$ P% Y( G0 ~
rs=stmt.executequery(sqlu);
4 l' D3 N! e) R/ x. D3 n. _2 s%>' f" V# r1 F- I& C# m
<script language='javascript'>
! o* W5 f/ Z, O, @: k) ~arr = new array();6 G9 G$ F5 u1 s, M3 a+ j1 s
<%  int temp=0;
' `1 v& X  W; B  C- {while(rs.next())
0 m5 A  t3 S# M9 \* d{
% I( P+ \% R+ k4 x8 H; k%>
5 m, M  ?) S& ]2 ^  H$ n6 [9 k1 harr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");# _5 B2 A" U/ k
<%$ Z& [0 z; u! G5 e3 d* w/ ]$ n1 \( u
temp = temp + 1;7 V% L; O3 s% e. u* T
}
8 ]5 L. F# n2 i0 T%>: z3 v9 L6 u8 R
temp=<%=temp%>;
/ o4 b  [. Q1 k) vfunction changelocation(id){
* i8 b5 u& k% v! k: d) Odocument.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 ) O4 Z5 T6 Q: [8 G& c
var i = 0; # B8 k" ?8 ?- A& }
document.combo_box.city.options[0]=new option('-------',''); - a  p* X, {9 r4 S+ k6 o; f! {
for(i=0;i<temp;i++){ , X& V, A/ k- ?  S3 X. Y
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
+ |$ G1 G8 W1 p- m* Gdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
9 k3 u- z7 I+ ^) Y" G3 D}
; ?# ]& V  E9 `$ \}
# M% P$ |$ s) O; l}
9 {1 Y9 I- Q. _- l1 e+ Q1 c' V( p</script>
& {" t/ t% ~! ^' [. q
1 N5 a$ W/ }9 ^$ O! S$ Z; ~<form name="combo_box">
3 ?; j6 s% c8 `9 _. O<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">8 e' u/ c& i3 Q
  <tr height="24">
2 ]8 Z( ]# f: h0 q' D: X2 J# }" I/ R    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
! Q0 M& w# C* U0 m    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>. `3 R& Z0 A# q
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
( w% u; V; [4 x3 o, T    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>8 \& q. Q* p) w# ^+ w+ r
  </tr>. M2 g9 I- M( j
  <tr> # m; i  K! k) R1 d. S5 h
    <td>
6 ]) Q! A- J1 u2 o4 P  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
1 h, l# o- ]. Q1 Y: R; [  <option value="0">请选择部门 ---></option>
6 {+ w# y! u2 c6 d; o0 Y% K& f+ U# k<%! l# T0 e) \3 F
    string sqld="select * from tdept";$ X( R7 n8 w: s$ t* ]; c. x
stmt=conn.createstatement();
/ h: @1 k# ?8 `; K1 Grs=stmt.executequery(sqld);1 S" G. Z4 I3 |- Y' v. r
while(rs.next())" y8 B+ P& E, S7 Z' {+ S+ v
{
7 l7 N9 K( |6 G- \! f. a%>7 c# l. ?0 Q* I3 F+ |
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
6 J3 K* M* [4 c& u$ f8 ]<%
) Z; k" W  M; b" ~/ D, K$ f4 E, f}( p: t2 e! _0 _: Y
%>
  W( l! R1 H  T9 V+ L* d( l  </select>! ~' c0 @3 |' @/ ?( J0 T
</td>
4 e4 T3 h% h0 F& A    <td>( k: S0 w- D. @# ^
  <select multiple id=city style="width:150;height:200" class="bgc">
' \/ O4 b1 l% w1 {9 ^- D* [  </select>' o6 U& F8 U1 C
</td>( w# g, U* z$ l' c9 W; _
    <td nowrap align="center" class="bgc">; h; g0 ?$ K6 S' [! U2 d3 [/ ^
  <input type="button"  value="<<" class="buttons">
* Q  e$ V, T1 s, B9 H# V0 y/ V) C  <input type="button"  value=">>" class="buttons">/ ~5 c$ v5 P' R( E2 e; r! \1 U0 ^4 b
</td>
$ F9 B: U8 _) G) N, C/ g    <td>9 e+ J9 I: T; v+ ?/ g, J9 ~
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
6 w: v* e9 }' n% O" z/ {  </select>1 l5 a# R8 B) N) M( U
</td>
" c6 ]* x2 y1 i5 x0 O  </tr>
7 s" Z" ?$ g* |6 J* Z! y3 Z3 t) i    <tr class="bgc"> 3 z8 P0 R7 ]* _5 k; V- ?
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
. a3 q+ [+ B3 b( [5 }2 o  </tr>1 @8 c6 n$ g1 k; i9 f  B
</table>. a/ ^5 u9 w9 z- p$ a! x" {
</form>
- t; [: Y* _( k4 d<script language="javascript">
2 e2 L7 r$ X2 x* X8 O  ~//人名移动
8 B6 }  S; ?( H* T7 w% A4 xfunction move(fbox, tbox) {+ _, K# B) w  [# U  K* }
var arrfbox = new array();  n: o9 o: S, |# \% z) u" [
var arrtbox = new array();; C9 j0 D# J  D6 g) ^  y
var arrlookup = new array();" @; Q' q5 T" r
var i;( G, T% |  D; T% I2 I
for (i = 0; i < tbox.options.length; i++) {
; g6 \! g  X  W7 karrlookup[tbox.options.text] = tbox.options.value;
2 V( R$ F# R1 q! {/ _arrtbox = tbox.options.text;; |5 |) n, g; N, E
}
* K6 ^" I! g7 }$ G( lvar flength = 0;1 N. w7 n3 M4 B: P
var tlength = arrtbox.length;
3 n+ O2 y" g  Ffor(i = 0; i < fbox.options.length; i++) {
9 {3 i) c0 f  b# W1 F% @arrlookup[fbox.options.text] = fbox.options.value;& A2 R! z# L7 P* L; i  o$ D$ }
if (fbox.options.selected && fbox.options.value != "") {
. r1 Q* p/ z! \arrtbox[tlength] = fbox.options.text;8 k* U7 c* R' c9 l! N, H2 e
tlength++;
$ V0 o5 g7 q9 |3 O}
6 p+ Z- ^/ W+ D% f. e- W3 Selse {9 K3 v+ F9 @4 k! {( O# o. ^3 N+ Z
arrfbox[flength] = fbox.options.text;0 d$ F/ ]. _" q! [6 u$ x
flength++;/ o$ j: a4 M3 ?* L7 y5 q& n
   }
6 P# A% Z  h( A* i* ]( L}
! R' x, F& W$ zarrfbox.sort();
: K* ?0 ?$ a! l( @, v3 e% @arrtbox.sort();
, J* W* Z6 D9 }% C  C9 F& j8 w+ A/ z) R4 {0 ~6 w
fbox.length = 0;/ j* w  V+ Z9 s. d9 g9 t" U
tbox.length = 0;" l2 V2 ]8 S6 S- Z% q- ]; z
var c;
% o4 k( F6 N' P4 z- {2 ffor(c = 0; c < arrfbox.length; c++) {: k" f. F% e7 k5 y6 G
var no = new option();
# R- f) c) j3 ?9 Y! `8 O5 A, V; C! ?no.value = arrlookup[arrfbox[c]];
4 U0 P7 z3 T) k1 Nno.text = arrfbox[c];% g2 ~# G6 W2 d
fbox[c] = no;
# |7 b8 X4 x7 c) E# t- _% d* ~  l( {/ S- c}2 @5 B6 _* _/ a/ n
for(c = 0; c < arrtbox.length; c++) {8 `1 E, b- @9 Y0 d* E
var no = new option();) C0 \/ w% u9 u5 [0 L5 p
no.value = arrlookup[arrtbox[c]];& ?* W& m2 n. o
no.text = arrtbox[c];, r  I1 u" v9 `$ |) F" Y) h6 y( t$ T
tbox[c] = no;, i( m6 H" I& K9 n: M
   }
( ?" g: C8 F7 y* Y}
0 ^% O% q/ x! Q</script>
; g, ~; |; ~' i9 ^: _9 C3 s# V7 F</body>2 O3 A1 m/ [1 l7 v6 s

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