有人可以帮助以下代码吗?这似乎是不正确的。
如何从回调中返回布尔值,并检查是否可以继续。
在我看来,布尔值始终为 true,并且永远不会返回 false。
还请描述代码在您更正后如何对我起作用。谢谢你。
$("#divContent").on('blur', "input[id^='cak4premium0']", function () {
var selectedPayoutFreq = $('input[name=SelectedPayoutFrequency]:checked').val();
if (typeof selectedPayoutFreq === "undefined") {
alert("Please select Payout Frequency");
return;
}
var selectedValue = $(this).val();
if (selectedValue = '') {
alert("Please enter Premium");
return;
}
var premiumValid = checkPremiumAmount();
if (premiumValid) {
var url = "/Annuity/Home/CalculateAnnuityPayout";
var data = GetAnnuityMainPlan();
data.SelectedPayoutFrequency = selectedPayoutFreq;
$.post(url, data, DisplayCountAnnuity);
}
});
function checkPremiumAmount() {
var url = "/Annuity/Home/GetAnnuityMinMaxPremium";
var data = GetAnnuityMainPlan();
var currentPlan = $('.selectPlan').val();
var retValue = true;
$.post(url, data, null).done(function (data) {
minPremium = data.MinPremium;
maxPremium = data.MaxPremium;
var premium = data.Premium;
if (premium < minPremium) {
if (currentPlan == 'CAK4') {
alert("The minimum Premium is $" + minPremium);
$("input[id^='cak4premium0']").val(minPremium);
retValue = false;
}
else if (currentPlan == 'GAK4') {
alert("For single premium less than " + minPremium + ", annuity installment will be paid yearly.");
$("input[id^='cak4premium0']").val(minPremium);
retValue = false;
}
}
if (premium > maxPremium) {
alert("The maximum Premium is " + maxPremium);
$("input[id^='cak4premium0']").val(maxPremium);
retValue = false;
}
return retValue;
});
}