gpt4 book ai didi

javascript - HtmlService GAS 在 html 表单之间传递变量

转载 作者:行者123 更新时间:2023-11-27 23:47:52 25 4
gpt4 key购买 nike

我创建了两个 HTML 页面 page1.htmlpage2.html。如何在 page1 中单击按钮时将 ID 从 page1 传递到 page2?

代码.gs:

function addAuc(form) { 
var s1 = form.ID,
s2 = form.Name,
s3 = form.Email,
html = HtmlService.createTemplateFromFile('page2');

html.setSandboxMode(HtmlService.SandboxMode.NATIVE);
html.setWidth(700);
html.setHeight(600); SpreadsheetApp.getUi().showModelessDialog(html, 'Reg');
return s1;
}

page1.html:

<form id="myForm">
<input type="button" value="Choose" onclick="google.script.run.withSuccessHandler(updateUrl).rowArray()" />
<input onclick="google.script.run.addAuc(document.forms[0])" type="button" value="Add" />
<input type="button" value="Close" onclick="google.script.host.close()" /><br/>
<label id="Name"></label>
</form>
<label id="ID">1</label>|
<label id="Name">Jon</label>|
<label id="Email">jon@email.com</label>|
<label id="Phone">004423554897</label>

page2.html:

<div class="info" >
<span id="ID" name="ID"></span>
</div>

最佳答案

在您的示例中,您会将变量传递给“html”模板对象。

html = HtmlService.createTemplateFromFile('page2');
html.id = s1;

然后在第2页使用tag打印出id值;

<div class="info" >
<span id="ID" name="ID"><?=id?></span>
</div>

关于javascript - HtmlService GAS 在 html 表单之间传递变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28855218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com