使用 Google Apps 脚本变量预填充 HTML 输入

我正在 Google Apps 脚本的侧边栏上制作一个表单,并且我想使用用户的电子邮件自动填充“邮件”输入。


我知道这个变量获取的是用户电子邮件


var email = Session.getEffectiveUser (). getEmail ();


但我不知道如何将从该变量(用户的电子邮件)获得的值传递给表单上的输入(inputmail2)。


HTML 表单代码:


<form action="">

    <div>

      <label for="inputmail2">Mail</label>

      <input type="email" id="inputmail2">

    </div>

    <div>

      <label for="inputproblem">Your Problem</label>

      <textarea id="" ></textarea>

    </div>

    <div>

      <button type="submit">Enviar</button>

    </div>

  </form>

从已经非常感谢你了!


四季花海
浏览 47回答 1
1回答

青春有我

为此,您可以使用模板化 HTML。使用 scriptlet,您可以将变量传递到 HTML,如此处所述。为此,您需要将其放入.gs代码中:var ui = SpreadsheetApp.getUi();var email = Session.getEffectiveUser().getEmail();var html = HtmlService.createTemplateFromFile('filename');html.email = email;var output = html.evaluate();ui.showSidebar(output);然后,对于您的表单,您需要插入 scriptlet<?= email ?>作为值:<form action="">&nbsp; &nbsp; <div>&nbsp; &nbsp; &nbsp; <label for="inputmail2">Mail</label>&nbsp; &nbsp; &nbsp; <input type="email" id="inputmail2" value="<?= email ?>">&nbsp; &nbsp; </div>&nbsp; &nbsp; <div>&nbsp; &nbsp; &nbsp; <label for="inputproblem">Your Problem</label>&nbsp; &nbsp; &nbsp; <textarea id="" ></textarea>&nbsp; &nbsp; </div>&nbsp; &nbsp; <div>&nbsp; &nbsp; &nbsp; <button type="submit">Enviar</button>&nbsp; &nbsp; </div>&nbsp; </form>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript