【问题标题】:Google Form script & HTML won't execute the called scriptGoogle 表单脚本和 HTML 不会执行调用的脚本
【发布时间】:2013-06-13 15:46:03
【问题描述】:

我使用 html 页面在 Google 脚本中创建了一个表单,然后调用了一个 javascript 函数 as documented here。当我运行应用程序时,表单加载得很好,但它不会执行脚本。我怎样才能做到这一点?

这是我正在尝试做的一个示例:

<html>
  <!--Create Sign Out Form-->
  <form id="signOut">

    <div>
      Destination: 
      <select name="destination">
        <option value="lunch">Lunch</option>
        <option value="meeting">Client Meeting</option>
        <option value="vacation">Vacation</option>
        <option value="sick">Out Sick</option>
        <option value="personal">Personal</option>
        <option value="home">Working from Home</option>
        <option value="scedule">Reduced Schedule</option>
      </select>
    </div>

    <div>
      Supervisor: 
      <select name="supervisor" onselect="google.script.run.withUserObject(this.parentNode).populate(destination)"></select>
    </div>

    <div>
      Start Date: 
      <input type="date" name="startDate" onselect="google.script.run.withUserObject(this.parentNode).SignOutLibrary.dateSelect()"/>
    </div>

    <div>
      End Date: 
      <input type="date" name="endDate" onselect="google.script.run.withUserObject(this.parentNode).SignOutLibrary.dateSelect()"/>
    </div>

    <div>
      Details: 
      <textarea type="text" name="details" style="width: 150px; height: 75px;"></textarea>
    </div>

    <div>
      <input type="button" value="Submit"
        onclick="google.script.run
             .sendRequest(this.parentNode)"/>
    </div>
  </form>
</html>

以及它应该调用的脚本:

function doGet() {
  // Uses html form
  return HtmlService.createHtmlOutputFromFile('request_form');
}

SignOutLibrary:

function dateSelect() {
  var app = UiApp.createApplication();
  var handler = app.createServerHandler("change");
  var date = app.createDatePicker().setPixelSize(150, 150).addValueChangeHandler(handler).setId("date");
  app.add(date);
  return app;
}

function change(eventInfo) {
  var app = UiApp.getActiveApplication();
  app.add(eventInfo.parameter.date);
  return app;
}

【问题讨论】:

  • 控制台有错误吗?
  • 我还没遇到过。 (假设您正在谈论记录器,因为没有控制台:/)
  • 我在文档中看到有一个onclick,有谁知道是否支持onselect
  • 另一个更新:我的提交按钮的 onclick 脚本不起作用?我什至尝试从头开始建立一个全新的库和表单,以确保这不是我选择的某个选项,它们仍然没有运行。
  • AFAIK google-form 适用于 Google 表单应用程序,不适用于使用 Google Apps 脚本的 HTML 服务创建的表单。应删除此标记。

标签: javascript html google-apps-script


【解决方案1】:

尝试使用 this.form 更改代码中的所有 this.parentNode

我很快查看了文档,也许它会起作用,抱歉,我现在无法测试我的答案

【讨论】:

    【解决方案2】:

    你没有显示populate() - 希望你确实有这样的功能。如果您这样做了,那么您的下一个任务是找到一种方法来获取您作为参数传递的destination 的值。以目前的形式,它是未定义的。见Get selected value in dropdown list using JavaScript?

    您不能直接使用脚本运行程序调用库函数,请参阅Private Functions 上的位。您需要将中间函数添加到“本地”gs 以与库函数(例如 SignOutLibrary.dateSelect())进行交互。

    该库使用 UiApp,而您的其余代码使用 Html 服务。选择一个或另一个,因为你不能像这样混合它们。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-28
      • 1970-01-01
      • 2014-02-15
      • 1970-01-01
      • 2020-07-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多