我有一个用户脚本问题。我需要脚本来加载每天的统计信息。但是在第一个运行日已经有了值2015-10-10(+200天)。
var today = '2015-11-26';
var year = '2015';
var month = 5;
var day = 1;
var date = '2015-05-01';
var max = 31;
var from = document.getElementById('From');
var to = document.getElementById('To');
for (var i = 0; i < 200; i++) {
setTimeout(function () {document.getElementById("btn").click();
from.value = date;
to.value = date;
if (month == 5 || month == 7 || month == 8 || month == 10) {
max = 31;
} else {
max = 30;
}
if (day > max) {
month++;
day = 1;
} else {
day++;
}
if (day < 10) {
day = '0' + day.toString();
}
date = year + '-' + month + '-' + day;
}, 9000);
}
更新不要感谢Bergi和Jamiec。因为我不是开发人员,所以我只需要获得统计数据。如果你知道答案你可以帮助,伙计们。但我找到了解决方案:
var dates = [];
for (var i = 0; i < 214; i++) {
if (month == 5 || month == 7 || month == 8 || month == 10) {
max = 31;
} else {
max = 30;
}
if (day > max) {
month++;
day = 1;
} else {
day++;
}
if (day < 10) {
day = '0' + day.toString();
}
date = year + '-' + month + '-' + day;
dates[i] = date;
}
var j = 0;
function changeDate() {
to.value = dates[j];
from.value = dates[j];
document.getElementById("btnSearch").click();
j++;
}
setInterval(changeDate, 4000);