我正在开发发票项目,在零件部分,我有公司价格和客户价格。
细分如下:
1
至4.99
,则为14.95
5
至49.99
,则价格为4*
第一个if
语句有效但第二个没有,有什么想法吗?
var five = 4.99;
var fifty = 49.99;
var four = 4;
var fourteenninefive = 14.95;
var qty4 = h.find('[name="requestpartquantity[]"]');
var price4 = h.find('[name="requestpartdb[]"]');
var total4 = h.find('[name="requestcustomerpartdb[]"]');
if (price4 < five ) {
total4.val(qty4.val() * fourteenninefive);
} else if (price4 <= fifty ) {
total4.val(qty4.val() * price4.val() * four);
} else {
}
我尝试了你的建议,但仍然关闭,请参见下面的截图:
total4.val((+qty4.val()) * (+price4.val()) * four);
如果零件价格为10
,则表示客户总数应为80
10(Price) * 2(quantity) * 4 = 80
答案 0 :(得分:1)
假设您从具有<input>
属性的某些name
获取价格,您应该将它们转换为整数(这是我的代码中的+
)。此外,您忘记在.val()
上使用price4
方法。
var five = 4.99;
var fifty = 49.99;
var four = 4;
var fourteenninefive = 14.95;
var qty4 = h.find('[name="requestpartquantity[]"]');
var price4 = h.find('[name="requestpartdb[]"]');
var total4 = h.find('[name="requestcustomerpartdb[]"]');
if (+price4.val() < five ) {
total4.val(+qty4.val() * fourteenninefive);
} else if (+price4.val() <= fifty ) {
total4.val((+qty4.val()) * (+price4.val()) * four);
} else {
}
更具可读性的替代方案是使用内置的parseInt()
函数。