Enum Button
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
Button
Enum ที่แสดงปุ่มกล่องโต้ตอบที่แปลแล้วซึ่งกําหนดไว้ล่วงหน้าซึ่ง alert
หรือ PromptResponse.getSelectedButton()
แสดงผลเพื่อระบุปุ่มในกล่องโต้ตอบที่ผู้ใช้คลิก คุณไม่สามารถตั้งค่าเหล่านี้ได้ หากต้องการเพิ่มปุ่มลงใน alert
หรือ prompt
ให้ใช้ ButtonSet
แทน
หากต้องการเรียกใช้ enum ให้เรียกคลาสหลัก ชื่อ และพร็อพเพอร์ตี้ของ enum นั้น เช่น
Base.Button.CLOSE
// Display a dialog box with a message and "Yes" and "No" buttons.
const ui = DocumentApp.getUi();
const response = ui.alert(
'Are you sure you want to continue?',
ui.ButtonSet.YES_NO,
);
// Process the user's response.
if (response === ui.Button.YES) {
Logger.log('The user clicked "Yes."');
} else {
Logger.log('The user clicked "No" or the dialog\'s close button.');
}
พร็อพเพอร์ตี้
พร็อพเพอร์ตี้ | ประเภท | คำอธิบาย |
CLOSE | Enum | ปุ่มปิดมาตรฐานที่แสดงในแถบชื่อของกล่องโต้ตอบทุกกล่อง ปุ่มนี้ไม่ได้เพิ่มลงในกล่องโต้ตอบอย่างชัดเจนและนำออกไม่ได้ |
OK | Enum | ปุ่ม "ตกลง" ซึ่งระบุว่าควรดําเนินการต่อ |
CANCEL | Enum | ปุ่ม "ยกเลิก" ซึ่งบ่งบอกว่าไม่ควรดําเนินการต่อ |
YES | Enum | ปุ่ม "ใช่" ซึ่งแสดงการตอบกลับเชิงบวกต่อคําถาม |
NO | Enum | ปุ่ม "ไม่" ซึ่งแสดงการตอบกลับเชิงลบต่อคําถาม |
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[[["\u003cp\u003e\u003ccode\u003eButton\u003c/code\u003e is an enum representing localized dialog buttons returned by alerts or prompts, indicating user action.\u003c/p\u003e\n"],["\u003cp\u003eThese predetermined button values (\u003ccode\u003eCLOSE\u003c/code\u003e, \u003ccode\u003eOK\u003c/code\u003e, \u003ccode\u003eCANCEL\u003c/code\u003e, \u003ccode\u003eYES\u003c/code\u003e, \u003ccode\u003eNO\u003c/code\u003e) cannot be set directly but are accessed via \u003ccode\u003eui.Button\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eTo add buttons to alerts or prompts, use \u003ccode\u003eButtonSet\u003c/code\u003e instead of individual \u003ccode\u003eButton\u003c/code\u003e values.\u003c/p\u003e\n"],["\u003cp\u003eThe provided example code demonstrates using \u003ccode\u003eButton\u003c/code\u003e to handle user responses from a dialog.\u003c/p\u003e\n"]]],[],null,["# Enum Button\n\nButton\n\nAn enum representing predetermined, localized dialog buttons returned by an [alert](/apps-script/reference/base/ui#alert(String)) or [PromptResponse.getSelectedButton()](/apps-script/reference/base/prompt-response#getSelectedButton()) to indicate\nwhich button in a dialog the user clicked. These values cannot be set; to add buttons to an\n[alert](/apps-script/reference/base/ui#alert(String,ButtonSet)) or [prompt](/apps-script/reference/base/ui#prompt(String,ButtonSet)), use [ButtonSet](/apps-script/reference/base/button-set) instead.\n\nTo call an enum, you call its parent class, name, and property. For example, `\nBase.Button.CLOSE`.\n\n```javascript\n// Display a dialog box with a message and \"Yes\" and \"No\" buttons.\nconst ui = DocumentApp.getUi();\nconst response = ui.alert(\n 'Are you sure you want to continue?',\n ui.ButtonSet.YES_NO,\n);\n\n// Process the user's response.\nif (response === ui.Button.YES) {\n Logger.log('The user clicked \"Yes.\"');\n} else {\n Logger.log('The user clicked \"No\" or the dialog\\'s close button.');\n}\n``` \n\n### Properties\n\n| Property | Type | Description |\n|----------|--------|---------------------------------------------------------------------------------------------------------------------------------------------|\n| `CLOSE` | `Enum` | The standard close button displayed in every dialog's title bar. This button is not explicitly added to a dialog, and it cannot be removed. |\n| `OK` | `Enum` | An \"OK\" button, indicating that an operation should proceed. |\n| `CANCEL` | `Enum` | A \"Cancel\" button, indicating that an operation should not proceed. |\n| `YES` | `Enum` | A \"Yes\" button, indicating a positive response to a question. |\n| `NO` | `Enum` | A \"No\" button, indicating a negative response to a question. |"]]