返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"/ u: Y8 {: a6 Q' P7 t) V1 _# B9 W! d) z% ~
         c pageencoding="gb2312"8 g3 Q' l6 ~" ]0 y0 x2 o, b; R
%>
8 C) ^( I% t3 T- Q' Z<style># a6 X; N/ O0 i8 M% t
.f9{ font-size:9pt; }
5 W2 P6 K' Q4 X: L.bgc{ background-color:#aecaf9; color: #0033ff }
1 ]% E6 T/ ^& p0 h' Y.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
% w  D# {# _* l- ^" x( |  border-bottom: solid 1px #4e7dc1;
6 J( B; Y1 D! y5 j  e  border-left: solid 1px #aecaf9;! X* r! G# J- R5 ^7 G
  border-right: solid 1px #5679bd;, W' |8 K! R0 L' H) o4 m- ?! R
  padding:1px;( ~% C+ B3 h# ~0 O# N
  margin:0px;}
+ O2 E( t& Q, D! V1 s4 |5 G</style>8 d4 M, y7 B( w$ G% T; n: {
<script language="javascript">
/ H* v; M. q' K. X2 D<!--
2 w4 |2 C1 L& s. |7 I+ \: Jfunction rv()
# m# F5 ]% [, M: J: X4 `{
$ ^3 _; N  W7 g0 ~( r2 r  var val="";' ], ~. M! X4 g( o: ?
  for(i=0;i<combo_box.list2.length;i++){
4 U" f. L6 `: n4 H$ v   val+=","+combo_box.list2.value;
+ @, `# ~6 K4 V/ i& I. B9 U  }3 L  ?, M8 S. \
  if(val.charat(0)==","){
5 ?# H9 \" M4 ]; |5 n/ E* |4 P1 N   val=val.substr(1,val.length);( I8 j, k" z3 I; H- f
  }# G$ R! ]7 N9 ?( I9 s1 o0 s. b
  opener.form1.frecname.value=val;( v/ |( a, a% Z2 D' z  w5 J+ J
  self.close();1 j& k- d/ h& c
}
' i' c# b( L3 ^, u//-->
1 P$ m/ f+ D. L' V* D* }</script>
0 r1 G% `$ {8 O<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">5 y% O, V+ m2 G3 O3 b: u. h
<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />
/ G% d6 w% ^( m7 s7 c) U<%! t4 k) O  B! H( x: l! J9 b9 S
  cdatasource ds=new cdatasource();  //数据联结bean实例5 j) Q! k4 R7 V" d- L' }
  java.sql.connection conn=ds.getconnection();7 ^' y& b+ h% x/ k/ r! i
  java.sql.statement stmt=null;- \3 K9 [7 a- N1 a( x% w/ ]  G
  java.sql.resultset rs=null;
# d9 s# w( y4 ~+ y/ r  cdatacheck dc=new cdatacheck();! W3 o$ H/ k+ o1 [
%>
( q8 s, |  B- }<%% f8 x6 B; U3 g+ h* u% z. d! R9 l
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";
6 F" B) {0 |! ]1 Cstmt=conn.createstatement();6 n; P3 H6 e0 R( L9 T
rs=stmt.executequery(sqlu);
1 O/ I; h  J: X$ E; m& n4 H# y6 ?%>! P* j6 E" Z) h( a7 E0 [0 S
<script language='javascript'>
: ?! I: D( L7 ?) p/ w, {arr = new array();
- O' J9 `# s8 z$ w& k: R# Y<%  int temp=0;
# Y. V) R9 \$ f, W3 o" uwhile(rs.next())
' w% J9 W& m; Z$ q5 @! t& u{5 W8 M" Q$ G# A3 R6 W- Q8 C4 p# Y$ [
%>! c  |' y( ~- G# x8 O  E9 H
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
. c" A8 k! `& j<%; e8 r- I3 B. Z, ^4 _8 S; V" m6 A' `
temp = temp + 1;
' c0 M( w) N6 r0 ~4 J8 m; p, t( Z}
- A, r6 K# {* z) w9 c" r3 U%>2 @9 G7 X1 X5 t$ o  `
temp=<%=temp%>;
' s1 H6 h; O4 s' }function changelocation(id){ 7 M; c) S" U; v* w6 U- b
document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 ; A( j8 r0 J1 D9 w$ u5 a
var i = 0;
8 t- W, i; Y1 J# |document.combo_box.city.options[0]=new option('-------','');
6 ^% c& O6 ~' q3 ~- M- ^for(i=0;i<temp;i++){
6 ^! }7 j* _1 Q, G7 k$ eif(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
2 U& p& d7 c# M1 L/ z5 J9 S' u2 cdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]);
& |8 [8 [6 ^; L6 S7 [}
9 B; |) T6 y0 N/ }# E}
& V& k& `% n6 V6 a: I' k" P+ ^2 `}
" n$ ^8 B, W6 G5 j9 h1 g6 p</script>4 ]- v% q$ g" _7 ^

7 q/ ~% D+ i2 W5 w( r<form name="combo_box">' P, m5 a  j( k$ J
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
7 I2 z" X6 V: f; D8 F7 }  <tr height="24">& Y9 T/ k$ r5 ?7 |: P% M+ O% X
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>
2 c$ A8 Z( V8 [; {    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>8 n/ g( Z1 C  r6 a5 e8 b4 H
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
: ~7 w( T, G9 Z  b; m    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>
& S5 X' h$ j4 q# J) ^4 |( _  </tr>9 }* |4 O8 f0 n7 P: k3 O
  <tr>
# P8 k8 i2 R) I8 {8 Q, Q* a    <td>
( Y# m& T2 k8 m* A% w4 v$ X+ `; o  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">3 [' p" _6 f, Q0 y. s1 k' k0 F( y
  <option value="0">请选择部门 ---></option>
- Z; D# U, N' U7 }! l$ S<%
3 x1 Z' m) `) J! E- ^    string sqld="select * from tdept";% }; H- ]! e- c! E
stmt=conn.createstatement();
# B2 s8 ~* H( `rs=stmt.executequery(sqld);9 z5 ~2 d' i* R. e' S" M
while(rs.next())
% z% t, T: \& F{
9 L+ f6 U+ `( c& E%>
1 _) }- W7 p4 E* D5 m1 g  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
! Q8 ^1 @! I; U3 J<%" S6 F  ?% j5 N  @* Y, }
}
3 b9 G1 F; L# k& N6 C2 ~* r%> . N$ g2 j& G2 [9 |4 C
  </select>0 N# J3 x9 _% ]; V6 \- ]1 e* K
</td>) d: B) e+ S. [# Z: P8 L3 @
    <td>% p- Q8 p, ]5 `# ^
  <select multiple id=city style="width:150;height:200" class="bgc">
8 R& j* ?# p0 Q$ u8 E  </select>3 a# b$ ?4 }5 o5 z0 b9 g4 ]9 j
</td>2 |8 B% l$ P% h/ L' x& N6 X/ H0 W
    <td nowrap align="center" class="bgc">
! _6 j/ l5 K& D  <input type="button"  value="<<" class="buttons">! Q$ Q( o1 D) L: a& S
  <input type="button"  value=">>" class="buttons">
- m+ O* T3 V; g' L7 P</td>6 z, q3 g( p# p6 x. P: j
    <td>) o! T* w9 X- t& S* c3 U
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">2 A9 E, [* a0 d$ h; |. c
  </select>3 `" H' _& X+ X/ Z% g
</td>
) ~  `% @7 [: F1 s+ b2 @( I; G, P  </tr>) _5 k% }; n* v; O* r- L6 n- k5 i
    <tr class="bgc"> $ e  x$ v& P# `9 p6 i2 f/ o2 F
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>" A, j1 r$ t& O" u' z3 z
  </tr>& ]4 E9 V! i0 Y3 A% P/ @6 b
</table>
8 |0 Y) I0 `) J2 c</form>9 |1 d( ]4 S9 T6 D. e
<script language="javascript">
- m; ~, l# v  ]3 H1 J//人名移动3 `$ ^: `3 D1 d- W! Q. G/ h; P
function move(fbox, tbox) {3 b& E% }9 K) [; ^, S2 N- q
var arrfbox = new array();
1 W' {8 k. R, f5 {var arrtbox = new array();
, h$ C& d" {/ zvar arrlookup = new array();3 h& W8 o* B) W
var i;  d4 o  u8 E1 U- J
for (i = 0; i < tbox.options.length; i++) {
: y) a: U$ I+ U  [8 T0 narrlookup[tbox.options.text] = tbox.options.value;- a/ \! C* H. y& F+ Q3 ?
arrtbox = tbox.options.text;
6 K6 E4 J* h4 O) S" _! z) b}9 a2 Q8 [# v  k2 w5 s2 [
var flength = 0;4 M0 b8 Q& h% a% y5 X
var tlength = arrtbox.length;) r8 p$ w$ u! Q9 q
for(i = 0; i < fbox.options.length; i++) {# j4 f0 z$ @( R! _8 K' E
arrlookup[fbox.options.text] = fbox.options.value;% C, \1 z! i1 X# ]
if (fbox.options.selected && fbox.options.value != "") {8 f) D6 n" t* d. H# @% v
arrtbox[tlength] = fbox.options.text;! ~2 c0 K# E1 ^. M" \# w7 B
tlength++;3 g" ~/ U- i, `
}5 M5 [, O& y$ }; Y  {) ~( J* e
else {" T  L) S. ?& i* q
arrfbox[flength] = fbox.options.text;
* m/ J1 Z+ h5 o0 P4 n6 gflength++;
/ Q- @- g$ z% V% R$ c   }6 i/ e  W6 g& [' a6 [$ F
}
1 }( J5 X' R7 g8 Y6 J% Tarrfbox.sort();
7 X4 Q" w# f5 K/ tarrtbox.sort();
) n2 T) Y) |" I2 p8 K: V3 i) Y7 s8 b4 ]) D/ B+ b) G7 e
fbox.length = 0;% E4 Z) x7 V6 l
tbox.length = 0;* y0 G% r8 |9 u0 ]* [
var c;8 v. n2 K( v. I1 u! u
for(c = 0; c < arrfbox.length; c++) {
' S; p( m# }, ?2 Y  G) |: }  zvar no = new option();$ d7 V. ^$ N1 g. L* A) @4 [
no.value = arrlookup[arrfbox[c]];( P2 g7 O$ H7 J) C/ a
no.text = arrfbox[c];; m) B( X# F, M* @4 _# ^) T2 ?
fbox[c] = no;
6 O5 g2 s5 ^# G5 J  G( l8 K! z  P7 l}
9 N1 {: d) }$ k- t+ w% k' d$ [" Vfor(c = 0; c < arrtbox.length; c++) {  J' K! t. r! X1 U* P: d. |% C' y
var no = new option();7 E" v1 A. P6 Z/ P( X- A
no.value = arrlookup[arrtbox[c]];
/ Y9 y- E+ Z2 T) P# Q2 G9 pno.text = arrtbox[c];
4 ^+ [. k3 f6 @4 U  G- ~# p1 Mtbox[c] = no;5 a( }! j! r$ Z+ U& R& X0 ^* }
   }5 c: z. Q& F# U2 _0 p
}
0 h4 c6 u+ j: p8 o</script>
4 n2 n( x, M) e1 }! i</body>
: @+ F) ^  U7 m7 r

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