我是 javascript 的新手,正在尝试编写一些简单的代码。在这一点上,我所做的就是找出我在车里还剩下多少加仑。我似乎无法让结果显示出来。任何帮助,将不胜感激
<!doctype>
<html>
<head>
<script type="text/javascript">
var gasMilage = document.getElementById("mpg");
// getting the percent of the tank left
var gasReading = document.getElementById("tank_reading") / 100;
var gasTank = document.getElementById("tank_capacity");
function getGallons(){
var gallons = gasReading * gasTank;
window.alert(gallons);
}
</script>
</head>
<body>
<style>
form input{
display:block;
}
</style>
<form name=test>
MPG<input type="text" id="mpg" name="mpg">
Gas Tank Reading<input type="text" id="tank_reading" name="tank_reading">
Tank Capacity<input type="text" id="tank_capacity" name="tank_capacity">
<input type="submit" onclick=getGallons()>
<input name=result readonly >
</form>
</body>
</html>