0
我有三个输入值,一个用于付款,第二个用于预付款 ,第三个用于从actual_payment到advance_payment的剩余余额。Onkey up第二个输入值不应大于第一个值
如果预付款超过实际付款,则不应输入预付款。
<input type="text" id="actual_payment" value="">
<input type="text" id="advance_payment" value="">
<input type="text" id="balance_payment" value="">
如何比较预付款不应超过实际付款余额不应超过实际付款和预付款。
这里是我的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");
}
})
});
你可能会在结果中得到'NaN',因为你减去了字符串,试着改变这些输入的类型到'number'(或者用'parseInt'解析这个值),它也应该是'if ($(“#advance_payment”).val()> $(“#actual_budget”).val())' –
实际上,在if()中代替'$(“#actual_budget”)'是'actual_payment'。 –