返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
- b# g% D2 Q; s6 d8 H         c pageencoding="gb2312"
3 P0 U" o1 @( M+ K. k% L%>5 o* h# Q# j  b7 d* Q  W
<style>" L; |" U) U- A: z5 u
.f9{ font-size:9pt; }
5 Q5 o+ T1 g/ [2 V+ a/ k3 L& i.bgc{ background-color:#aecaf9; color: #0033ff }6 q- @4 \5 P9 J% g/ a. }+ `
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;1 N" m% g7 M! ^8 i! ^
  border-bottom: solid 1px #4e7dc1;
& u0 U" L- T1 K) |. t7 n: X# I* z  border-left: solid 1px #aecaf9;0 b7 `: }0 X8 C- O' o
  border-right: solid 1px #5679bd;, E1 M4 o, I  B
  padding:1px;! {4 N1 k7 T  S; O7 l
  margin:0px;}
5 p% [4 _2 b! U  z</style>6 H+ C" @3 [6 B6 G" Z
<script language="javascript">
% e; f* P' Z! ?# B" l& [<!--
' a, d6 p% i' |+ d3 ufunction rv()1 v- h% X' d* ?# x2 q: b
{
& Z% U, W7 P4 b) h) G6 O  var val="";
& K" K4 t. @- ]4 I5 Q" N, E# S  for(i=0;i<combo_box.list2.length;i++){6 W1 h4 z! ^) [
   val+=","+combo_box.list2.value;
" }7 |5 `; |! C0 G  }
8 ^3 P. V/ G! n+ {5 ~) N+ @8 B  if(val.charat(0)==","){
" n3 j9 A6 }, f4 ^3 z. C1 k# g   val=val.substr(1,val.length);# z8 J- Q6 v4 y0 C9 e
  }9 u2 P1 H1 |; ]8 a5 f/ D4 a! ]0 r/ M
  opener.form1.frecname.value=val;
