프로토콜 및/또는 형식의 잠재적 인 오류를 용서하십시오. 나는 이것에 관해 새로운 사람이다. 내 "제출"버튼을 클릭해도 function cost()가 호출되지 않습니다. 내가 도대체 뭘 잘못하고있는 겁니까?제출 단추가 작동하지 않음 기능
<html>
<head>
<script type="text/javascript">
function cost() {
mpg = document.getElementById("mpg");
distance = document.getElementById("distance");
gasPrice = document.getElementById("gasPrice");
alert("<p>" + Math.round((distance/mpg) * gasPrice) + "</p>");
}
</script>
<h1>Trip Cost Calculator</h1>
</head>
<p> Enter mpg (miles): </p>
<input type="text" id="mpg">
</input>
</body>
<body>
<p> Enter distance (miles): </p>
<input type="text" id="distance">
</input>
</body>
<body>
<p> Enter gas price (dollars): </p>
<input type="text" id="gasPrice">
</input>
</body>
<body>
</br>
<input type="button" id="submit" value="Submit" onclick="cost()"/>
</body>
, 당신은 HTML 페이지에 여러'body' 태그가 안되며, 모든 컨텐츠는 몸에 있어야합니다. – sje397
먼저 '
'과 ''중 하나만 있으면됩니다. 실제로 당신은 당신의 머리 뒤에 '몸'을 갖지 못합니다. – steveoh입력 필드의 값은 캡처하지 않고 입력 필드 자체 만 캡처합니다. 입력 필드의 value 속성을 사용하여 값을 가져옵니다. 예 : document.getElementById ("gasPrice"). 값; –