Javascript 谷歌应用程序脚本不能从表单表中设置值
我有一个html表单,比如Javascript 谷歌应用程序脚本不能从表单表中设置值,javascript,google-apps-script,google-sheets,Javascript,Google Apps Script,Google Sheets,我有一个html表单,比如 <script> function formSubmit() { google.script.run.getValuesFromForm(document.forms[0]); } </script> <form> <table border="1" cellpadding="1" cellspacing="1" style="width: 500px;"> <
<script>
function formSubmit() {
google.script.run.getValuesFromForm(document.forms[0]);
}
</script>
<form>
<table border="1" cellpadding="1" cellspacing="1" style="width: 500px;">
<tbody>
<tr>
<td>
<input id="date" name="date" style="width:125px;" type="date" />
</td>
<td>
<input id="type" name="type" style="width:125px;" type="text" />
</td>
<td>
<input id="status" name="status" style="width:125px;" type="text" />
</td>
<td>
<input id="name" name="name" style="width:125px;" type="text" />
</td>
<td>
<input id="comment" name="comment" style="width:125px;" type="text" />
</td>
<td>
<input id="where" name="where" style="width:125px;" type="text" />
</td>
</tr>
</tbody>
</table>
</form>
<input onclick="formSubmit()" type="button" value="Submit" />
但这段代码也很有效
第页附录行([s1、s2、s3、s4、s5、s6])
我做错了什么?您需要读取输入元素的
值
属性:
var s1 = form.date.value,
s2 = form.type.value,
s3 = form.status.value,
s4 = form.name.value,
s5 = form.comment.value,
s6 = form.where.value,
您必须在HTML中的某个地方有一个调用服务器端代码的
google.script.run
google.script.run
是一个API,它使您能够从用户计算机与谷歌的服务器进行通信
我在代码中没有看到submit
按钮,或
标记,或onClick
事件。配置表单提交有多种方法,但需要调用google.script.run.myServerFunctionName()
来触发.gs
应用程序脚本文件中的函数
您可以直接从提交按钮使用google.script.run
:
<input type="button" value="Not Clicked"
onclick="google.script.run
.withSuccessHandler(updateButton)
.withUserObject(this)
.getEmail()" />
,或具有HTML onclick事件属性的按钮:
<button onclick="myFunction()">Click me</button>
<form onsubmit="myFunction()">
Enter name: <input type="text">
<input type="submit">
</form>
点击我
或HTML onsubmit事件属性:
<button onclick="myFunction()">Click me</button>
<form onsubmit="myFunction()">
Enter name: <input type="text">
<input type="submit">
</form>
输入名称:
从脚本标记:
<script>
function myFunction() {
google.script.run.doSomething();
};
</script>
函数myFunction(){
google.script.run.doSomething();
};
您可以通过各种方式传递数据。有很多方法可以配置HTML和客户端代码。
var rowData=[[s1,s2,s3,s4,s5,s6]];
sheet.insertRowBefore(index).getRange(index, 1,1,6).setValues(rowData);
您是否检查了
表单
变量的数据类型,以及该变量是否包含任何内容,或者是否为未定义的
?变量不未定义,仅清空如果其中一个字段id为空,则该行根本不插入