การตอบกลับกล่องโต้ตอบ 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. 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" หรือ
ปุ่มปิดในแถบชื่อของกล่องโต้ตอบ' getSelectedButton()
สามารถช่วยตัดสินว่าผู้ใช้มีเจตนาให้ข้อความตอบกลับถูกต้องหรือไม่
ไปกลับ
String
— ข้อความที่ผู้ใช้ป้อนในช่องป้อนข้อมูลของกล่องโต้ตอบ
getSelectedButton()
รับปุ่มที่ผู้ใช้คลิกเพื่อปิดกล่องโต้ตอบ หากผู้ใช้คลิกปุ่มปิดที่อยู่ในกล่องโต้ตอบชื่อของกล่องโต้ตอบทุกปุ่ม เมธอดนี้จะแสดงผล Button.CLOSE
ไปกลับ
Button
— ปุ่มที่ผู้ใช้คลิก