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

时间:2015-03-04 13:02:18

标签: javascript jquery html google-apps-script

我创建了两个HTML网页page1.htmlpage2.html。如何在第1页的按钮单击中将ID从第1页传递到第2页?

code.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>

1 个答案:

答案 0 :(得分:1)

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

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

然后在第2页中使用标签打印出id值;

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