나는 항목, 가격, 수량별 가격 등을 표시해야하는 연습이 있습니다 ... 수량에 가격을 곱하는 데 어려움이 있습니다. .. 아래에 내가 표시하고 입력과 옵션 내 코드이며, 아래의 스크립트 기능은 도움이 아주 많이 감사합니다! :두 변수 (JS)를 입력에 곱하기
이<body>
<label>Choose Item</label>
<select onChange="getPrice(this)">
<option></option>
<option>Tomatoes</option>
<option>Lettuce</option>
<option>Potato</option>
<option>Carrots</option>
<option>Artichoke</option>
</select>
<br/>
<label>Price</label>
<input type="text" id="price" />
<br/>
<label>Quantity</label>
<select onChange="getFull(this)">
<option></option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<br />
<label>Total $</label>
<input type="text" id="quantityPrice" />
<script type="text/javascript">
var veggy = {};
veggy ["Tomatoes"] = 5.99
veggy ["Lettuce"] = 7.66
veggy ["Potato"] = 4.52
veggy ["Carrots"] = 2.13
veggy ["Artichoke"] = 10.58
function getPrice(select) {
document.getElementById("price").value = veggy[select.value];
}
var quantity = {};
quantity ["1"] = 1
quantity ["2"] = 2
quantity ["3"] = 3
quantity ["4"] = 4
quantity ["5"] = 5
function getFull(select) {
document.getElementById("quantityPrice").value = (quantity[select.value] * veggy [select.value]);
}
</script>
</body>
</html>
같은
그리고
getFull
, 그 시도. – Mritunjay