javascript函数停车时间
javascript function parking hours
这是完整的问题
写一份完整的表格,根据停车小时数向每位客户收取停车费。要求用户使用prompt()输入总小时数
使用函数calcCharge()计算客户必须支付的费用金额
此功能通过其参数接收总小时数或停车时间。然后,它计算并将费用金额返回给客户
计算客户费用金额的公式:第一个小时的费用为RM 1.00。在接下来的一个小时内,额外收费为每小时0.50令吉。最高收费为RM 10.00。使用函数calcTotal()计算所有客户的总费用。显示客户的费用金额。使用alert()显示所有客户的总费用
我试着编写代码,但没有成功。
我没有显示一个客户的总费用和所有客户的总收费。
我希望有人愿意帮助我,谢谢
<html>
<head><title>Calculate Parking Hours</title>
<script type="text/javascript">
function calcCharge()
{
var hour=parseInt(document.fee.hour.value);
var tot;
if (hour==1)
tot=1;
else if (hour>1 && hour<=20)
tot=1+0.5*(hour-1);
else
tot=10;
document.write("The total charge is : RM "+tot);
}
function calcTotal()
{
var totCha;
totCha=parseInt(totCha);
totCha+=document.tot.value;
alert("Total charge all customers"+totCha);
}
</script>
</head>
<body onload="calcTotal()">
<form name="fee" method="post">
Hour : <input name="hour" type="text"><br>
<input type="submit" name="submit" value="Total Charge" onclick="calcCharge()">
</form>
</body>
</html>
更新以下行:
var hour = parseInt(document.getElementByName("hour").value);
在您的问题中,您说calcCharge()
函数通过其参数接收总小时数或停车时间。事实上,你没有把任何论点传递给你的函数。如果你想用正确的方式,那么试试下面的代码
html
<input type="button"onclick="calcCharge(document.getElementById('text1').value)"/>
<input type="text" id="text1"/>
js
function calcCharge(value)
{
var hour=parseInt(value);
var tot=0;
if (hour==1)
tot=1;
else if (hour>1 && hour<=20)
{
tot=1+(0.5*(hour-1));
}
else
{
tot=10;
}
alert(tot);
}
DEMO
相关文章:
- Java脚本时间添加
- Json数据包含日期和时间格式
- 如何根据时间运行不同的脚本
- 用每小时的差值填充数组/列表-从下拉列表中给定两个时间值
- 在wordpress一定时间后更改自定义字段
- 更改angularjs中的日期-时间格式
- 将当前时间添加到我的页面上的特定部分
- 门户网站:当地时间有多有用
- 显示时间的脚本
- 如何在窗体打开时从javascript倒计时计时器值中节省时间
- 通过JSON&比较时间
- Javascript时间轨迹
- 将日期时间作为 JSON 发送将无法在我的视图中正确显示
- 将日期时间从json转换为可读格式
- 高库存时期时间与时区不匹配
- Jquery如何检查今天的时间大于使用给定时间
- jquerydatetimepicker日期和时间应在框默认值中,而无需单击框
- primefaces日历可以禁用过去的日期和时间吗
- Jquery函数在错误的时间提交
- javascript函数停车时间