不能使用this.ParentNode从HTML页面调用Google脚本

Cannot call Google script from HTML page using this.ParentNode

本文关键字:调用 Google 脚本 HTML this ParentNode 不能      更新时间:2023-09-26

我也问过类似的问题。我似乎无法让onclick事件为我触发。有没有什么显而易见的东西能帮到我。函数写在下面的代码

<div id= "right_column">
    <form>
      <input type="button" name="enter_grades" id="enter_grades" value="Enter Grades for Selected Lessons"
              onclick="google.script.run.withSuccessHandler(showMsgForLoginAttempt).generate_grades_for_lesson(this.parentNode)" /> 
    </form>

</div>
这是gscript函数
function generate_grades_for_lesson(formObject) {
    Browser.msgBox("Hello");
}

我记得大约一年前我为此挣扎了很久。经过几个小时的辛苦工作,我终于让它工作了,让我分享一些我的代码,也许它会有所帮助。

首先在您的页面的<head></head>(假设您有一个格式良好的HTML页面),您可以添加一个错误处理程序:

<script>
  function onFailure(error) {
    var div = document.getElementById('output');
    div.innerHTML = "ERROR: " + error.message;
  }
</script>

然后在您的<body>结束前添加一个"output"div:

<div id="output"></div>

当你点击

按钮时,这会输出一些你之前没有意识到的错误。

最后是我使用的"onclick":onclick="google.script.run.withFailureHandler(onFailure).FUNCTIONNAME(this.parentNode)"

希望这对你有帮助!