【发布时间】:2021-06-10 07:30:20
【问题描述】:
根据问题陈述,我们需要输入产品的数量和价格,然后在输出中显示总价 它显示 Parameter(id) 缺失并且总价的值错误 没有显示结果的可能原因是什么
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="billcalc.css">
<script type = "text/javascript">
function calculateTotalPrice()
{ pric=parseFloat(document.getElementById("price"));
qt=parseInt(document.getElementById("qty"));
res=pric*qt;
document.getElementById(totalprice).innerHTML=res;
return false;
}
</script>
</head>
<h1>Bill Calculator</h1>
<form onsubmit="calculateTotalPrice()">
<table>
<tr>
<td><label for="productName">Product Name</label></td>
<td><input type="text" placeholder="Product Name" id="productName" name="productName" required></td>
</tr>
<tr>
<td><label for="price">Product Price in Rs.</label></td>
<td><input type="number" placeholder="Product Price" id="price" min="0" required/></td>
</tr>
<tr>
<td><label>Quantity</label></td>
<td><input type="number" placeholder="Enter Quantity" id="qty" min="1" required></td>
</tr>
<tr>
<td><label for="totalprice">Total Price in Rs.</label></td>
<td><output type="number" id="totalprice" for="price qty" required>
</output></td>
</tr>
<tr>
<td colspan="2"><input type="submit" id="submit" ></td>
</tr>
</table>
</form>
</html>```
【问题讨论】:
-
忘记引号了:
document.getElementById('totalprice').innerHTML=res; -
document.getElementById('price') => document.getElementById('price').value
标签: javascript html css html5-canvas