对 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
- 用户在对话框输入字段中输入的文本。