闲暇之余给公司做了个内衣尺码测量页面,其中涉及到内衣尺码各阶段判断,由于不涉及到数据库,所以代码直接用javascript来写,现贴上JS代码供
友友们讨论,看是否能优化下代码,让执行效率更高点。
代码
<script type="text/javascript" language="javascript">
function braSize_onClick(){ //内衣尺码测量函数
var numUp = document.getElementById("numUp").value;
var numDown = document.getElementById("numDown").value;
var result = numUp - numDown;
if(numDown != "" && numUp != ""){
if(numDown < 68 || numDown > 92){alert("对不起,您的下围尺码不在测量范围内,请重输。");}
else if(numDown < 73){document.getElementById("braSize").value = 70}
else if(numDown < 78){document.getElementById("braSize").value = 75}
else if(numDown < 83){document.getElementById("braSize").value = 80}
else if(numDown < 88){document.getElementById("braSize").value = 85}
else if(numDown < 93){document.getElementById("braSize").value = 90}
if(result < 6 || result > 21){alert("对不起,没有适合您的罩杯!");}
else if(result < 8){document.getElementById("braClass").value = "AA"}
else if(result < 10){document.getElementById("braClass").value = "A"}
else if(result < 13.5){document.getElementById("braClass").value = "B"}
else if(result < 16){document.getElementById("braClass").value = "C"}
else if(result < 20){document.getElementById("braClass").value = "D"}
}
}
function underwearSize_onClick(){ //内裤尺码测量函数
var waistSize = document.getElementById("waistSize").value;
var hipSize = document.getElementById("hipSize").value;
if(waistSize != "" && hipSize != ""){
if(waistSize < 58 || waistSize > 83 || hipSize < 79 || hipSize > 103){alert("对不起!没有适合您的尺码。请重输");}
if(waistSize >=58 && waistSize <=63){if(hipSize>=79 && hipSize<=89) document.getElementById("underwearSize").value = "S";}
if(waistSize >=63 && waistSize <=68){if(hipSize>=83 && hipSize<=93) document.getElementById("underwearSize").value = "M";}
if(waistSize >=68 && waistSize <=73){if(hipSize>=86 && hipSize<=96) document.getElementById("underwearSize").value = "L";}
if(waistSize >=73 && waistSize <=78){if(hipSize>=89 && hipSize<=99) document.getElementById("underwearSize").value = "XL";}
if(waistSize >=78 && waistSize <=83){if(hipSize>=91 && hipSize<=103) document.getElementById("underwearSize").value = "XXL";}
}
}
</script>
function braSize_onClick(){ //内衣尺码测量函数
var numUp = document.getElementById("numUp").value;
var numDown = document.getElementById("numDown").value;
var result = numUp - numDown;
if(numDown != "" && numUp != ""){
if(numDown < 68 || numDown > 92){alert("对不起,您的下围尺码不在测量范围内,请重输。");}
else if(numDown < 73){document.getElementById("braSize").value = 70}
else if(numDown < 78){document.getElementById("braSize").value = 75}
else if(numDown < 83){document.getElementById("braSize").value = 80}
else if(numDown < 88){document.getElementById("braSize").value = 85}
else if(numDown < 93){document.getElementById("braSize").value = 90}
if(result < 6 || result > 21){alert("对不起,没有适合您的罩杯!");}
else if(result < 8){document.getElementById("braClass").value = "AA"}
else if(result < 10){document.getElementById("braClass").value = "A"}
else if(result < 13.5){document.getElementById("braClass").value = "B"}
else if(result < 16){document.getElementById("braClass").value = "C"}
else if(result < 20){document.getElementById("braClass").value = "D"}
}
}
function underwearSize_onClick(){ //内裤尺码测量函数
var waistSize = document.getElementById("waistSize").value;
var hipSize = document.getElementById("hipSize").value;
if(waistSize != "" && hipSize != ""){
if(waistSize < 58 || waistSize > 83 || hipSize < 79 || hipSize > 103){alert("对不起!没有适合您的尺码。请重输");}
if(waistSize >=58 && waistSize <=63){if(hipSize>=79 && hipSize<=89) document.getElementById("underwearSize").value = "S";}
if(waistSize >=63 && waistSize <=68){if(hipSize>=83 && hipSize<=93) document.getElementById("underwearSize").value = "M";}
if(waistSize >=68 && waistSize <=73){if(hipSize>=86 && hipSize<=96) document.getElementById("underwearSize").value = "L";}
if(waistSize >=73 && waistSize <=78){if(hipSize>=89 && hipSize<=99) document.getElementById("underwearSize").value = "XL";}
if(waistSize >=78 && waistSize <=83){if(hipSize>=91 && hipSize<=103) document.getElementById("underwearSize").value = "XXL";}
}
}
</script>