好吧,我根据你的建议做了,但有点看起来很糟糕哈...因为它为每个百分比组重复相同的事情:css和消息.我想知道是否还有其他方法可以改变它?如果没有,我对此感到满意..
if(69 <percentDiscount && percentDiscount <101){
$(this).find("#percentoff").html('> 70% off');
$(this).find("#percentoff").addClass('badge70');
}
else if (49 < percentDiscount && percentDiscount < 70) {
$(this).find("#percentoff").html('> 50% off');
$(this).find("#percentoff").addClass('badge50');
}
else if (29 < percentDiscount && percentDiscount < 50) {
$(this).find("#percentoff").html('> 30% off');
$(this).find("#percentoff").addClass('badge30');
}
else if (19 < percentDiscount && percentDiscount < 30) {
$(this).find("#percentoff").html('> 20% off');
$(this).find("#percentoff").addClass('badge30');
}
Run Code Online (Sandbox Code Playgroud)
你有错误的方式.让我们看一下第一个例子:
if (percentDiscount > 69 && percentDiscount > 101)
Run Code Online (Sandbox Code Playgroud)
(我颠倒了第一个条件,因为我认为它会使下一个更明显.)
所以percentDiscount必须大于69且大于101.你想要
if (69 < percentDiscount && percentDiscount < 101)
Run Code Online (Sandbox Code Playgroud)
这应该做你期望的.
| 归档时间: |
|
| 查看次数: |
761 次 |
| 最近记录: |