왜 그런지는 모르겠지만 오렌지 만이 내가 만든 형태로 계산하는 것처럼 보이지만, 내가 지정한 다른 과일은 계산하지 않습니다. 각 열매마다 각 .value가 지정되어 있습니다. 모든 과일의 형태는 논리적으로 내가 볼 수있는 것과 동일하므로 왜 내가 수박이나 파인애플에서 결과를 얻지 못하는지 이해하지 못합니다.자바 스크립트 - 여러 값으로 양식을 만들었지 만 한 개만 계산하는 중입니까?
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title> Purchase Orange </title>
<!-- Script for the event handlers -->
<script type = "text/javascript">
// The event handler function to compute the cost
function computeCost() {
var orange = document.getElementById("orange").value;
// Compute the cost
document.getElementById("cost").value = orange * 1.99;
var watermelon = document.getElementById("Watermelon").value;
document.getElementById("cost").value = watermelon * 4.99;
var pineapple = document.getElementById("Pineapple").value;
document.getElementById("cost").value = pineapple * 4.69;
} //* end of computeCost
</script>
</head>
<body>
<form>
Orange $1.99/lb <input type = "text" id = "orange" size ="3" />
<br />
</form>
<form>
Watermelon $4.99/lb <input type = "text" id = "watermelon" size ="3" />
<br />
</form>
<form>
Pineapple $4.69/lb <input type = "text" id = "pineapple" size ="3" />
<br />
</form>
<form>
Total Cost is <input type = "text" id = "cost" size ="5" />
<br />
</form>
<form>
<input type = "button" value = "Total Cost" onclick="computeCost();"/>
</form>
</body>
소계를 얻고 싶습니까? –
현장에서 각 과일을 얻고 싶습니다. 지금까지 계산 된 유일한 합계는 오렌지색이지만 다른 과일은 아닙니다. 코드를 실행할 때 과일마다 필드가 있으며, 각 필드에는 수량을 입력 할 수있는 상자가 있습니다. 오렌지는 내가 지정한 1.99의 가격으로 계산하고 계산은 내가 만든 전체 필드로 이동합니다. 그러나 그것은 파인애플과 수박에 대해서는 그렇게하지 않습니다. – user3577397
ID를 올바르게 작성한 후에 모든 변수를 합산해야합니다. –