Internet Explorer 是否有某些你不能使用的 JS?
Does Internet Explorer have certain JS you can’t use?
我有一个还款计算器,在所有其他浏览器中都可以正常工作,但在 IE11 中 运行 不行。
我查看了 IE11 是否有某些您不能使用的 JS,并将我的一些 let's 更改为 var,但没有成功。
<script>
function loanRepay(){
//Present Value
var pv = (parseFloat((document.getElementById("AB").value).replace(/[&\/\#,+()$~%'":*?<>{}]/g,''), 10));
//Interest Rate (Compounded Monthly)
var r = ((parseFloat((document.getElementById("IR").value).replace(/[&\/\#,+()$~%'":*?<>{}]/g,''), 10)) / 100) / 12;
//Number of Compounds in a Period - Compounded monthly
var n = (parseFloat((document.getElementById("TL").value).replace(/[&\/\#,+()$~%'":*?<>{}]/g,''), 10));
//Payments per Month
var pay = pv * (r / (1 - (1 + r)**-n));
document.getElementById("pay").innerHTML = "$" + pay.toFixed(2);
//Interest Paid
var interest = (pay * n) - pv;
document.getElementById("interest").innerHTML = "Interest Paid $" + interest.toFixed(2);
//Total Payment
var total = interest + pv;
document.getElementById("total").innerHTML = "Total Amount $" + total.toFixed(2);
//if form isn't filled out correctly
if (isNaN(total))
{ alert('Please fill all fields with numerical values before pressing calculate.');} else{};
}
</script>
IE 没有抛出任何错误,只是没有 运行。我还在学习 JS,我认为它是非常简单的 JS,所以我不确定为什么它不是 运行。
求幂运算符(**
)是 ES2016+ 的一个特性,it is not supported in IE 11。将此行更改为:
var pay = pv * (r / (1 - Math.pow(1 + r, -n)));
您可以设置babel and its presets in your project to target specific browsers. If it is a small project or it gets too complicated, you can just paste your code in Babel REPL获取转译后的代码。
我有一个还款计算器,在所有其他浏览器中都可以正常工作,但在 IE11 中 运行 不行。
我查看了 IE11 是否有某些您不能使用的 JS,并将我的一些 let's 更改为 var,但没有成功。
<script>
function loanRepay(){
//Present Value
var pv = (parseFloat((document.getElementById("AB").value).replace(/[&\/\#,+()$~%'":*?<>{}]/g,''), 10));
//Interest Rate (Compounded Monthly)
var r = ((parseFloat((document.getElementById("IR").value).replace(/[&\/\#,+()$~%'":*?<>{}]/g,''), 10)) / 100) / 12;
//Number of Compounds in a Period - Compounded monthly
var n = (parseFloat((document.getElementById("TL").value).replace(/[&\/\#,+()$~%'":*?<>{}]/g,''), 10));
//Payments per Month
var pay = pv * (r / (1 - (1 + r)**-n));
document.getElementById("pay").innerHTML = "$" + pay.toFixed(2);
//Interest Paid
var interest = (pay * n) - pv;
document.getElementById("interest").innerHTML = "Interest Paid $" + interest.toFixed(2);
//Total Payment
var total = interest + pv;
document.getElementById("total").innerHTML = "Total Amount $" + total.toFixed(2);
//if form isn't filled out correctly
if (isNaN(total))
{ alert('Please fill all fields with numerical values before pressing calculate.');} else{};
}
</script>
IE 没有抛出任何错误,只是没有 运行。我还在学习 JS,我认为它是非常简单的 JS,所以我不确定为什么它不是 运行。
求幂运算符(**
)是 ES2016+ 的一个特性,it is not supported in IE 11。将此行更改为:
var pay = pv * (r / (1 - Math.pow(1 + r, -n)));
您可以设置babel and its presets in your project to target specific browsers. If it is a small project or it gets too complicated, you can just paste your code in Babel REPL获取转译后的代码。