hookee你好!刚才的问题还有点小BUG。
我给你发送了短信,麻烦你再帮我看看
------解决方案-------------------- <script>
var f;
function init(){
f = document.form1;
var dt = new Date();
var s = " ";
var m = dt.getMonth()+1;
var y = dt.getFullYear();
var d = dt.getDate();
var lastDay;
lastDay = getLastDay(m,y);
f.m0.value = m;
f.y0.value = y;
f.d0.value = d;
load(0);
getSum();
f.m0.focus();
}
function load(n){
var mm, obj;
obj = eval( "f.m "+n);
obj.index = n;
obj.onblur=check;
obj.onfocus=dofocus;
var m = parseInt(obj.value);
obj = eval( "f.y "+n);
obj.index = n;
obj.onblur=check;
obj.onfocus=dofocus;
var y = parseInt(obj.value);
obj = eval( "f.d "+n);
obj.index = n;
obj.onblur=check;
obj.onfocus=dofocus;
var d = parseInt(obj.value);
var dt;
var lastDay;
lastDay = getLastDay(m,y);
for(var i=n+1;i <10;i++){
mm = m + i-n;
var dd;
dt = new Date(y,mm-1,d);
if(dt.getMonth()!=(mm-1) || dt.getFullYear()!=y) dd = getLastDay(mm,y);
else dd = d;
dt = new Date(y,mm-1,dd);
var mmm = dt.getMonth()+1;
var yy = dt.getFullYear();
obj = eval( "f.m "+i);
obj.value = mmm;
obj.index = i;
obj.onblur=check;
obj.onfocus=dofocus;
obj = eval( "f.d "+i);
obj.value = dd;
obj.index = i;
obj.onblur=check;
obj.onfocus=dofocus;
obj = eval( "f.y "+i);
obj.value = yy;
obj.index = i;
obj.onblur=check;
obj.onfocus=dofocus;
obj = eval( "f.s "+i);
obj.value = 0;
obj.onblur=getSum;
}
}
function getLastDay(pm,py){
pm = parseInt(pm);
py = parseInt(py);
var dt2 = new Date(py,pm,1-1);
return dt2.getDate();
}
function getSum(){
var sum = 0;
for(var i=0;i <10;i++){
obj = eval( "f.s "+i);
if(obj.value== " " || isNaN(obj.value)) obj.value = 0;
sum += parseFloat(obj.value);
}
f.sum.value = sum;
}
function dofocus(){
var obj = event.srcElement;
window.val = obj.value;
}
function check(){
var obj = event.srcElement;
if(isNaN(obj.value)){alert( "该字段不是数字! ");obj.focus();return false;}
var index = obj.index;
var om = eval( "f.m " + index);
var oy = eval( "f.y " + index);
var od = eval( "f.d " + index);
var cm = parseInt(om.value)-1;
var cd = parseInt(od.value);
var cy = parseInt(oy.value);
var cdt = new Date(cy,cm, cd);
if(cdt.getFullYear()!= cy || cdt.getMonth() != cm || cdt.getDate() != cd){
alert( "日期无效! ");obj.focus();return false;
}
for(var i=0;i <index;i++){
var onm = eval( "f.m " + i);
var ony = eval( "f.y " + i);
var ond = eval( "f.d " + i);
var nm = parseInt(onm.value)-1;
var ny = parseInt(ony.value);
var nd = parseInt(ond.value);
var ndt = new Date(ny,nm, nd);
if(ndt.getTime()> cdt.getTime()){
alert( "日期小于前面的日期! ");obj.focus();return false;
}
}
/*
for(var i=index+1;i <10;i++){
var onm = eval( "f.m " + i);
var ony = eval( "f.y " + i);