我制作了这个脚本,但它显示 99% 已完成 idk 为什么
代码:
function Percentage(){
var start = new Date(2021,3,16),
end = new Date(2021,6,8),
today = new Date();
progress = 100 - (((end - start) * 100 ) / today)
alert((progress).toFixed(11) + '%')
setTimeout("Percentage()",10)
}
答案 0 :(得分:0)
正如我所说,Javascript 月份从 0 开始。 相应地设置开始和结束日期 此外,如果进度百分比表示从可用天数中过去的天数,则
progress = (((today-start) * 100 ) / (end-start))
如果进度百分比意味着可用总天数中剩下的天数,那么它应该是
progress = 100 - (((today-start) * 100 ) / (end-start))