You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Apps Script生成Google表单:多选项子版块跳转问题求助

解决Google Apps Script表单版块跳转问题

问题出在你对表单跳转逻辑的理解上:页面分隔符(PageBreakItem)本身不支持设置跳转,表单的导航规则是绑定在**问题(FormItem)**上的——用户提交某个问题的答案后,才会执行对应的跳转动作。你之前尝试给sectionOne(页面分隔符)调用setGoToPage,自然不会生效。

正确的做法是:给每个子版块的最后一个问题设置跳转,让用户回答完该问题后直接跳转到指定的nextPage。

修改后的完整代码

// 先创建目标跳转页,确保后续可引用
var nextPage = form.addPageBreakItem()
    .setTitle("The next page")
    .setHelpText("This is the next page I would need to be redirected to after answering to any subsections of the mci");

// 设置多选问题
let mci = form.addMultipleChoiceItem()
      .setTitle("Question")
      .setRequired(true) 
    
// 设置第一版块
var sectionOne = form.addPageBreakItem()
    .setTitle("First Section")
    .setHelpText("This is the first section");

// 给版块最后一个问题添加跳转
form.addTextItem()
    .setTitle("Question inside section one")
    .setRequired(true)
    .setGoToPage(nextPage); // 关键:回答后跳转到nextPage

// 设置第二版块
var sectionTwo = form.addPageBreakItem()
    .setTitle("Second section")
    .setHelpText("This is the second section");

form.addTextItem()
    .setTitle("Question inside section two")
    .setRequired(true)
    .setGoToPage(nextPage); // 关键:添加跳转

// 设置第三版块
var sectionThree = form.addPageBreakItem()
    .setTitle("Third section")
    .setHelpText("This is the third section");

form.addTextItem()
    .setTitle("Question inside section three")
    .setRequired(true)
    .setGoToPage(nextPage); // 关键:添加跳转

// 关联多选答案与对应版块
mci.setChoices([
  mci.createChoice("first answer", sectionOne),
  mci.createChoice("second answer", sectionTwo),
  mci.createChoice("third answer", sectionThree)
]);

核心修改点

  1. 调整nextPage的创建顺序:先创建nextPage,确保后续给问题设置跳转时能正确引用这个页面
  2. 给每个版块的最后一个问题绑定跳转:调用setGoToPage(nextPage),让用户回答完该问题后直接跳转到目标页,不会继续走默认的表单流程进入其他版块

这样设置后,用户选择任一选项进入对应版块,完成版块内的问题后会直接跳转到nextPage,不会再进入其他子版块。

内容的提问来源于stack exchange,提问作者ElPaul0

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 17:23:28