【发布时间】:2021-04-30 00:53:52
【问题描述】:
跟进ToggleButton for Google HtmlService,最后说:
在我提供的HTML demo code 中,我能够使用
form.myButton.value,但问题是当我尝试使用它从Google App Code 函数中更新我的标签时,就像@987654323 一样@ 正在做,它总是失败,我不知道为什么。
以下是详细信息:
HTML
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<h2>Feedback Form</h2>
<div id="message" style="color:green"></div>
<form id="myForm">
<br /><input id="name" type="text" name="name" placeholder="Your Name">
<br /><input id="email" type="email" name="email" placeholder="Your Email">
<br /><input type="button" name="myButton" value="OFF" style="color:blue"
onclick="toggle(this);">
<br /><textarea id="comment" rows="10" cols="40" name="comment"></textarea>
<br /><input type="button" value="Submit" onclick="submitForm(this.parentNode);" />
</form>
<script>
var state = false;
// Toggles the passed button from OFF to ON and vice-versa.
function toggle(button) {
state = !state;
if (state) {
button.value = "ON";
} else {
button.value = "OFF";
}
}
function submitForm(form) {
google.script.run
.withSuccessHandler(function(value){
document.getElementById('message').innerHTML = value;
document.getElementById("myForm").reset();
})
.submitData(form);
}
</script>
</body>
</html>
气体
// https://stackoverflow.com/questions/59583876/google-apps-script-html-form/
//It works as a dialog
function showTheDialog() {
var userInterface=HtmlService.createHtmlOutputFromFile('Index');
SpreadsheetApp.getUi().showModelessDialog(userInterface, "Form")
}
// Test at
// https://jsbin.com/vodamekuxu/edit?html,js,console,output
function submitData(form) {
Logger.log('name: %s <br />Email: %s<br />Comment: %s', form.name,form.email,form.comment);
return Utilities.formatString('name: %s <br />Email: %s<br />Comment: %s', form.name,form.email,form.comment);
//return Utilities.formatString('name: %s <br />Email: %s<br />Toggle: %s<br />Comment: %s', form.name,form.email,form.myButton,form.comment);
}
同样,问题是当我尝试从 Google App Code 函数中更新我的标签时,就像 HTML 演示代码所做的那样,它总是失败,我不知道为什么。
上面的代码有效,但是如果切换到使用第二个返回,它会失败(我相信是因为form.myButton 部分)。
【问题讨论】:
-
表格上的所有内容似乎都对我有用。我不知道你说的是什么标签我在你的表格上没有看到任何标签。您改为使用占位符。消息从 submitData() 函数返回并显示 div。所以我看不到你所说的问题。无论如何,引用非现场资源对我没有用,因为我不关注大多数链接。
-
@MetaMan,我的 HTML 和 GAS 包含您需要的一切。请重新打开它。如果一切都为你工作,那是我的意图,表明一切都在工作。然后你需要注释掉第一个返回并取消注释第二个返回,当你会注意到事情不再工作时。
标签: javascript google-apps-script