Class 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. const ui = DocumentApp.getUi(); const 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」或對話方塊標題列中的關閉按鈕等具有負面含義的按鈕,系統仍會顯示這段文字。getSelectedButton() 可協助判斷使用者是否希望回應文字有效。

回攻員

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


getSelectedButton()

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

回攻員

Button:使用者按下的按鈕。