2 回答
TA贡献1848条经验 获得超10个赞
在 HTMLid中用作指向 HTML 元素的链接。您将其设置在要引用的标签中:
<td width="75%" id="totalFee></td>
然后您可以获取该标签并从 js 操作它:
let total_Fee = (fee * term);
document.getElementById('totalFee').value = total_Fee;
TA贡献1828条经验 获得超3个赞
您的代码有很多语法错误。
尝试这个:
<html>
<body>
<table style="width:100%">
<tr>
<td class="bosytext" width="15%">Membership Period</td>
<td class="bosytext" width="75%">
<input type="number" name="membershipterm" id="term" required="required">
<button onclick="calc()">calc</button>
$22 for single year membership/ $20 per multi-year membership </td>
</tr>
<tr>
<td width="15%">Fee</td>
<td width="75%" id="totalFee"></td>
</tr>
</table>
<script>
function calc(){
var term = document.getElementById('term').value;
var fee;
if (term == 1) {
fee = 22;
} else {
fee = 20;
}
var totalFee = (fee * term);
document.getElementById('totalFee').innerHTML = totalFee
}
</script>
</body>
</html>
添加回答
举报