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()
取得使用者在對話方塊輸入欄位中輸入的文字。即使使用者按下「Cancel」或對話方塊標題列中的關閉按鈕等具有負面含義的按鈕,系統仍會顯示這段文字。getSelectedButton()
可協助判斷使用者是否希望回應文字有效。
回攻員
String
:使用者在對話方塊輸入欄位中輸入的文字。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003e\u003ccode\u003ePromptResponse\u003c/code\u003e objects store user input and button selections from prompts in Google Apps Script UI.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003egetResponseText()\u003c/code\u003e retrieves the text entered by the user in the prompt's input field.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003egetSelectedButton()\u003c/code\u003e identifies which button the user clicked to close the prompt (e.g., YES, NO, CLOSE).\u003c/p\u003e\n"],["\u003cp\u003eThis data allows scripts to react differently based on user interaction with the prompt dialog.\u003c/p\u003e\n"]]],[],null,["# Class PromptResponse\n\nPromptResponse\n\nA response to a [prompt](/apps-script/reference/base/ui#prompt(String)) dialog displayed in the\nuser-interface environment for a Google App. The response contains any text the user entered in\nthe dialog's input field and indicates which button the user clicked to dismiss the dialog.\n\n```javascript\n// Display a dialog box with a title, message, input field, and \"Yes\" and \"No\"\n// buttons. The user can also close the dialog by clicking the close button in\n// its title bar.\nconst ui = DocumentApp.getUi();\nconst response = ui.prompt(\n 'Getting to know you',\n 'May I know your name?',\n ui.ButtonSet.YES_NO,\n);\n\n// Process the user's response.\nif (response.getSelectedButton() === ui.Button.YES) {\n Logger.log('The user\\'s name is %s.', response.getResponseText());\n} else if (response.getSelectedButton() === ui.Button.NO) {\n Logger.log('The user didn\\'t want to provide a name.');\n} else {\n Logger.log('The user clicked the close button in the dialog\\'s title bar.');\n}\n``` \n\n### Methods\n\n| Method | Return type | Brief description |\n|---------------------------------------------|----------------------------------------------|------------------------------------------------------------------|\n| [getResponseText()](#getResponseText()) | `String` | Gets the text that the user entered in the dialog's input field. |\n| [getSelectedButton()](#getSelectedButton()) | [Button](/apps-script/reference/base/button) | Gets the button that the user clicked to dismiss the dialog. |\n\nDetailed documentation\n----------------------\n\n### `get``Response``Text()`\n\nGets the text that the user entered in the dialog's input field. The text is available even if\nthe user closed the dialog by clicking a button with a negative connotation, like \"Cancel\" or\nthe close button in the dialog's title bar. [getSelectedButton()](#getSelectedButton()) can help to determine\nwhether the user intended the response text to be valid.\n\n#### Return\n\n\n`String` --- The text that the user entered in the dialog's input field.\n\n*** ** * ** ***\n\n### `get``Selected``Button()`\n\nGets the button that the user clicked to dismiss the dialog. If the user clicked the close\nbutton that is included in every dialog's title bar, this method returns [Button.CLOSE](/apps-script/reference/base/button#CLOSE).\n\n#### Return\n\n\n[Button](/apps-script/reference/base/button) --- The button that the user clicked."]]