가격 매트릭스에서 폭과 높이에 따라 커튼 가격을 계산해야합니다. if 문 대신 배열에서 어떻게 계산할 수 있습니까?자바 스크립트 가격 매트릭스 배열
function checkPrice() {
var price = calculatePrice();
function calculatePrice(price) {
var width = parseInt(document.getElementById('customid0').value);
var height = parseInt(document.getElementById('customid1').value);
// width up to 100
if (width <= 100){
if (height <=50){
price = 67.22;
}
if (height >50 && height <=100){
price = 103.34;
}
if (height >100 && height <=130){
price = 133.11;
}
}
// width between 101 and 125
if (width > 100 && width <= 125){
if (height <=50){
price = 76.69;
}
if (height >50 && height <=100){
price = 113.01;
}
if (height >100 && height <=130){
price = 146.05;
}
}
// width between 126 and 150
if (width > 125 && width <= 150){
if (height <=50){
price = 83.69;
}
if (height >50 && height <=100){
price = 124.74;
}
if (height >100 && height <=130){
price = 161.28;
}
}
return price;
}
document.getElementById('product_addtocart_form').action = '<?php echo $this->getAddToCartUrl($_product) ?>&price='+price;
optionsPrice.changePrice('options', price);
optionsPrice.reload();
Price.changePrice(price);
}
돈을 위해 십진법을 사용하지 마십시오. 수학에 100을 곱하고 수학이 끝나면 100으로 나눕니다. 이유를 보려면 0.02와 0.01을 함께 사용해보십시오. – Incognito
감사합니다. – Gumtee
이 숙제가 있습니까? – Incognito