返回列表 发帖

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"
1 g' Q. }+ K7 U- z9 a+ k* Y3 N         c pageencoding="gb2312"7 Y6 `3 e8 m% R# |6 w" N
%>+ ~2 T9 C* Q; p
<style>
' h* L/ y; o; Y4 W.f9{ font-size:9pt; }! }  J/ I, F% d3 l# {
.bgc{ background-color:#aecaf9; color: #0033ff }3 d6 j8 Y+ S% |  j& K- V5 C
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;: M2 V3 E$ g; A8 S$ q3 Q7 O  T5 n
  border-bottom: solid 1px #4e7dc1;
: w3 O  H: P0 @) N  p/ F1 P  border-left: solid 1px #aecaf9;
& Y9 z: Z5 m( t  border-right: solid 1px #5679bd;; e" o) w  ?4 T; P7 j. e2 t1 H7 H
  padding:1px;6 M6 \' Z/ ?8 Z9 w( Q
  margin:0px;}; o' s% Z1 G; \3 g
</style>$ i" U  q; Y3 P& o$ W! W  [
<script language="javascript">/ f; P% _3 F+ {* D0 u4 ]
<!--
) y. }% S5 {) H4 u: hfunction rv()
7 [8 |6 H9 P% ]5 c, }{* Z, t, p: i- I5 b1 C) D
  var val="";+ Z7 O6 v- \; d/ ~3 q- c6 f4 I. C" Z
  for(i=0;i<combo_box.list2.length;i++){% W% ^/ r& G; v1 k8 s4 K; q
   val+=","+combo_box.list2.value;
) g) [, G$ \3 V6 K$ c* n# i  }0 W& I2 C8 Z* j# E* |: _9 |
  if(val.charat(0)==","){
9 D9 @2 \; }0 r' k; B; v6 A   val=val.substr(1,val.length);% t, @" L7 x: {2 j
  }3 t* k% Y+ k) t- H1 V
  opener.form1.frecname.value=val;
) e7 _5 m" a% a5 I. F! r# A0 I  self.close();' U9 O9 h0 U) C2 A5 Z& Q
}- ^. X+ \* K- {& l& @8 J- i1 p
//-->$ N$ D2 ]' L" z/ L* Y: @6 u# I7 L
</script>8 V- n! f: Q8 K2 c0 Z
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
/ I  b$ i+ A: y+ g( [- G/ p7 S<jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />9 A6 d3 d. _; @) f/ ^# h4 T
<%+ q- T4 D, }4 n" O
  cdatasource ds=new cdatasource();  //数据联结bean实例
4 Z9 ^  l2 F6 N( E) s  java.sql.connection conn=ds.getconnection();
' C! \% y/ |6 C7 m5 o  java.sql.statement stmt=null;
( ^4 t! _$ u& ]$ K  u, ^  java.sql.resultset rs=null;
/ z4 o( J! U4 ^& L$ P: i, {8 A  cdatacheck dc=new cdatacheck();! K! X% J$ o4 _8 G! }
%>
3 j. l8 h. z. x* G: Z( _<%7 m/ Y$ L$ N8 D: z' A
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";3 N, o  }6 G( N
stmt=conn.createstatement();
! c2 t6 Q8 k; A% Lrs=stmt.executequery(sqlu);
, ^: A, Y, B" R* C" y%>
( H3 I2 X6 n# V* q  `4 N<script language='javascript'>1 U8 j  K6 Z  I$ \
arr = new array();2 Q& {+ C# E- {, F9 n
<%  int temp=0;
$ [- O' m8 z/ Q  V; uwhile(rs.next())5 B: c/ j' U1 s' t( A7 L
{/ X. P5 k5 Q" _* J+ `3 g' c4 e
%>7 p- C( C2 F% P  h/ ]7 \1 R
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
" J& D5 c2 l# R1 o7 s7 W, A<%
- v: h+ T( }( y% ctemp = temp + 1;( g2 V0 e" c2 z, y8 ~( }! s
}. u. u' ~6 E8 d5 b( N- D5 c
%>& i! s; a4 I# z  Y
temp=<%=temp%>;5 f4 t! z+ E. s
function changelocation(id){
1 B) ?8 S$ I6 h; \* }document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始
: f, `4 ~3 A7 y  lvar i = 0;
: j7 C7 l6 R9 `% F: ]; l6 Q! _document.combo_box.city.options[0]=new option('-------',''); ' Z) a, h" A, C& V" V& A9 T
for(i=0;i<temp;i++){ 8 B; a& y0 }5 R) ?: L+ r1 m
if(arr[1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门]
/ h5 L# p2 h# Z; q* y& p& ]$ _) Cdocument.combo_box.city.options[document.combo_box.city.length] = new option(arr[0], arr[0]); 1 I1 {* D( o, u3 Y/ m5 |2 Y9 m
} , [' |6 X$ g7 Q: a
} ) D4 _. I2 {- U! ~) q
}
! }$ c' L4 m2 y3 ^. x! {4 a</script>
3 X. w/ _2 }, i& V1 K; n' A: Y& W4 F0 W9 J' ^$ ^* r- X
<form name="combo_box">- S5 D6 ^. j5 Q& d" X" C% L
<table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
) ?( d5 t) @  S& l; N% c  <tr height="24">" o4 A0 k% v, L
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>  m- }: T4 H3 H
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>. \$ K/ ]8 n4 g& a7 v6 r
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
% C% m: t9 q/ w; V6 `% g    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>; o7 q$ n. f. a, L6 ^
  </tr>' g- N9 j, i. C; t: _
  <tr>
& w6 Z. L: s6 T    <td>
& ^' \9 b6 T" X# x  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc">* V- k. W4 m6 q2 \3 v' \' D" K
  <option value="0">请选择部门 ---></option>  ?: S4 W" P6 S+ I2 f. m
<%
! V' k0 c+ O8 z. ?    string sqld="select * from tdept";
5 N0 m) e9 D) r: [" `0 M2 astmt=conn.createstatement();
0 n* c' z7 a6 u3 I; ]  U6 irs=stmt.executequery(sqld);5 P9 W) V9 r- N) I. C; z! D3 W! Q
while(rs.next())+ ]0 ?( }0 H( B( J' O4 c: _
{
& J1 n: N" y) E%>
3 k0 L" g: S4 @! C8 E5 @0 Z& \  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>4 g' j3 g. M7 q5 j) _
<%' q; Z, y% [2 N* f: i
}
3 `" f5 X9 u# f+ {%>
- C* p; {0 r/ o8 T  </select>0 k$ C. v7 w* m% a! w) a
</td>
- u4 |- g: @- k5 u. x    <td>
8 b5 m% m" i2 s+ _6 E  <select multiple id=city style="width:150;height:200" class="bgc">9 X9 N6 b' y. Y1 U! s; C
  </select>
9 {& X( V- ]/ J: d% q5 c</td>
1 P7 v5 R& ^8 n7 t$ c6 O" n% [    <td nowrap align="center" class="bgc">+ u4 N+ h; y2 Q' h5 f( s
  <input type="button"  value="<<" class="buttons">- U# `9 t4 ^( J, n. g( o
  <input type="button"  value=">>" class="buttons">" P. h; O0 G5 C, h
</td>9 B1 G2 v8 \6 h* _
    <td>
) h0 k- Z+ Q) x8 B. I" q8 W  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">% C8 ]5 D3 h8 H, w3 V
  </select>! ^& e3 f; l6 y) I) i: ^
