我在用户界面中有一个时钟,当我将鼠标悬停时会看到一个日期。过期后,我应该只会看到单词Expired,但是我会看到日期和过期。请检查屏幕截图:clock hover expired我分享了。
我正在与您共享执行此操作的代码,并且我肯定在这里犯了一个错误:
$scope.getBannerScheduledTitle = function(banner) {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
var banner_from = null;
var banner_to = null;
if(banner.from){
var pFromDate = new Date(banner.from);
if($scope.countrycode == "US")
banner_from = (pFromDate.getMonth()+1) + "/" + pFromDate.getDate() + "/" + pFromDate.getFullYear();
else
banner_from = pFromDate.getDate() + "/" + (pFromDate.getMonth()+1) + "/" + pFromDate.getFullYear();
}
if(banner.to){
var pToDate = new Date(banner.to);
if($scope.countrycode == "US")
banner_to = (pToDate.getMonth()+1) + "/" + pToDate.getDate() + "/" + pToDate.getFullYear();
else
banner_to = pToDate.getDate() + "/" + (pToDate.getMonth()+1) + "/" + pToDate.getFullYear();
}
if(dd<10) {
dd='0'+dd
}
if(mm<10) {
mm='0'+mm
}
today = dd+'/'+mm+'/'+yyyy;
var title = "";
if (banner.from && banner.to == null)
title += "from " + banner_from + " to " + " ... ";
if (banner.to && banner.from == null)
title += "from " + today + " to " + banner_to;
if (banner.to && banner.from)
title += "from " + banner_from + " to " + banner_to;
if (banner.expired === true)
title += "Expired";
return title;
}
最佳答案
嗯,我认为您只需要更改以下内容:
(...) if (banner.expired === true)
title += "Expired";
return title;
至:
if (banner.expired === true)
title = "Expired";
return title;
告诉我。