我正在制作一个价目表,我有很多数据要解析。所有的数据都是不同的,没有公式。下面是我正在使用的一个片段。我想知道是否有更好的方法来存储和访问所有这些数据。
function getPrice(number) {
totalPrice = 0;
for (var t = 2; t <= number; t++) {
var ipp = 'cab' + (t - 1) + 'Size';
var cabP = 'p' + (t - 1);
var cabStyle = document.getElementById('cab' + (t - 1)).value;
var cabs = document.getElementById(ipp);
switch (cabStyle) {
case 'b1':
if (cabs.value === "") {
totalPrice = totalPrice + 0;
document.getElementById(ipp).style.border = "1px solid red";
} else if (cabs.value <= 12) {
totalPrice = totalPrice + 111;
document.getElementById(cabP).innerHTML = " $111";
document.getElementById(ipp).style.border = "";
} else if (cabs.value > 12 && cabs.value <= 13.5) {
totalPrice = totalPrice + 113;
document.getElementById(cabP).innerHTML = " $113";
document.getElementById(ipp).style.border = "";
} else if (cabs.value > 13.5 && cabs.value <= 15) {
totalPrice = totalPrice + 116;
document.getElementById(cabP).innerHTML = " $116";
document.getElementById(ipp).style.border = "";
} else if (cabs.value > 15 && cabs.value <= 16.5) {
totalPrice = totalPrice + 118;
document.getElementById(cabP).innerHTML = " $118";
document.getElementById(ipp).style.border = "";
} else if (cabs.value > 16.5 && cabs.value <= 18) {
totalPrice = totalPrice + 120;
document.getElementById(cabP).innerHTML = " $120";
document.getElementById(ipp).style.border = "";
} else if (cabs.value > 18 && cabs.value <= 19.5) {
totalPrice = totalPrice + 122;
document.getElementById(cabP).innerHTML = " $122";
document.getElementById(ipp).style.border = "";
} else if (cabs.value > 19.5 && cabs.value <= 21) {
totalPrice = totalPrice + 124;
document.getElementById(cabP).innerHTML = " $124";
document.getElementById(ipp).style.border = "";
} else if (cabs.value > 21 && cabs.value <= 22.5) {
totalPrice = totalPrice + 126;
document.getElementById(cabP).innerHTML = " $126";
document.getElementById(ipp).style.border = "";
} else if (cabs.value > 22.5 && cabs.value <= 24) {
totalPrice = totalPrice + 141;
document.getElementById(cabP).innerHTML = " $141";
document.getElementById(ipp).style.border = "";
} else if (cabs.value > 24 && cabs.value <= 27) {
totalPrice = totalPrice + 146;
document.getElementById(cabP).innerHTML = " $146";
document.getElementById(ipp).style.border = "";
} else if (cabs.value > 27 && cabs.value <= 30) {
totalPrice = totalPrice + 152;
document.getElementById(cabP).innerHTML = " $152";
document.getElementById(ipp).style.border = "";
}
break;
case 'b2':
if (cabs.value === "") {
totalPrice = totalPrice + 0;
document.getElementById(ipp).style.border = "1px solid red";
} else if (cabs.value <= 27) {
totalPrice = totalPrice + 167;
document.getElementById(cabP).innerHTML = " $167";
document.getElementById(ipp).style.border = "";
} else if (cabs.value > 27 && cabs.value <= 30) {
totalPrice = totalPrice + 173;
document.getElementById(cabP).innerHTML = " $173";
document.getElementById(ipp).style.border = "";
} else if (cabs.value > 30 && cabs.value <= 33) {
totalPrice = totalPrice + 178;
document.getElementById(cabP).innerHTML = " $178";
document.getElementById(ipp).style.border = "";
} else if (cabs.value > 33 && cabs.value <= 36) {
totalPrice = totalPrice + 183;
document.getElementById(cabP).innerHTML = " $183";
document.getElementById(ipp).style.border = "";
} else if (cabs.value > 36 && cabs.value <= 39) {
totalPrice = totalPrice + 194;
document.getElementById(cabP).innerHTML = " $194";
document.getElementById(ipp).style.border = "";
} else if (cabs.value > 39 && cabs.value <= 42) {
totalPrice = totalPrice + 199;
document.getElementById(cabP).innerHTML = " $199";
document.getElementById(ipp).style.border = "";
} else if (cabs.value > 42 && cabs.value <= 45) {
totalPrice = totalPrice + 205;
document.getElementById(cabP).innerHTML = " $205";
document.getElementById(ipp).style.border = "";
}
break;