javascript - 脚本可以在 Chrome 中运行,但不能在 Firefox 中运行

标签 javascript cross-browser

我正在学习 JS 教程,刚刚制作了一个抵押贷款计算器,它在 Chrome 中的工作方式就像一个 super 按钮,但在 Firefox 中却没有任何作用。我可以得到一些帮助来解决这个问题吗? Here's the whole thing :

// Formula: c = ((p * r) *  math.pow((1 + r), n)) / (math.pow((1 + r), n) - 1)

//@param p float Amount borrowed
//@param r interest as percentage
//@param n term in years

function percentToDecimal(percent) {
return (percent / 12) / 100;
}

function yearsToMonths(years) {
return years * 12;
}

function calculateMortgage(p, r, n) {
// convert this percentage to decimal:
r = percentToDecimal(r);
n = yearsToMonths(n);

var pmt = ((p * r) * Math.pow((1 + r), n)) / (Math.pow((1 + r), n) - 1);

return parseFloat(pmt.toFixed(2));

}

function postpayments(payment) {
var payments = document.getElementById("outMonthly");
payments.innerText = "$" + payment;
}

var btn = document.getElementById("btnCalculate");
btn.onclick = function () {
var cost = document.getElementById("inCost").value;
var downpayment = document.getElementById("inDown").value;
var interest = document.getElementById("inAPR").value;
var term = document.getElementById("inPeriod").value;

var amountBorrowed = cost - downpayment;

var pmt = calculateMortgage(amountBorrowed, interest, term);

postpayments(pmt);
};

最佳答案

payments.innerText 替换为 payments.textContent

关于javascript - 脚本可以在 Chrome 中运行,但不能在 Firefox 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27792958/

相关文章:

css - 如何在浏览器中检查 CSS 供应商前缀?

html - Mac 和 Windows 浏览器中的不同 CSS

javascript - Ember.js ArrayController 用法

Javascript Pong 游戏移动 bat

javascript - 将表行从一个表移动到另一个表 - AngularJS

java - 有没有什么工具可以让我们检查我们的Web应用程序在各种浏览器及其版本之间的兼容性?

javascript - 在浏览器中选择全字

javascript - 模糊+不透明度文本动画在 Google Chrome 浏览器中闪烁

javascript - 如何将渲染的 Vue 组件作为参数传递?

javascript - GWT 编译的 JavaScript 是否经过混淆或仅缩小?