捌玖网络工作室's Archiver

admin 发表于 2007-12-5 17:43

jsp+javascript打造级连菜单

<%@ page import="java.util.date,yava.fileapp.*,java.sql.*;"5y NY:d'@p/@
         c pageencoding="gb2312"x!N[`,fz
%>
&L#Sgz@)V(q6hU'Y <style>4qZDs;ye/\&G,C
.f9{ font-size:9pt; }I;KO$aLI$g;kB F
.bgc{ background-color:#aecaf9; color: #0033ff }S(k5sR/` x1R[T
.buttons{font-family:arial; font-size:13px; font-weight:bold; background-color:#6796e4; color:white; border-top: solid 2px #aacafb;
F4W9nq#]5o;B@   border-bottom: solid 1px #4e7dc1;
E4| |;P&\-Q7[   border-left: solid 1px #aecaf9;sSP~ y:bqZw
  border-right: solid 1px #5679bd;
4Y_5q#|]r9?   padding:1px;
uYR!G+{/wDV1A   margin:0px;}T$v6r1B%N#o%a
</style>
!Z:XXQ{N ?[gq <script language="javascript">Yy"?^F0or _
<!--
;V5w,_5U6S4e&B function rv()8D vdsy6CS-N
{
ro`Nc a   var val="";
N&u\k[   for(i=0;i<combo_box.list2.length;i++){Gg)KhN2xp;e
   val+=","+combo_box.list2[i].value;
3GYe"^m*_\ e   }
+x s1\JTM5`   if(val.charat(0)==","){
,{2_,? ^3mS-D    val=val.substr(1,val.length);
Op7gP#DC   }q0VeHw5toZY5io$S
  opener.form1.frecname.value=val;
l:M9y%`T   self.close();hH8h4m4G0T{DJ
}H/a G$v(R
//-->(r$J \6IKOP
</script>(dR4vqt
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
:O Ob7fXzmb'h0I <jsp:usebean id="user" scope="session" class="yava.fileapp.userbean" />S#I1\0?)o
<%
C+aU h!I4aMl   cdatasource ds=new cdatasource();  //数据联结bean实例y_)hJry xaS
  java.sql.connection conn=ds.getconnection();SJArxq
  java.sql.statement stmt=null;
hiL U]p   java.sql.resultset rs=null;
m(_:t2sD `T   cdatacheck dc=new cdatacheck();B+Uy+so
%>,F%v KB!u%^ DY;U c
<%+h+B9k Vu8V
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";C wU-rGP,ow
stmt=conn.createstatement();|_vTGw9nv W
rs=stmt.executequery(sqlu);c4bG2t S| o+P(qK
%>6XR5c(I3?I:xA.gG_?
<script language='javascript'>xS*C mp
arr = new array();
`P4Lh;F ryy@ <%  int temp=0;
\7G U;gP while(rs.next())"T8af?3A;X
{,F aY;G@4K]
%> a.T0ZVc o
arr[<%=temp%>]=new array("<%=rs.getstring("fname")%>","<%=rs.getstring("fdept")%>");
/i|T4L'~x2FmHL0{'n <%
7e(h [7B|c&Z temp = temp + 1;
'{J|1b$T)Y }v5hNIqOH9Uu0y
%>
"ul${5Ydy([_ temp=<%=temp%>;rz/mVS/k P.t
function changelocation(id){
$j Bx;t6e%L2|v document.combo_box.city.length=0; //初始化第2级菜单的长度,下标从0开始 3qQ[4f5c ?2OX9tG
var i = 0;
^RFcq-b1? document.combo_box.city.options[0]=new option('-------',''); 7I5g3_S _
for(i=0;i<temp;i++){ @A T`~2|/G8K5m
if(arr[i][1]==id){//如果相等,证明在第2级里面有输入第1级组织的子集,arr[总数目][部门] cWd`+nwQ
document.combo_box.city.options[document.combo_box.city.length] = new option(arr[i][0], arr[i][0]); aJ(l"Q,N[O j
} 4Li;d9r!m6R7CYN#cGk
} )| uJ!`"q-MR
} (s+z Q,X(u+_-L4g~
</script>]8D$R2qUak:X0e

J"W`5A+y \e+e0e9k <form name="combo_box">
3z+{Qj$p'qK^&R <table border="0" cellspacing="0" cellpadding="0" height="210" width="59">
l6i E$j7Y$[   <tr height="24">
A3I9V h A     <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>部门选择</font></td>0V+SEQGZ;l8w
    <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>人名选择</font></td>4s'RC'Q3~ [(hC
    <td bgcolor="#336699" class="buttons" align=center nowrap><font color=#ffffff>添加/移除</font></td>
x Wv5{J,p}0D4n4u     <td bgcolor="#336699" class="buttons" align=center><font color=#ffffff>最终人</font></td>M1E,?p,w*a7_
  </tr>7c6X"I1M-XSNV
  <tr>
A `9^6m{3YG |S.`?     <td>#LK ~6U#Fx o
  <select multiple id=prov name="prov"    style="width:150;height:200" class="bgc"> H:S/o3P5B5L&x1gf
  <option value="0">请选择部门 ---></option>
p1vP$L? <%
I/uuoO]eR/w     string sqld="select * from tdept";
B+gt6I+A6k6^2D stmt=conn.createstatement();B1tkn I j
rs=stmt.executequery(sqld);
:j!_@Nj@6u while(rs.next()))q Kk9[f;Z A3HZ
{
+q h:Ql$x!Iu;w %>0A1qre| m;S
  <option name="<%=rs.getstring("fno")%>"><%=rs.getstring("fname")%></option>
,u4qy/kOO.@K <%M^6qa\Tt
}
nw4T*Ld.{ q6u %> 2Bi4{7o*\a8W
  </select>
)b-m.^.wy1p*R1{ </td>9j,j(HL4i} P
    <td>"K!@U6}f(];Y
  <select multiple id=city style="width:150;height:200" class="bgc">+C0pw5M#B5T*}o8U
  </select>3f:q c"{A-SHT
</td>/Z2N"t(?Nzc7fF
    <td nowrap align="center" class="bgc">tM0s\5lE,J
  <input type="button"  value="<<" class="buttons">.K2r k2~F5_)@J
  <input type="button"  value=">>" class="buttons">,E p|$Ze-y?!c
</td>RC0R"n"j#?
    <td>Z2b$@ S@:q
  <select multiple size="10" name="list2" style="width:150;height:200" class="bgc">
xS_u}f   </select>S"Jg|H%D'~(Oq
</td>7I:ur+@BW4KK
  </tr>
A[k A`)pV"M0i     <tr class="bgc"> ` J^L4m Xs {8A
    <td colspan="4" align="center"><input type="button" name="button1" class="buttons" value="选好了!" ></td>^Jj0Z8qo*H
  </tr>
t7c;?&v7Pk7p </table>
y+c\/PD ApB~6J </form>7Q*L9F%G$H
<script language="javascript">9J/H)W#}}X
//人名移动,e1nWWb,q0? CG
function move(fbox, tbox) {n a3N;POQ3y
var arrfbox = new array();rQi3^-u7T@ ?
var arrtbox = new array();5g*}&|!f%Fq
var arrlookup = new array(); J2hejn;i
var i;Q!d_N"Xe7rY?
for (i = 0; i < tbox.options.length; i++) {
sB-^iu!zSFh arrlookup[tbox.options[i].text] = tbox.options[i].value;
d O-mJR` l arrtbox[i] = tbox.options[i].text;@)r!bxLsL9\:hy9? D
}a!z0U%t$w6@(@YRu`
var flength = 0;rl&h `5k)D$s
var tlength = arrtbox.length;
h'[-a${,^ for(i = 0; i < fbox.options.length; i++) {$M S'E e$v(K9V g
arrlookup[fbox.options[i].text] = fbox.options[i].value; I@_/KbP
if (fbox.options[i].selected && fbox.options[i].value != "") {
b;z,~/U&jj1U)cs arrtbox[tlength] = fbox.options[i].text;1aA @7r`0E
tlength++;!J)S\9u%T(C%c'y
}
eRE0NY else { q3Q$br!g?:_
arrfbox[flength] = fbox.options[i].text;Z O5o#u|H
flength++;?n^4cmB6e
   }
,l l!O{7vAb&V(A }
V r'g)F5QQ M*Ep$YI arrfbox.sort(); RC { f4hpWQ
arrtbox.sort();e-R w(OyM
j&Y2Fp!]T3\&m0M4v
fbox.length = 0;
+^e`$CY@l tbox.length = 0;
Cp H;d$J| var c;
r+v4` Lmt for(c = 0; c < arrfbox.length; c++) {}UN th,Z
var no = new option();
/B]f6_d(vG:i no.value = arrlookup[arrfbox[c]];G7V%U2PiMAW
no.text = arrfbox[c];p{&q5hCA
fbox[c] = no;
q,?b2iWr F$y }
2]1iPY qwV for(c = 0; c < arrtbox.length; c++) {
O&~}GO/|*T(h var no = new option();
h#~I iJ no.value = arrlookup[arrtbox[c]];L`n V|
no.text = arrtbox[c];
+KC1t6BW2r5x tbox[c] = no;
;S{kcA5}D    }3j n BE W_S
}
W_ qZjg </script>~['N worf^i
</body>B(z{+C W3_k8kL
[/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i]

页: [1]
【捌玖网络】已经运行:


Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.