我有一個孩子的功能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