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()

取得使用者在對話方塊輸入欄位輸入的文字。即使使用者點選帶有負註解 (例如「Cancel」) 的按鈕 (例如「Cancel」或對話方塊標題列中的關閉按鈕) 關閉對話方塊,文字仍會顯示。getSelectedButton() 可協助判斷使用者預期的回應文字是否有效。

回攻員

String:使用者在對話方塊輸入欄位輸入的文字。


getSelectedButton()

取得使用者點擊關閉對話方塊的按鈕。如果使用者點選每個對話方塊標題列中包含的關閉按鈕,這個方法會傳回 Button.CLOSE

回攻員

Button:使用者點選的按鈕。