javascript - Google App Script 和 Javascript:访问 div 标签内的表单元素
问题描述
我想访问表单和 div 中的输入元素。我是 Google 应用脚本的新手,我相信我需要将包含 DOM 地址的参数从 JS 函数传递给应用脚本函数。
这是代码:
Javascript:
<script>
function update()
{
google.script.run.selectCell(document.getElementById(location));
alert("Success");//test message
}
</script>
HTML 代码:
<div class="container">
<form>
<div class="row">
<div class="col-25">
<label for="location">Location</label>
</div>
<div class="col-75">
<input type="text" id="location" name="location_txt" placeholder="The location..">
</div>
</div>
<div class="row">
<input type="button" onclick="update()" value="Update">
</div>
谷歌应用脚本:
function selectCell(domAddress)
{
var val0 = domAddress.value;
if (cell)
{
sheet.appendRow([val0]);
}
}
解决方案
问题:
- DOM 元素,除了表单元素不是服务器端函数的合法参数
解决方案:
- 将表单本身传递给服务器端函数,该函数将转换为表单对象。
修改代码:
客户端:
<div class="container">
<form id ="myForm">
<div class="row">
<div class="col-25">
<label for="location">Location</label>
</div>
<div class="col-75">
<input type="text" id="location" name="location_txt" placeholder="The location..">
</div>
</div>
<div class="row">
<input type="button" onclick="update()" value="Update">
</div>
</form>
<script>
function update()
{
google.script.run.selectCell(document.getElementById('myForm'));
alert("Success");//test message
}
</script>
服务器端:
function selectCell(formObject)
{
var val0 = formObject['location_txt']
if (val0)
{
sheet.appendRow([val0]);
}
}
读书:
推荐阅读
- jekyll - 在 GitHub 页面上托管下一个应用程序时未加载 js 和 css
- arrays - 无法快速访问数组中的特定结构。不断收到此错误“无法调用非函数类型的值”“”
- python - 如何获得熊猫数据框每列的最大小数位数?
- python-3.x - Matplotlib 使用 DataFrame 中的值进行注释
- angular - 是否可以使用 angularfire2 在 Firestore 中创建顶级集合?
- curl - 为什么我总是卷曲:(60)服务器证书验证失败。CAfile:/etc/ssl/certs/ca-certificates.crt CRLfile:无?
- java - Java中ArrayList方法的“For”循环问题
- firebase - 使用 Firebase 电子邮件和密码身份验证时自动登录
- javascript - 无法从通过车把生成的按钮中拉出 .attr()
- node.js - 使用带有 Firebase Admin SDK 的云功能上传到 Firebase 存储时出现问题