我正在尝试创建一个显示文本的自定义浏览器消息,您可以在下面看到该消息,还可以单击按钮说“确定”,另一个按钮说“带我去指导”单击时,打开另一个带有指南的选项卡。
这是我目前的代码:
function onEdit(e) {
var cell = e.range;
var cellColumn = cell.getColumn();
var cellSheet = cell.getSheet().getName();
var cellValue = e.value;
var sheet = "System_Info";
if (cellSheet !== sheet) {
if (cellColumn === 4 || cellColumn === 5) {
if (cellValue === "PT1 - Induction Training") {
Browser.msgBox('Course Information', "PT1 - Induction Training:\\n\\nType: Theory \\n\\nTime Needed: 15-20 Minutes\\n\\n Learning Resource/Manual: BBACT, Forum Post: Rules for Officers", Browser.Buttons.YES_NO); //Add the course name and the message that I want to popup. Course name should be exactly the same as in the list (case sensitive)
}
else if (cellValue === "PT2 - Traffic & Communications - Part 1") {
Browser.msgBox("PT2 - Traffic & Communications - Part 1 - Starting a Patrol/Loadouts: \\n\\nType: Practical \\n\\nTime Needed: 15-20 Minutes\\n\\n Learning Resource/Manual: PT2 Guide \\n Section: 1, 2"); //// add as many "else if" conditions as you want"
} else if (cellValue === "PT2 - Traffic & Communications - Part 2") {
Browser.msgBox("PT2 - Traffic & Communications - Part 2 - Checkpoints: \\n\\nType: Practical \\n\\nTime Needed: 40-60 Minutes\\n\\n Learning Resource/Manual: PT2 Guide \\n Section: 4");
} else if (cellValue === "PT2 - Traffic & Communications - Part 3") {
Browser.msgBox("PT2 - Traffic & Communications - Part 3 - Communications & Navigation: \\n\\nType: Practical & Theory (Still required to be on the server) \\n\\nTime Needed: 15-20 Minutes\\n\\n Learning Resource/Manual: PT2 Guide \\n Section: 5, 6, 7");
} else if (cellValue === "PT2 - Traffic & Communications - Part 4") {
Browser.msgBox("PT2 - Traffic & Communications - Part 4 - Faction Relations: \\n\\nType: Theory \\n\\nTime Needed: 15-20 Minutes\\n\\n Learning Resource/Manual: PT2 Guide \\n Section: 8");
} else if (cellValue === "PT3 - Officer Advancement - Part 1") {
Browser.msgBox("PT3 - Officer Advancement - Part 1: \\n\\nType: Theory \\n\\nTime Needed: 20-25 Minutes\\n\\n Learning Resource/Manual: BBACT, Forum Post: Rules for Officers, Forum Post: Sergeant Rules and Regulations, PT2 Guide");
} else if (cellValue === "PT3 - Officer Advancement - Part 2") {
Browser.msgBox("PT3 - Officer Advancement - Part 2: \\n\\nType: Practical \\n\\nTime Needed: 70 Minutes (1 Hour, 10 Minutes)\\n\\n Learning Resource/Manual: NONE, You are taught in-game.");
} else if (cellValue === "PT4 - Air Support") {
Browser.msgBox("PT4 - Air Support: \\n\\nType: Practical \\n\\nTime Needed: 15-25 Minutes\\n\\n Learning Resource/Manual: PT4 Guide");
} else if (cellValue === "PT5 - Interceptors") {
Browser.msgBox('Course Information',"PT5 - Interceptors: \\n\\nType: Practical \\n\\nTime Needed: 25-35 Minutes\\n\\n Learning Resource/Manual: PT5 Guide");
} else if (cellValue === "Planning to Attend") {
Browser.msgBox('Course Information',"You have chosen to attend this time. However, if you cannot attend training for what ever reason, please select the option, Sorry Can't Make It!");
} else if (cellValue === "Sorry Can't Make It!") {
Browser.msgBox('Course Information',"You have chosen not to attend this time. Please add a comment into the cell stating why you couldn't attend. It would also help if you could contact the instructor stating that you cannot attend.");
} else if (cellValue === "PT1 - Induction Training - Review") {
Browser.msgBox('Course Information',"This course is for people who have been instructed to redo the final 5 questions of PT1 based upon the restructure of the BB ACT");
} else if (cellValue === "PTE1 - Combat Tactics") {
Browser.msgBox('Course Information',"This training is optional but requires at least 5 officers to book it. This is a practical course. This training may take up to 1 hour.");
} else if (cellValue === "PT1 - Induction Training - Review") {
Browser.msgBox('Course Information',"This course is for people who have been instructed to redo the final 5 questions of PT1 based upon the restructure of the BB ACT");
}
else if (cellValue === undefined) { }
else {
Browser.msgBox('You have entered an invalid data, please select correct data corresponding to the Column.'); //This is in case they put a wrong course name
}
}
}
}
总结一下代码当前的作用,当用户从数据验证中提交输入时,它将运行if语句并找到该特定值并显示特定于该值的浏览器消息框。
如果if范围中没有值,则会转到else,否则显示消息表示无效数据。
我所坚持的是创建不是“YES_NO”的自定义按钮,如here所述
接下来,当用户按下按钮时,我仍然坚持如何使按钮将您带到外部链接。
例如,我想要的按钮是“Ok”和“Go to the guide”。好的,只需关闭消息框,同时指南按钮将您带到指南。
答案 0 :(得分:0)
您是否考虑过模态 - 他们会允许您提供自己的HTML,其中包括自定义按钮。
下面的文档 - 首先是关于模态对话框,第二个是关于自定义对话框的文档。他们有简单的例子可以帮助你入门。
1)https://developers.google.com/apps-script/reference/base/ui#showModalDialog(Object,String)
2)https://developers.google.com/apps-script/guides/dialogs#custom_dialogs
不相关,但是你可能想要考虑一个switch语句 - 如果你已经开始的话,那将是相当大的一部分。