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
:使用者在對話方塊輸入欄位輸入的文字。