我对 JavaScript 很陌生,对 Google Apps 脚本更陌生。我正在尝试一个简单的函数来显示当前日期(仅日、月和全年),但 Google 脚本显示错误 ReferenceError:“document”未定义。
我的目标是在 Google 网站中使用此功能。这是代码:
function Data()
{
var d=new Date();
var dia=d.getDate();
var mes=d.getMonth();
var ano=d.getFullYear();
var DataCompleta=dia + "/" + mes + "/" + ano
document.write(DataCompleta);
}
最佳答案
作为 Google Apps 脚本运行的代码不在浏览器中运行,因此您无法使用网络浏览器 API。如果您想将内容输出到Google网站,那么您需要使用API for Sites .
大概你会想要像 createWebPage
这样的东西然后使用 the methods on the resulting object将内容添加到其中。
关于javascript - ReferenceError: "document"未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13552250/