我有一个孩子的功能alertMSGS所以alertMSGS功能检查中的四个变量的值,并给出一个警告消息,他们是不相等的,所以它会返回false父功能关闭功能,是DoSave()它的一个闭包函数,从我的知识(Begginer to Javascript)。所以如果返回是错误的,我需要退出保存,否则需要执行保存。 !见下文 。 许多感谢提前退出时,如果条件返回false
function alertMSGS(){
var currentWeekEarning = parseFloat($("#_fid_19").val());
var totalYearEarning= parseFloat($("label[for=_fid_39]").next("div").text().replace('$', '').replace(',', ''));
var currentLoss = parseFloat($("#_fid_20").val());
var totalYearLoss= parseFloat($("label[for=_fid_38]").next("div").text().replace('$', '').replace(',', ''))
if((currentWeekEarning != totalYearEarning)){
alert("currentWeekEarning Not Equal to totalYearEarning");
return false;
}
if (currentLoss != totalYearLoss) {
alert(' currentLoss Not Equal to totalYearLoss');
return false;
}
}
DoSave = (function(fn){
return function(){
var resultofalertMSGS = alertMSGS();
if (resultofalertMSGS === false) {
// so if the function returns false then i need to exit from the (DoSave Function) and if it satisfies then i need to perform the (DoSave Function)
}
var result=fn.apply(fn, arguments);
return result;
}
})(DoSave);
对不起,但是,你为什么要尝试做这么复杂的事情?你不能在'alertMSGS'函数外面写'DoSave'函数并调用它吗? – Fefux
是啊,我同意fefux – Sindhoor