Class PromptResponse

PromptResponse

การตอบกลับกล่องโต้ตอบ prompt ที่แสดงในสภาพแวดล้อมของอินเทอร์เฟซผู้ใช้สำหรับแอป Google การตอบกลับมีข้อความใดๆ ที่ผู้ใช้ป้อนในช่องป้อนข้อมูลของกล่องโต้ตอบ และระบุปุ่มที่ผู้ใช้คลิกเพื่อปิดกล่องโต้ตอบ

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

รับข้อความที่ผู้ใช้ป้อนในช่องป้อนข้อมูลของกล่องโต้ตอบ ข้อความจะยังคงอยู่แม้ว่า ผู้ใช้จะปิดกล่องโต้ตอบโดยคลิกปุ่มที่มีความหมายในเชิงลบ เช่น "ยกเลิก" หรือ ปุ่มปิดในแถบชื่อของกล่องโต้ตอบ getSelectedButton() จะช่วยพิจารณา ว่าผู้ใช้ต้องการให้ข้อความตอบกลับถูกต้องหรือไม่

รีเทิร์น

String — ข้อความที่ผู้ใช้ป้อนในช่องป้อนข้อมูลของกล่องโต้ตอบ


getSelectedButton()

รับปุ่มที่ผู้ใช้คลิกเพื่อปิดกล่องโต้ตอบ หากผู้ใช้คลิกปุ่มปิด ที่รวมอยู่ในแถบชื่อของกล่องโต้ตอบทุกกล่อง เมธอดนี้จะแสดง Button.CLOSE

รีเทิร์น

Button — ปุ่มที่ผู้ใช้คลิก