简体   繁体   English

如何从网页上将负数更改为0

[英]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.

相关问题 如何从数组中减去数字以使总数为 0。我想跳过会使总数为负数的数字 - 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 我怎样才能让我的计数器停在 0? 它递减为负数 - How can I get my counter to stop at 0? It decrements to negative numbers 如何解决负数的问题? - How can I fix the problem with negative numbers? 如何将我的 v-text-field 设置为不显示负数? - How can i set my v-text-field to not show negative numbers? 如何从网页中删除一些JavaScript? - How can I remove a some javascript from my webpage? 如何将内容从博客中提取到我的网页上? - How can I pull content from blogger onto my webpage? 如何从我的网页运行本地服务器脚本? - how can i run a local server script from my webpage? 如何在网页上显示JSON中的数据? - How can I display the data from the JSON on my webpage? 如何在 javascript 中对带有负数的表进行排序 - How can I sort a table with negative numbers in javascript 如何在布尔值的子类化中更改字符串表示形式,而又不会在函数外部产生负面影响? - How can I subclass Boolean to change string representation without negative side effects outside of my function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM