显示表td中的脚本变量



我想在表格中显示一个计算值,而不使用input.

这是我的脚本....

<script type="text/javascript">
function totalIt() {
var input = document.getElementsByName("product");
var total = 0;
for (var i = 0; i < input.length; i++) {
if (input[i].checked) {
total += parseFloat(input[i].value);
}
}
document.getElementsByName("total")[0].value = total.toFixed(0);
}
</script>

我的HTML是....

echo "<td align='right' data-label='Option Prices'> **DISPLAY THE VALUE HERE** </td>";

如果我正确阅读你的问题,你可以使用以下(即,你想显示计算值而不使用输入字段):

document.querySelector('[data-label="Option Prices"]').innerText = total.toFixed(0);

如果你想把你的答案格式化成"15,900"这是美国英语语言环境标准,请使用以下

document.querySelector('[data-label="Option Prices"]').innerText = new Intl.NumberFormat().format(total.toFixed(0))

更多格式和文档类型在这里

最新更新