简体   繁体   English

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

[英]Script working in Chrome, but not in firefox

I'm following a JS tutorial and just made a mortgage calculator that works like a charm in Chrome, but it does nothing in Firefox. 我正在遵循JS教程,并且刚刚制作了抵押贷款计算器,其在Chrome中的作用类似于魅力,但在Firefox中却不起作用。 Can I get some help figuring this out please? 请帮我解决这个问题吗? 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

If you want to work it across all browsers, a clean solution would be to create a TextNode and attach it to the view. 如果要在所有浏览器上使用它,一个干净的解决方案是创建一个TextNode并将其附加到视图。

function postpayments(payment) {
    var payments = document.getElementById("outMonthly");
    while (payments.firstChild!==null)
        element.removeChild(payments.firstChild); // remove all existing content
    payments.appendChild(document.createTextNode("$" + payment));
}

Check this for more details: https://stackoverflow.com/a/1359834/891092 检查此以获取更多详细信息: https : //stackoverflow.com/a/1359834/891092

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 脚本可在Chrome上运行,但不能在Firefox上运行 - Script working on Chrome but not on Firefox jQuery脚本在Firefox和Coda(IDE)中工作但不是Chrome - jQuery script working in Firefox and Coda (IDE) but not Chrome Ajax脚本仅适用于Firefox(不适用于Chrome,Safari,Edge等) - Ajax script only working in Firefox (not working in Chrome, Safari, Edge,…) 脚本适用于chrome,但不适用于Firefox - Script works in chrome but not in firefox 我的脚本无法在Chrome和Firefox(Mac)中运行,但可以在Safari中运行? - My Script is not working in Chrome and Firefox (Mac) but works in Safari? Java脚本形式验证在Chrome中正常工作,但不能在Firefox中工作? - java script form validation works fine in chrome but not working in firefox? 始终在chrome / firefox中运行的脚本在IE中只能运行一次 - script always working in chrome / firefox works only once in IE ZeroClipboard用户脚本添加到了鼠标上方,可以在Firefox中使用,但不适用于Chrome - ZeroClipboard user script adding in mouse over, working in firefox, but not chrome Web-Push通知脚本适用于Firefox但不适用于Chrome - Web-Push notification script working on Firefox but not on Chrome 按钮适用于Chrome,但不适用于Firefox - Button working on chrome but not on firefox
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM