[英]Onkey up Second input value should not be greater than first value
I have three input values one for payment, second for advance payment and third for remaining balance from actual_payment to advance_payment. 我有三个输入值,一个用于付款,第二个用于预付款,第三个用于从实际付款到预付款的余额。
If the advance payment is greater than acutal payment, the advance payment should not be enter. 如果预付款大于预付款,则不应输入预付款。
<input type="text" id="actual_payment" value="">
<input type="text" id="advance_payment" value="">
<input type="text" id="balance_payment" value="">
How to compare advance payment should not greater actual payment and remaining balance should not be greater than actual payment and advance payment. 如何比较预付款应不大于实际付款,余额应不大于实际付款和预付款。
Here is my jquery code 这是我的jQuery代码
$(function(){
$("#advance_payment").on('keyup', function(){
var actual_payment = $("#actual_budget").val();
$("#balance_payment").val(actual_payment-$(this).val());
if ($("#advance_payment").val()>$("#actual_budget")) {
alert("sorry the advance payment should be less actual payment");
}
})
});
The following returns a string: 以下返回一个字符串:
$("#actual_budget").val()
You probably want to use the parseFloat() function: 您可能要使用parseFloat()函数:
parseFloat($("#actual_budget").val());
That will apply to any field that you retrieve as a decimal number. 这将适用于您检索为十进制数字的任何字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.