</td>& k+ L/ A) u) W( ?7 V; |) W) ^1 P4 D9 |! t
  </tr>, O, j# @+ ^, \0 B0 a! o6 e& v
    <tr class="bgc"> , C; ~7 E8 A/ E  }3 {# |$ r
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>$ L# l/ {6 d; I: F$ o" \3 f& o) G+ S
  </tr>& [1 H" o# {7 U; s+ v
</table>/ h4 z# N; H% R5 N0 y
</form>
" N4 [, ^# i! l  n3 ]7 \<script language="javascript">' \8 N% }/ L0 @) o& a# E  k& ~2 f
//人名移动
* d9 W2 e; D9 x1 M( g; i  Yfunction move(fbox, tbox) {
0 B+ g4 q! ~, U, _  Z: |) fvar arrfbox = new array();( P0 ?3 u: w2 D/ ]
var arrtbox = new array();) |( z- D- g! L- D5 ?& F
var arrlookup = new array();
: Y: r  D: a2 x1 Mvar i;/ L2 n+ E  ~: w' `1 T! O  [
for (i = 0; i < tbox.options.length; i++) {
. n- m, m; P8 o* q$ q$ garrlookup[tbox.options.text] = tbox.options.value;
, o/ S) |. t7 c$ h/ V1 carrtbox = tbox.options.text;
# I6 C2 V: B. k& }! Z}
0 k, ?. [7 c; ?/ B8 A3 w2 x& ^2 Qvar flength = 0;
# U+ ]7 ~. c' l& c9 lvar tlength = arrtbox.length;$ g) a3 i* M2 r% u; I! r; s% u) t
for(i = 0; i < fbox.options.length; i++) {- k( C6 ]& x6 ]9 N# o7 H' I; V
arrlookup[fbox.options.text] = fbox.options.value;
  _# I( `" v  a1 Qif (fbox.options.selected && fbox.options.value != "") {$ l$ |" X: X( u1 O, o% o2 W+ D- }* e
arrtbox[tlength] = fbox.options.text;8 |/ R4 u. z4 F
tlength++;% f; d/ H+ V' P- C1 h+ J4 p
}6 ]1 a; Y. n, D: d! x. w
else {% @8 @# i8 I; a; T- k7 |3 h8 R6 f
arrfbox[flength] = fbox.options.text;! r1 {6 W$ z) I% ^7 j' P* X0 B
flength++;
0 J9 C: o2 S8 B; S$ O8 o! J   }
, D7 h$ b, S" C  Z# [$ O}( K. o: y2 I6 K: m5 i& a
arrfbox.sort();
" }' T  U& t6 d$ E8 w* farrtbox.sort();" j; H9 F2 h( G# j- l# _- P
! Y4 B* H  W2 A5 e0 ~: [1 n
fbox.length = 0;$ A7 P# Z  c4 D/ D; B' S
tbox.length = 0;$ X' h0 C9 G* N$ M: _5 R
var c;, \3 _  s: m6 a1 w8 v% [+ u5 e/ F
for(c = 0; c < arrfbox.length; c++) {6 R6 G! B% h$ S& V8 e) g& Q8 V
var no = new option();# [2 r" A8 Y4 L" d2 k. ]  A& W
no.value = arrlookup[arrfbox[c]];
7 J8 N. Q( _- \+ j' J) N+ Rno.text = arrfbox[c];
. y, b" |0 i- gfbox[c] = no;
! u: S& k7 Y! [7 c5 @}
: G! x3 l# \0 l' x! B  q0 zfor(c = 0; c < arrtbox.length; c++) {$ F* p. T" c! X: i- `
var no = new option();
$ S1 e" L+ S" Dno.value = arrlookup[arrtbox[c]];
* F# N' s* h9 E: W7 r- [& m3 Ono.text = arrtbox[c];6 V/ {; a3 Q; T1 j1 [, }
tbox[c] = no;
6 v2 M, Q, i2 b& E+ j   }3 n* ?$ v% G/ n  N  j
}1 D) T5 Y7 G. v' a  j
</script>9 w3 t, a5 k0 `7 P8 c5 q
</body>
7 d* o  u, Q2 \, c3 u" ]0 |. M- a

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