我已经编写了代码来跟踪值并在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;
}
}
Run Code Online (Sandbox Code Playgroud)
尝试innerHTML像
document.getElementById('subtotal').innerHTML = amount;
Run Code Online (Sandbox Code Playgroud)
看一下它们之间的差异,假设您有以下html
<div id="Test"><b>InnerText and InnerHTML</b><div>
Run Code Online (Sandbox Code Playgroud)
innerHTML 给 <b>InnerText and InnerHTML</b>
innerText 给 InnerText and InnerHTML
有关更多详细信息,请访问 HERE