Class PromptResponse

PromptResponse

对 Google 应用界面环境中显示的 prompt 对话框的响应。该响应包含用户在对话框的输入字段中输入的任何文本,并指示用户点击了哪个按钮来关闭对话框。

// Display a dialog box with a title, message, input field, and "Yes" and "No" buttons. The
// user can also close the dialog by clicking the close button in its title bar.
var ui = DocumentApp.getUi();
var response = ui.prompt('Getting to know you', 'May I know your name?', ui.ButtonSet.YES_NO);

// Process the user's response.
if (response.getSelectedButton() == ui.Button.YES) {
  Logger.log('The user\'s name is %s.', response.getResponseText());
} else if (response.getSelectedButton() == ui.Button.NO) {
  Logger.log('The user didn\'t want to provide a name.');
} else {
  Logger.log('The user clicked the close button in the dialog\'s title bar.');
}

方法

方法返回类型简介
getResponseText()String获取用户在对话框的输入字段中输入的文本。
getSelectedButton()Button获取用户点击以关闭对话框的按钮。

详细文档

getResponseText()

获取用户在对话框的输入字段中输入的文本。即使用户通过点击带有负面含义的按钮(例如“取消”或对话框标题栏中的关闭按钮)关闭了对话框,该文本仍然可用。getSelectedButton() 有助于确定用户是否希望响应文本有效。

弃踢回攻

String - 用户在对话框的输入字段中输入的文本。


getSelectedButton()

获取用户点击以关闭对话框的按钮。如果用户点击了每个对话框标题栏中的关闭按钮,此方法会返回 Button.CLOSE

弃踢回攻

Button - 用户点击的按钮。