用HTML编写一个收银柜台收款程序,根据商品单价、购买数量以及收款金额计算并输出应收金额和找零。当总价大于或等于500,享受8折优惠
时间: 2024-05-06 21:19:22 浏览: 33
好的,这个问题是关于编程的,我可以回答。以下是HTML代码示例:
```html
<!DOCTYPE html>
<html>
<head>
<title>收银程序</title>
</head>
<body>
<h1>收银程序</h1>
<form>
<label>商品单价:</label>
<input type="number" id="price" min="0"><br><br>
<label>购买数量:</label>
<input type="number" id="quantity" min="0"><br><br>
<label>收款金额:</label>
<input type="number" id="payment" min="0"><br><br>
<button type="button" onclick="calculate()">计算应收金额和找零</button><br><br>
<label>应收金额:</label>
<input type="number" id="total" disabled><br><br>
<label>找零:</label>
<input type="number" id="change" disabled>
</form>
<script>
function calculate() {
var price = parseFloat(document.getElementById("price").value);
var quantity = parseInt(document.getElementById("quantity").value);
var payment = parseFloat(document.getElementById("payment").value);
var total = price * quantity;
if (total >= 500) {
total *= 0.8;
}
var change = payment - total;
document.getElementById("total").value = total.toFixed(2);
document.getElementById("change").value = change.toFixed(2);
}
</script>
</body>
</html>
```
这个程序可以根据用户输入的商品单价、购买数量和收款金额计算应收金额和找零,并且如果总价大于或等于500,享受8折优惠。请注意,这只是一个代码示例,实际开发中可能需要更多的输入验证和安全保障。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)