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.
一些评论将是apreciated。
Thanks!
2 个解决方案
#1
You could use the short if else like this:
你可以像这样使用short if else:
$('.val5', this).html((cantidadesminimas < 0 ? 0 : cantidadesminimas));
#2
You could use the built in Math.max(x, 0) method. The result will be which ever is highest, your input or zero.
您可以使用内置的Math.max(x,0)方法。结果将是最高的,您的输入或零。
e.g.
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'。
#1
You could use the short if else like this:
你可以像这样使用short if else:
$('.val5', this).html((cantidadesminimas < 0 ? 0 : cantidadesminimas));
#2
You could use the built in Math.max(x, 0) method. The result will be which ever is highest, your input or zero.
您可以使用内置的Math.max(x,0)方法。结果将是最高的,您的输入或零。
e.g.
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'。