我照看我的非营利游泳俱乐部的网站;它由Squarespace主持,我们的财务主管要求我在membership page添加一个计算器,这样,如果他们希望一次性支付,预期会员可以轻松计算所需的按比例金额。如果每年支付一年全年费用为475英镑,那么如果在6月30日点击按钮,我希望它在页面上返回237.50英镑。看看其他一些答案,并使用我有限的Javascript知识,我已经想出了这个,但它并没有给我我期望的答案:
<!DOCTYPE html>
<html>
<body>
<p>Click the button to display the total pro-rata annual amount due, if membership starts tomorrow</p>
<button onclick="myFunction()">Click Me</button>
<p id="prorata"></p>
<script>
function myFunction() {
var today = new Date();
var totalDays = new Date(today.getFullYear(), today.getMonth(), 0).getDate();
var daysLeft = (totalDays - today.getDate()) - 1;
var pricePerDay = 1.30;
var n = daysLeft * pricePerDay;
document.getElementById("prorata").innerHTML = n;
}
</script>
</body>
</html>
任何帮助都很明确!
答案 0 :(得分:0)
这是你想要的吗? 我确实喜欢这样:remaining_Days =(今年最后一天 - 今天);
Pro rata = remaining_Days * 1.30;
<!DOCTYPE html>
<html>
<body>
<p>Click the button to display the total pro-rata annual amount due, if membership starts tomorrow</p>
<button onclick="myFunction()">Click Me</button>
<p id="prorata"></p>
<script>
function myFunction() {
var today = new Date();
var year = new Date().getFullYear();
var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds
var firstDate = new Date();
var secondDate = new Date(year,11,31);
var diffDays = Math.round(Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay)));
var n = diffDays* 1.30;
document.getElementById("prorata").innerHTML = n;
}
</script>
</body>
</html>
&#13;