【问题标题】:HtmlService GAS pass variables between html formsHtmlService GAS 在 html 表单之间传递变量
【发布时间】:2015-03-04 13:02:17
【问题描述】:

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

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>

【问题讨论】:

    标签: javascript jquery html google-apps-script


    【解决方案1】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 2018-03-07
      • 1970-01-01
      • 2013-05-09
      • 1970-01-01
      • 1970-01-01
      • 2012-07-02
      • 2016-12-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多