谷歌应用程序脚本-表单输入未正确提交


<form id="colours" onsubmit="doSomething()">
<label for="startcolour" style="font-family:arial">Start:</label>
<input type="color" name="startcolour" id="startcolour" value="#123456"> &nbsp;
<label for="endcolour" style="font-family:arial">End:</label>
<input type="color" name="endcolour" id="endcolour" value="#abcdef"><br><br>
<br>
<input type="submit" value="Submit">
</form>
<script>
var startcolour = document.getElementById("startcolour").value;
var endcolour = document.getElementById("endcolour").value;
function doSomething() {
google.script.run.withFailureHandler(function(error) {
console.log("error")
console.log(error.message)
}).withSuccessHandler(function(result) {
console.log("done!")
}).test(startcolour);
}
</script>

我有一个谷歌应用程序脚本HTML侧边栏。这是HTML侧边栏的一些代码。当我输入一个颜色并按下"提交"时,我希望它以startcolor的提交值作为输入来运行test((函数。但是,它使用默认值"#123456"运行,而不是用户提交的值。我该如何解决这个问题?

问题是您正在定义"startcolor";以及";endcolor";doSomething函数外部的变量,因此当调用该函数时,它使用加载页面时定义的值,而不是提交表单时可以定义的值。

解决方案将是定义变量";startcolor";以及";endcolor";在你的doSomething功能内。

最新更新