简体   繁体   中英

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

Website which appear when i select some products on the column 'Unidad Minima' and 'Unidad Maxima'for example 10 or more for each one.

I've tried by using the format number jquery plugin but it didn't work in this case.

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. 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'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM