返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"/ l! O% d( E9 L% f" A" S+ _
         c pageencoding="gb2312"
2 L+ u1 a4 Q9 |" C%>
9 I7 a2 b. b( p<style>; {, {9 u; U) ^% F
.f9{ font-size:9pt; }
, Z  T7 I. u. J. z.bgc{ background-color:#aecaf9; color: #0033ff }# x- _. _! z$ O3 `/ G
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
% b+ Z* T4 t) t" _6 l: g2 c  border-bottom: solid 1px #4e7dc1;* C  _4 X: D& m, U, n
  border-left: solid 1px #aecaf9;
, o0 n# Q5 V4 q) i  L2 [  border-right: solid 1px #5679bd;; e3 f! ]( g2 g6 n- \3 V
  padding:1px;
; L# [& n% h( O  ^3 B. o  margin:0px;}
  }# r, q1 A# N" S+ U! f; i  X& a6 y</style>9 E) W, G( _- ~, X
<script language="javascript">
& l( }0 F0 v" |$ a  D. H+ ^<!--. f2 x) E' b. |7 k1 o+ P
function rv()
7 W# J, T2 q  |8 _1 h$ b{/ ^+ g- f4 m5 d1 p7 X" @& i6 a# O
  var val="";, d* ^1 W9 P) Q3 l: h( s; X
  for(i=0;i<combo_box.list2.length;i++){
% G- d; P5 O/ q3 K) [7 J- B# F   val+=","+combo_box.list2.value;8 s# u0 o4 l+ O' n3 B% J# C; t0 ~; C
  }
4 s: ^! @, X( y1 T0 r+ ]  if(val.charat(0)==","){
, ?! C) Q- x/ z3 z7 `8 Y   val=val.substr(1,val.length);" g: c# Z$ ?3 q9 |" s8 Q9 v
  }
9 f, L4 k+ X' ]  g  opener.form1.frecname.value=val;
) B8 M( X& e! U  self.close();0 M$ W( ?$ l/ V4 h9 C! {0 Z
}
$ u( D* Y( N8 m2 ~8 z) u" H/ k* u//-->
; e# z$ n3 f: v# e" `</script>: Y3 T3 G2 A* }
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">/ r8 p: p, u' k, M$ p
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />$ \' Z4 p4 ~  ?' A, k" v
<%- P/ n& {4 R* S( `3 X
  cdatasource ds=new cdatasource();  //数据联结bean实例
2 T- p8 y. S# I5 s0 e9 O  java.sql.connection conn=ds.getconnection();
  I6 a8 R  J2 q9 C  java.sql.statement stmt=null;
0 s: Z  h* ]7 R0 ^5 K7 K6 O% Y: D9 F  java.sql.resultset rs=null;+ h' f* }4 x* s0 h, i4 h3 C  O5 U
  cdatacheck dc=new cdatacheck();
  _5 Q6 b. |3 ~! [4 M9 q%>! n0 g) u! u7 R4 a+ @, v
<%9 }! r3 d& x- S2 T0 J8 H. }7 _2 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";( N1 e) |  A6 I5 F1 s- r; x
stmt=conn.createstatement();+ X5 M5 i) A7 v+ P% N- i  Y7 P' W
rs=stmt.executequery(sqlu);
$ u" d1 S9 R5 W* [%>! I4 `9 K  l) [; b/ Q
<script language='javascript'>  |$ B* E' H; R4 e2 N
arr = new array();
: S+ O- v$ ~, [: A8 h' q<%  int temp=0;- B1 f: L, x5 M. G" t
while(rs.next())/ E& x( T6 X3 D" ^& n
{
' V! F8 U' K# P+ F( ]( a% l%>
8 k9 i5 d& b6 Sarr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");/ K  D' r. k) i. b
<%
9 G3 \; O8 S# ]; v; o( }& i/ ^8 M4 I- |temp = temp + 1;' B4 G( ?( n# S. P3 U& z
}* p: F2 _3 z; O1 [& x
%>1 q7 m3 Z2 F8 P+ H6 ?% x2 j
temp=<%=temp%>;
8 k# R- O0 X0 t5 m* @4 ~function changelocation(id){ + o' f/ c0 ~) q/ q/ K
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
2 @2 B  l5 W0 E) w% i5 ?+ vvar i = 0; * s1 A, l% j( Z$ \+ d" r3 T9 e( L
document.combo_box.city.options[0]=new option('-------',''); & `! E/ a" o& k8 r
for(i=0;i<temp;i++){
* e- X+ @2 [& rif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
$ |, c0 j5 D5 C$ G7 f* |' gdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); % F! n% s+ v6 h' M
}
( N! a6 i5 j- d3 H( M9 z}
6 o7 R) z/ ?, H4 u}
% u* H8 ~. V" M* c. s</script>
" d/ e  H: R9 h& r+ I5 w* P+ V
; J  t" Y& X$ ?: N<form name="combo_box">
) d' j- c0 ^% x7 z- N<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
- r$ t  I( G7 b6 |0 u  <tr height="24">1 y. ]' U7 {0 J* i( Y
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
1 e3 K- l$ }* x- a' J1 d    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
- j, O9 J& N9 p! j8 @    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>( p( i- w% S/ s" z* C" D
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
: m- V5 d3 J3 G' q' G  </tr>
, g! C  Z) ~7 m# Z0 {  <tr> ! u7 a1 [+ w& u9 I- u' P3 ]1 N% S
    <td>
9 v/ p3 x" |7 {" w' p; M( l% j5 k* b  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
* r4 }0 t7 `; u8 p/ I7 c  <option value="0">请选择部门 ---></option>3 v; ?7 F+ `! S, J7 B. K
<%
" Q" s& C" }8 g- {9 J$ S    string sqld="select * from tdept";
- u0 `5 T" o4 H$ W& F  I$ nstmt=conn.createstatement();, t5 {+ u; t- R! R
rs=stmt.executequery(sqld);( p5 c, S% N9 F
while(rs.next())( Q% F4 b0 L; \0 Q% Q# [2 b3 l0 Y1 m
{
7 E0 k9 U' M$ E) A%>7 W2 _' m& m- B, f) _
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
+ @& s* F6 m6 v$ j9 h<%
6 M% [3 d% K: w}" G, t" k: m- J! B- o: N
%>
2 N; `1 l, n9 j  </select>
) ]9 M+ i- q0 D0 b. E</td>0 W3 E( j2 r1 P8 @7 ^! l
    <td>4 C! R5 y/ ~$ o6 T- T' c# a
  <select multiple id=city style="width:150;height:200" class="bgc">+ ]+ e5 N' F; k' K; `
  </select>8 I/ D2 ?! ~/ p% v+ q2 v& A
</td>, A9 Z% Y% g, o
    <td nowrap align="center" class="bgc">9 S0 |) E' ?" T4 P. A1 e( l# Q6 d: H
  <input type="button"  value="<<" class="buttons">
* l0 ]3 Y* n7 p$ ?9 n6 U6 y  <input type="button"  value=">>" class="buttons">- J0 k8 _' z' [$ ]1 t
</td>* `0 E) J: r" t. N, M" ?8 X
    <td>
! j+ n1 q3 s% ~3 M" F  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">$ Y! P6 T* ^' O- Y$ r0 k' z
  </select>2 c7 R- ~8 o/ E5 t
</td>0 U: q% Z0 q) E1 q* d$ ~
  </tr>
& `# i$ w/ M3 ]0 `    <tr class="bgc">
) g4 M+ X# t9 ]' a6 x; l/ q( m    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>1 v; h5 G' E8 y6 \; ?0 y, S' Z* }
  </tr>* G1 z7 H$ @4 V& e5 F6 K
</table>$ T  `$ \9 I; \+ C1 Z& b3 i
</form>, c% y7 z  |" F, N( M
<script language="javascript">+ T. Q+ F: y( U
//人名移动1 {. ?# V- ?8 \& q" `$ N
function move(fbox, tbox) {
9 ]6 s" i" ^4 xvar arrfbox = new array();
; e( U" E7 w7 h  {( u- A8 nvar arrtbox = new array();
; N* P2 n0 {9 g, i. k; y3 ~4 wvar arrlookup = new array();' _: R* h) O+ L3 h0 V5 `
var i;# D! u9 m: U5 C. K2 Y
for (i = 0; i < tbox.options.length; i++) {. C# V  J4 `; M+ C' r) n
arrlookup[tbox.options.text] = tbox.options.value;# M4 N/ J- H# s1 n
arrtbox = tbox.options.text;
2 \- ^+ ^- k$ c4 f- [5 R}
) @# \0 F+ y; b' U' B" Yvar flength = 0;
) N7 t. t; F6 T6 |var tlength = arrtbox.length;4 V/ Q5 p) ]; Y$ S2 {
for(i = 0; i < fbox.options.length; i++) {
; z0 M9 l' p: z! f) ?! v  Iarrlookup[fbox.options.text] = fbox.options.value;
: ^& X6 n. ~( x0 y) P5 }9 {2 _if (fbox.options.selected && fbox.options.value != "") {
, o5 o9 w( y7 D' ]* C8 o+ Jarrtbox[tlength] = fbox.options.text;" ~- M8 ~8 ?. u5 `
tlength++;: z# l& I) B8 L3 z# F' L; R
}% C$ F5 r6 b3 y4 K, U
else {
8 h" N' N# w% `3 Z# F+ m) e: oarrfbox[flength] = fbox.options.text;
( L& X$ |- ^  o6 Z8 r' Nflength++;
1 z' o$ X/ b8 X. D% D. E   }
) T  }! \. n5 M( I1 X}0 Y+ B! Y; }' e3 I+ B. V' e0 x
arrfbox.sort();
. e! W& v9 {7 A; p2 m6 |4 xarrtbox.sort();
& @0 @* R. n/ o- r$ e5 C
2 b8 }, h3 Q* sfbox.length = 0;
% o8 c- k4 Q9 [tbox.length = 0;
% @8 l- S* s( d5 t. kvar c;- A) |* f5 S  C7 B
for(c = 0; c < arrfbox.length; c++) {
: _8 A& }" L, S( p! ?9 ~! _# ^0 jvar no = new option();
' y7 [  e# I7 rno.value = arrlookup[arrfbox[c]];; |) |& o* [& b3 I! m& Y
no.text = arrfbox[c];/ z6 I+ W9 N7 f/ M+ u
fbox[c] = no;
& I3 {' A" K7 j' j}
$ D/ N6 l& W5 u3 b9 hfor(c = 0; c < arrtbox.length; c++) {9 D5 h4 U  \7 [: Y8 O+ V/ n
var no = new option();4 b# M# t8 W$ ^7 c8 B
no.value = arrlookup[arrtbox[c]];( V% o/ v3 v" Q# B
no.text = arrtbox[c];
- J3 _) m$ K* L, p8 ptbox[c] = no;# l2 \% C% _+ l1 N$ l# X- n: C
   }6 _5 U6 B) ~' W' c8 j3 ^
}
0 G+ d3 n9 r6 D</script>& i& R8 u% V$ b$ b! v" f( C' t) A
</body>
8 l1 T/ P5 E8 `$ E

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