我已经浏览了大部分与此相关的问题,但没有找到对我有帮助的解决方案(我已经一一应用了它们)。我有一个 HTML 表单,我正在通过 google 将其发布为网络应用程序。我需要用该参数预先填充输入框。
code.gs
function doGet() {
return HtmlService
.createTemplateFromFile('html')
.evaluate();
}
html.html
<!DOCTYPE html>
<html>
<head>
</head>
<style>
</style>
<body>
<form>
<h1><center>Verification</center></h1>
Form ID:<input type="number" name="formid" id="formid" class="formid">
</form>
</body>
</html>
正如我所说,我在类似问题中尝试了很多建议,但似乎找不到有效的建议。 id 是我可以输入我的 url + ?formid= 并将其填充在输入中。我怎样才能按照描述的那样实现这一点?
谢谢你!
- When Web Apps is accessed with the URL of
url + ?formid=###
, you want to put the value of ###
to the text box.
- 网址就像
https://script.google.com/macros/s/###/exec?formid=###
.
如果我的理解是正确的,这个答案怎么样?请将此视为多个答案之一。
修改点:
- 在这次修改中,我使用了
google.script.url.getLocation()
用于检索查询参数。
修改后的脚本:
请修改html.html
如下。
<!DOCTYPE html>
<html>
<head>
</head>
<style>
</style>
<body>
<form>
<h1><center>Verification</center></h1>
Form ID:<input type="number" name="formid" id="formid" class="formid">
</form>
<script>
google.script.url.getLocation(function(location) {
document.getElementById("formid").value = location.parameters.formid[0];
});
</script>
</body>
</html>
- 通过上述修改,当您使用以下方式访问Web Apps时
https://script.google.com/macros/s/###/exec?formid=12345
, 12345
被放入文本框。
参考:
- 获取位置(函数) https://developers.google.com/apps-script/guides/html/reference/url#getlocationfunction
如果我误解了你的问题并且这不是你想要的方向,我很抱歉。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)