大连至威海的汽车运费费用主要取决于车型、起始时间和行驶距离。私家车和商务车的运费较高,而小型客车和公交车则相对较低。起始时间越早,运费也越高;行驶距离越远,运费也会增加。不同的运输公司可能会有不同的收费标准,因此建议您在出行前咨询专业的运输公司获取准确的价格信息。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>大连至威海汽车运费价格查询</title>
</head>
<body>
<h1>大连至威海汽车运费价格查询</h1>
<form action="/calculate-运费" method="post">
<label for="car-type">车型:</label>
<select id="car-type" name="car-type">
<option value="">请选择车型</option>
<option value="大货车">大货车</option>
<option value="小轿车">小轿车</option>
</select>
<br>
<label for="weight">车辆重量:</label>
<input type="number" id="weight" name="weight">
<br>
<label for="distance">运输距离:</label>
<input type="number" id="distance" name="distance">
<br>
<label for="transport-method">运输方式:</label>
<select id="transport-method" name="transport-method">
<option value="">请选择运输方式</option>
<option value="公路">公路</option>
<option value="铁路">铁路</option>
<option value="海运">海运</option>
</select>
<br>
<button type="submit">查询运费</button>
</form>
<div id="result"></div>
<script>
function calculate运费() {
const carType = document.getElementById("car-type").value;
const weight = parseFloat(document.getElementById("weight").value);
const distance = parseFloat(document.getElementById("distance").value);
const transportMethod = document.getElementById("transport-method").value;
if (isNaN(carType) || isNaN(weight) || isNaN(distance) || isNaN(transportMethod)) {
alert("请输入有效的值");
return;
}
let result;
switch (carType) {
case "大货车":
result = 15 * weight + 0.5 * distance;
break;
case "小轿车":
result = 10 * weight + 1 * distance;
break;
default:
result = 10 * weight + 1 * distance;
break;
}
document.getElementById("result").innerHTML =根据您的选择,车价为:${result}
;
}
</script>
</body>
</html>
修改点包括:
1、更改表单标签和按钮名称,使之更易读。
2、添加了对各种有效输入值(如汽车类型、重量、距离和运输方式)的检查,确保它们都是数字。
3、使用switch
语句计算运费,避免在一行中写多行计算公式。
4、更新result
,将其作为函数的结果显示出来。
发表评论