将URL参数传递到HTML表单Google Web App 修改点:修改后的脚本:参考:

我已经解决了与此有关的大多数相关问题,但还没有找到一种对我有帮助的解决方案(我已逐一应用它们)。我有一个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 =并将其填充到输入中。我该如何按照说明进行操作?

谢谢!

zerowang1985 回答:将URL参数传递到HTML表单Google Web App 修改点:修改后的脚本:参考:

  • 使用URL url + ?formid=###访问Web Apps时,要将###的值放在文本框中。
    • URL类似于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>
  • 通过上述修改,当您使用https://script.google.com/macros/s/###/exec?formid=12345访问Web Apps时,12345将被放置到文本框中。

参考:

如果我误解了您的问题,而这不是您想要的方向,我深表歉意。

,

使用Jquery:

<script>
$(function(){
  google.script.run
  .withSuccessHandler(function(v){
    $('#formid').val(v);
   })
   .getTheValueOfV();
});
</scrip>

使用常规JavaScript

<script>
window.onload=function(){
  google.script.run
  .withSuccessHandler(function(v){
     document.getElementById('formId').value=v;
   })
  .getTheValueOfV();
};
</script>

Code.gs:

function getTheValueOfV() {
  var ss=SpreadsheetApp.getActive();
  return ss.getRangeByName("TheRangeWhereYouFindtheValueofv").getValue();
}

您可以根据需要将脚本放在头部或正文中。如果您使用JQuery,则头部需要这样的内容。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
本文链接:https://www.f2er.com/3141364.html

大家都在问