html - Google Apps 脚本 HTML 服务功能未运行 onclick
问题描述
我在 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:
<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;
}
推荐阅读
- r - 选择每第 n 行,偏移开始并重复
- python - 将一种引用类型复制到另一种的效果
- kubernetes - Istio HTTPRedirect 捕获组支持
- regex - 正则表达式查询:删除转义字符但保留字符串中的标点符号
- c# - 如何在 post 方法中将重音字符传递给 REST API
- php - Symfony\Component\Debug\Exception\FatalThrowableError: 参数 2 传递给 Illuminate\Auth\SessionGuard::__construct()
- python - 基于 CIFAR10 数据集类创建数据集时出错
- google-app-engine - 从 AppEngine 到 Cloud Function 的服务帐号身份
- java - 如何在 HashMap 中使用流 API
- c++ - __m128 何时在 xmm 寄存器中?