[英]How can I subtract numbers from an Array to get my total to 0. I want to skip numbers that would make my total a negative
[英]How can i change the negative numbers to 0 from my webpage
我正在尝试将我的负数转换或禁用为0
当我在“ Unidad Minima”和“ Unidad Maxima”列上选择一些产品(例如,每个产品有10个或更多)时出现的网站 。
我已经尝试过使用格式编号jquery插件,但在这种情况下不起作用。
我的网页上有一些代码。
$("tr.txtMult").each(function () {
var $val3 = $('.val3', this).val();
cantidadesminimas = (8260 - cantidadfinal) / $val3;
cantidadesmaximas = (12390 - cantidadfinal) / $val3;
$('.val5', this).html(cantidadesminimas.toFixed(0));
$('.val6', this).html(cantidadesmaximas.toFixed(0));
});
$("#cantidadmin").html(8260 - cantidadfinal.toFixed(0));
$("#cantidadmax").html(12390 - cantidadfinal.toFixed(0));
}
一些评论将不胜感激。
谢谢!
如果不是这样,您可以使用short:
$('.val5', this).html((cantidadesminimas < 0 ? 0 : cantidadesminimas));
您可以使用内置的Math.max(x,0)方法。 结果将是您输入的最高值或为零,以最高者为准。
例如
var x = -1;
var a = Math.max(x, 0);
如果“ x”为负,“ a”将为零,否则“ a”将等于“ x”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.