Jquery 如果值减去主值

Jquery if value is minus the main value

本文关键字:Jquery 如果      更新时间:2023-09-26

请问如何在 Jquery 中获取此工作? 我想使用 jquery 实现这一点需要您的帮助.. 示例如果 35000 - 349990 = - 314990

如果它显示-314990,我想向用户显示错误...

我想出这个没有帮助...

$("#apaid1").keyup(function () { // apaid input id for user to enter amount
    var textinput = $('#apaid1').val(); // get value from input id apaid1
    var textinput1 = $('#epayment1').val(); // get value from input id epayment1
    $("#bl1").val("" + textinput1 - textinput);
    // input id bl1 used as output
    if ($("#bl1").val() < textinput1) {
        $("#bl1").val("" + textinput1 - textinput);
    };
});

这就是它给我的-314990我想显示基于负值的错误

对不起,英语不好。谢谢。。。。

$("#apaid1").keyup(function(){ 
    var textinput = $('#apaid1').val(); 
    var textinput1 = $('#epayment1').val(); 
    /* I'm assuming that the "#bl1" tag is the input where you want to store the product of "textinput" and "textinput1"? */
    $("#bl1").val(textinput1 - textinput);
    //if the value is less than zero (e.g: a negative number), send an alert to the user.
    if ($("#bl1").val() < 0) {
        alert("Hey! Your answer resulted in a negative. Try again");
    };
});

我不完全确定为什么您将条件设置为"if ($("#bl1").val() <textinput1)>

使用此

条件检查负值。

 ($("#bl1").val() < 0)

我添加了

if(textinput1 - textinput < 0)
{
   alert("Error: Negative");
}

查看更新的 JSFIDDLE