提示在 google 应用程序脚本中不起作用
Prompt not working in google apps script
我正在创建一个 google 脚本,目的是向我提问、获取日期并将其全部放入一个新文档中。它通过提示获取信息。当我点击 run
时,它显示 'ReferenceError: "prompt" is not defined. (line 16, file "Code")'。我的代码如下:
function myFunction() {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10) {
dd='0'+dd
}
if(mm<10) {
mm='0'+mm
}
today = mm+'/'+dd+'/'+yyyy;
var prompted = prompt('How was recycling today?');
DriveApp.createFile('Recycle log for ' + today, prompted, 'GOOGLE_DOCS');
logger.log('On ' + today + ', recycling statistics were:' + prompted);
}
我该如何解决这个问题?如果我做不到,我怎么能做同样的事情?
Google 应用程序脚本基于 JavaScript,用于自动化 google 应用程序以及创建附加组件或构建 Web 应用程序,但 google 应用程序脚本在服务器而不是客户端的浏览器上运行,因此它不支持本机 JavaScript 功能,如 alert
、prompt
等
但是,google 应用脚本提供了 HTML Service,您可以使用它来为您的输入创建用户界面。
此外,如果您的脚本是Document bound script, you can use method like getUi which will return you UI Class through which you can show popups and dialog like alert and prompt, or even design your own dialog or sidebar。
例如:
DocumentApp.getUi().alert("Hello world.");
或
var ui = SpreadsheetApp.getUi();
var response = ui.prompt('May I know your name?', ui.ButtonSet.YES_NO);
按照文档中的 examples 进行操作。
我正在创建一个 google 脚本,目的是向我提问、获取日期并将其全部放入一个新文档中。它通过提示获取信息。当我点击 run
时,它显示 'ReferenceError: "prompt" is not defined. (line 16, file "Code")'。我的代码如下:
function myFunction() {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10) {
dd='0'+dd
}
if(mm<10) {
mm='0'+mm
}
today = mm+'/'+dd+'/'+yyyy;
var prompted = prompt('How was recycling today?');
DriveApp.createFile('Recycle log for ' + today, prompted, 'GOOGLE_DOCS');
logger.log('On ' + today + ', recycling statistics were:' + prompted);
}
我该如何解决这个问题?如果我做不到,我怎么能做同样的事情?
Google 应用程序脚本基于 JavaScript,用于自动化 google 应用程序以及创建附加组件或构建 Web 应用程序,但 google 应用程序脚本在服务器而不是客户端的浏览器上运行,因此它不支持本机 JavaScript 功能,如 alert
、prompt
等
但是,google 应用脚本提供了 HTML Service,您可以使用它来为您的输入创建用户界面。
此外,如果您的脚本是Document bound script, you can use method like getUi which will return you UI Class through which you can show popups and dialog like alert and prompt, or even design your own dialog or sidebar。
例如:
DocumentApp.getUi().alert("Hello world.");
或
var ui = SpreadsheetApp.getUi();
var response = ui.prompt('May I know your name?', ui.ButtonSet.YES_NO);
按照文档中的 examples 进行操作。