我已经编写了代码来跟踪值并在span标签中显示,值跟踪有效,但显示部分不起作用(innerText,我也尝试使用值)有人可以帮助我,谢谢
function goAndSetTotal() {
var amount = document.getElementById("amount").value;
if (document.getElementById('gst').checked) {
document.getElementById('subtotal').innerText = amount;
document.getElementById('gst_box').innerText = amount*10/100;
document.getElementById('total').innerText = amount + (amount*10/100);
} else {
document.getElementById('subtotal').innerText = amount;
document.getElementById('gst_box').innerText = 0;
document.getElementById('total').innerText = amount;
}
}
最佳答案
试试innerHTML
而不是像
document.getElementById('subtotal').innerHTML = amount;
看一下它们之间的差异,假设您有以下html
<div id="Test"><b>InnerText and InnerHTML</b><div>
innerHTML
给出<b>InnerText and InnerHTML</b>
innerText
给出InnerText and InnerHTML
有关更多详细信息,请访问HERE
关于javascript - Javascript document.getElementById ('id').innerText不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25305507/