【发布时间】:2020-11-17 14:44:13
【问题描述】:
我正在尝试在 Google 网络应用上显示生日提醒消息,其中数据存储在 Google 表格中。
我在部署的网络应用程序上收到的消息是 --> 今天是 undefined 的生日。
下面是我的脚本代码
function main() {
var sheet = SpreadsheetApp.getActive().getSheetByName("Birthdays");
var numRows = sheet.getLastRow();
var range = sheet.getRange(2, 1, numRows - 1, 2).getValues();
for(var index in range) {
var row = range[index];
var name = row[0];
var birthday = row[1];
if(isBirthdayToday(birthday)) {
displayReminder(name);
}
}
}
// Check if a person’s birthday is today
function isBirthdayToday(birthday) {
var today = new Date();
if((today.getDate() === birthday.getDate()) &&
(today.getMonth() === birthday.getMonth())) {
return true;
} else {
return false;
console.log(today);
}
}
// Function to display the reminder
function displayReminder(name) {
var message = "It is " + name + " 's birthday today.";
return message;
console.log(displayReminder);
}
HTML
<div>
<script>
function onSuccess(quote) {
var div = document.getElementById('Bday');
div.innerHTML = quote;
}
google.script.run.withSuccessHandler(onSuccess)
.displayReminder();
</script>
<em> <p id="Bday"></p></em>
</div>
注意:当我为函数 isBirthdayToday(birthday) 运行控制台日志时,出现以下错误。
TypeError:无法读取未定义的属性“getDate”(第 25 行,文件“代码”)
我不知道我哪里出错了。发生了什么错误?
【问题讨论】:
-
您是否考虑过只为您所有的生日使用日历,然后只需在该日历中查找您的日常活动,然后您就会获得当天的所有生日
标签: javascript google-apps-script google-sheets