【问题标题】:Google Apps Script HTML Service function not running onclickGoogle Apps 脚本 HTML 服务功能未运行 onclick
【发布时间】:2020-06-13 10:20:05
【问题描述】:

我在 Google Apps 脚本 HTML 服务页面上有一个表单。当我点击提交按钮时,什么也没有发生。

按钮上的代码是

<input type="submit" value="Submit" class="submit" 
    onclick="google.script.run
                       .withSuccessHandler(google.script.host.close)
                       .updateText(this.parentNode)"/>
<button class="button cancel" onclick="google.script.host.close()">Cancel</button>

提交按钮的代码是从另一个项目中提取的,它运行良好。 取消按钮的代码工作正常。

目前,当我点击提交按钮时没有任何反应(窗口没有关闭,updateText() 函数没有运行。

updateText() 如果我在脚本编辑器中手动调用它,它运行良好(它只是将一个值放在一个固定字段中以进行调试)。

function updateText(form){
  var ss = SpreadsheetApp.openById("sheet_id");
  ss.getActiveSheet().getRange(3,3).setValue("Test"); 
}

【问题讨论】:

  • 什么脚本/代码调用了html页面?显示它。
  • 您检查控制台是否有错误?如果是这样,您收到哪个错误?

标签: html google-apps-script


【解决方案1】:

试试这样:

HTML:

<form>
<!-- along with the rest of your form -->
<input type="button" value="Submit" class="submit" onclick="updateText(this.parentNode);"/>
<input type="button" value="Cancel" onclick="google.script.host.close()" />
</form>
<script>
  function updateTest(obj) {
  google.script.run
.withSuccessHandler(function(){google.script.host.close();})
.updateText(obj);
  }
  </script>

GS:

function updateText(form){
  var ss = SpreadsheetApp.openById("sheet_id");
  ss.getActiveSheet().getRange(3,3).setValue("Test"); 
  return;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多