[英]How can i change the negative numbers to 0 from my webpage
I'm trying to convert or disable the negative numbers to 0 on my 我正在尝试将我的负数转换或禁用为0
Website which appear when i select some products on the column 'Unidad Minima' and 'Unidad Maxima'for example 10 or more for each one. 当我在“ Unidad Minima”和“ Unidad Maxima”列上选择一些产品(例如,每个产品有10个或更多)时出现的网站 。
I've tried by using the format number jquery plugin but it didn't work in this case. 我已经尝试过使用格式编号jquery插件,但在这种情况下不起作用。
There is some code from my webpage. 我的网页上有一些代码。
$("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));
} }
Some comment will be apreciated. 一些评论将不胜感激。
Thanks! 谢谢!
如果不是这样,您可以使用short:
$('.val5', this).html((cantidadesminimas < 0 ? 0 : cantidadesminimas));
You could use the built in Math.max(x, 0) method. 您可以使用内置的Math.max(x,0)方法。 The result will be which ever is highest, your input or zero.
结果将是您输入的最高值或为零,以最高者为准。
eg 例如
var x = -1;
var a = Math.max(x, 0);
If 'x' is negative 'a' will be zero else 'a' will be equal to 'x'. 如果“ x”为负,“ a”将为零,否则“ a”将等于“ x”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.