: @4 V! a5 w% Z  self.close();- ?# X+ n/ Y/ N
}
- A( t. D( U2 v% T//-->( \2 B# i0 W( G! k) t( q
</script>. g  E; J) E( _* g
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
5 x5 B1 d5 v+ u. _! o8 t9 ]4 c<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />. E. s6 f. J. B7 z' P% T4 h
<%
/ A) Y$ C5 Z: \. U  cdatasource ds=new cdatasource();  //数据联结bean实例+ G0 j; H0 \( [) l
  java.sql.connection conn=ds.getconnection();) V7 [' p: M5 q4 ]* q
  java.sql.statement stmt=null;
- O5 Y" y0 l5 l8 C+ B% B6 d+ \  java.sql.resultset rs=null;
+ B3 a7 f% z5 O. y! X5 S2 ~  cdatacheck dc=new cdatacheck();
/ p2 `8 a' r' M# Z4 |7 w& g) H%>! T2 I: [9 J+ m$ U' \. Q1 j# J
<%! q5 i7 l! V. q. U; m# }
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";
4 R+ p  F2 L  H' r; a3 U9 Vstmt=conn.createstatement();1 e6 }1 Z7 D: \
rs=stmt.executequery(sqlu);5 o1 Z' e. w0 c# V5 Y8 s. U
%>
; h0 Z7 c! {0 L<script language='javascript'>
) |9 }8 U$ w( I+ Y( g: M- farr = new array();, Y8 R' d# z2 E& C7 B# v/ c
<%  int temp=0;+ ~, Y# o+ c- Y. h- O. @" w+ R. p8 @
while(rs.next())
$ a- o. |$ ^! \7 ?; t, n, a{& V3 U! c& D2 z, h' ]; E% _2 ^
%>2 e6 p/ j& J" u; B
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");! M+ W! g4 G# R3 Z' J
<%/ q$ Q; @! M* `/ B+ w5 U, C
temp = temp + 1;
8 w2 |8 K$ C' ~( J}
/ A3 H; f+ j- g- g) V  h%>
' {, c9 S" J) X) rtemp=<%=temp%>;: P- B) D0 C6 m( ~7 E3 s2 l
function changelocation(id){ / _7 K) f0 b2 Y6 Y
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
) f) n8 n2 d" A, E$ y: Vvar i = 0; 8 f, I- b" O; g/ V9 @2 G: R/ ]0 z
document.combo_box.city.options[0]=new option('-------',''); " g" J+ G/ k  R& C8 p7 S
for(i=0;i<temp;i++){
+ [& s8 x5 ~# ?if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] & ?* M' K1 m) L! \0 P1 E" z% U; J
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
! C9 }+ Y! I& P* t; X" H} ! H( J( y. K+ c7 p* I9 s
}
; w5 |( d5 ]' D% q3 D}
# z  Y2 |, i- o4 x! @</script>
1 x! E* L  ?# ?# K2 B# M) [3 g( F: j! _1 s; Y2 n
<form name="combo_box">* @8 x* K* u) h" X
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">" p5 \; a7 t9 A# O: n* _2 H9 m& R
  <tr height="24">9 a) [( c. x* `
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>- q3 {+ M7 [( e8 A0 b8 N
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>
! [, O0 j: N5 o" @6 k' F( _7 {2 g    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>2 I  U1 @7 M4 v$ w! B* h
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
, \- O9 _& O$ I/ N& U9 w6 q  </tr>
4 V! O! T  I+ H% I4 e0 e) R. {) T  <tr> ) @% [- p1 z% t9 i# Z2 H4 Q
    <td>
' ]/ a) p5 Y) K, @# E5 \3 w  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">
* A6 L8 y4 P6 k! K+ l5 m5 S  <option value="0">请选择部门 ---></option>
/ I; k$ d2 b& ^4 j<%! N* W- y5 ^  K: ]" d3 ~% m# h
    string sqld="select * from tdept";* k* r( e2 M# p, ^" B  z) _
stmt=conn.createstatement();
! u$ L: v1 P& n, ~$ Crs=stmt.executequery(sqld);
; J. y  o' T8 J# Owhile(rs.next())( m' K$ F. }. G, a+ U, |
{
' U1 T' n) N4 o% g( W%>
3 p8 `7 z! ?0 |; J  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
# [5 ]/ N% F( l2 i3 \' h$ s<%. k5 N! H7 H% F1 |. K. e
}
7 |' ~3 J# [# P$ d%>
, W9 K# g1 i5 \7 N: l( n- o8 q  </select>
3 S" U9 a( l, n) W$ U/ I/ u</td>
, m2 ]  a8 X2 E3 E2 c    <td>+ O) G/ v- |( g$ n+ d2 ?. I: e
  <select multiple id=city style="width:150;height:200" class="bgc">
8 x( i2 {8 [& |  </select>: c- t3 l+ I/ r2 X
</td>
8 y* D( g3 l' B, K    <td nowrap align="center" class="bgc">3 r7 r1 L% p( W2 ^
  <input type="button"  value="<<" class="buttons">. A" a7 d. u' ^( N
  <input type="button"  value=">>" class="buttons"># h8 X) v5 I( K1 i. R3 Y- h0 @
</td>
( C1 b9 Y3 f" n! p' h    <td>
1 |7 l6 I6 d5 S% P) Z  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">; {1 I4 h! Q/ P) }; Y
  </select>6 v4 M- C: A4 H
</td>
$ h) K  Q7 k8 e% _* e  </tr>
6 h% F8 H6 h8 ?- s    <tr class="bgc"> * b' l& g% }0 e8 c& o+ q
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>
$ y* Y1 f2 M* v/ Y: U- b4 ?  </tr>
6 a& x( h3 j8 C6 L9 z* R</table>7 E5 o: u3 p9 A1 V% a+ B- [. O
</form>! n  q" A) r5 Q3 }7 I9 j
<script language="javascript">
+ p. |' w( w* G4 p6 z//人名移动
+ G) {# U$ ]# S$ Afunction move(fbox, tbox) {& Q( P# v/ j% v$ Q' h
var arrfbox = new array();2 Z- j1 c+ S! |0 R5 H
var arrtbox = new array();
# i1 B% c& R6 z& ?5 S& qvar arrlookup = new array();
. P. K: w& Y& n. Z8 }, cvar i;
$ e$ Q  u5 l0 B" Ifor (i = 0; i < tbox.options.length; i++) {8 @+ |6 X9 h! O8 v- w: i
arrlookup[tbox.options.text] = tbox.options.value;
$ n' ^9 h! H- larrtbox = tbox.options.text;
7 ^( W% Y3 q0 M9 m# v+ E9 S}
$ h1 C0 G- c' x" s  q) _+ @6 Mvar flength = 0;
( e; i3 t3 ?* T: m+ u$ @8 I- ~& P7 x3 tvar tlength = arrtbox.length;
4 g  K( W. h7 @9 Pfor(i = 0; i < fbox.options.length; i++) {2 I  G4 K- j" k1 E' k! I
arrlookup[fbox.options.text] = fbox.options.value;: ^" \) t+ c- X/ X- E4 ~# e1 T
if (fbox.options.selected && fbox.options.value != "") {
4 b  W( C6 N  L3 r% y+ Karrtbox[tlength] = fbox.options.text;
0 M  {/ x9 I2 {9 [5 b4 ktlength++;/ d- E. [1 r) D7 f5 ?, [: }- J( `
}
' H% `& m# C8 \* Welse {0 i& U0 u3 N% |9 ~9 I; c5 O
arrfbox[flength] = fbox.options.text;
9 Z/ H8 S9 A( pflength++;: u1 B  ?, _1 |7 |9 f& y, |+ B6 b
   }
# w5 l& P+ M) u/ }" {2 q- L& G( ?}
. ]1 @6 S9 V  v+ \9 aarrfbox.sort();
% E) t* o3 `; narrtbox.sort();
2 N, B  N; f4 h# E6 ?! Y  \! n9 D, k7 _
fbox.length = 0;
- S  ]0 @* `* E- C7 X2 d0 P* Otbox.length = 0;3 B/ W+ @$ h& }: c0 o& \
var c;8 i3 `" `" w' D) c
for(c = 0; c < arrfbox.length; c++) {; p9 V4 j& P5 S, t1 h
var no = new option();& |& P4 Q: [6 P& f
no.value = arrlookup[arrfbox[c]];
1 R6 P& \) ]7 Zno.text = arrfbox[c];$ _- ^" K% Q+ Y% f
fbox[c] = no;
0 Q8 [) N2 e" Y7 G' v. K& ]& d$ |, \& p}
- K8 M* [- N; }+ e; E% x& R* hfor(c = 0; c < arrtbox.length; c++) {6 L3 r: B* H2 h3 I9 A1 Z2 s
var no = new option();
9 |5 ?. e- P1 Uno.value = arrlookup[arrtbox[c]];
8 b$ k1 Z  K/ H0 @no.text = arrtbox[c];
! C1 h6 H7 ^$ }" f( ltbox[c] = no;7 U" h6 m' a) O7 s9 R' D6 p
   }# j5 _7 Q* K4 [# E  _0 f% X
}
1 E; s5 I, u2 E4 k' V( u</script>
& d' y( c- g' P# P5 \4 d</body>
$ l" b  b5 M7 u3 ]/ {

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