html - 将 URL 参数传递给 HTML 表单 Google Web App
问题描述
我已经解决了大多数与此相关的问题,但没有找到对我有帮助的解决方案(我已经一一应用了它们)。我有一个 HTML 表单,我通过 google 将其作为网络应用程序发布。我需要用该参数预填充一个输入框。
代码.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= 并将其填充到输入中。我怎样才能做到这一点?
谢谢!
解决方案
- 当使用 的 URL 访问 Web 应用程序时
url + ?formid=###
,您希望将 的值放入###
文本框中。- URL 就像
https://script.google.com/macros/s/###/exec?formid=###
.
- URL 就像
如果我的理解是正确的,这个答案怎么样?请认为这只是几个答案之一。
修改点:
- 在此修改中,我用于
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
将被放入文本框中。
参考:
如果我误解了您的问题并且这不是您想要的方向,我深表歉意。
推荐阅读
- sql - SQL 查询以获取过去 12 个月内匹配条件的记录的运行总计
- mysql - 在特定字符串中的列值精确的表中搜索
- python - 将Excel中的数据扫描到python时如何设置自动DataFrame结构?
- c++ - 我想在 C++ 中实现映射,因为我无法检查矢量大小并为我制作的矢量赋值
- python - 为什么 Python venvs 在它们的配置中有一个“home”设置,而它们也有一个 python.exe 文件?
- powerbi - 根据 Power BI 中的开始和结束日期计算活动合同?
- express - 处理 connect-history-api-fallback 和 Express 中的斜杠
- lxml - 您如何获得根元素下的所有内容?
- oop - DART 中类字段的默认值
- r - 如何在 Mac 上的 Shiny 中将文件名传递给 downloadHandler