【问题标题】:Get inputbox populated on button click in GAS在 GAS 中单击按钮时获取输入框
【发布时间】:2014-06-02 07:02:03
【问题描述】:

首先,我的编码:

code.gs
var ui = DocumentApp.getUi();

function showSidebar() {
  var html = HtmlService.createHtmlOutputFromFile('index')
      .setTitle('My custom sidebar').setWidth(300);
  ui.showSidebar(html);
}

以上代码在 Google Doc 中打开侧边栏。

index.html
<div>
<input type="button" value="Name"
  onclick="google.script.run.updateinput()" />
<input id="name">
</div>

此代码添加一个按钮作为名称,该按钮运行下一组代码并向侧边栏添加一个输入框

  function updateinput() {
  var app = UiApp.getActiveApplication();
  Logger.log("Clicked")
  app.getElementById("name").value("This is inputbox")
  }

问题:

在单击名称按钮时,记录器会记录 Clicked 的值,但是,如何获取输入框以获取值“这是输入框”。请提出建议。

执行脚本显示以下错误“执行失败:TypeError:Cannot find function value in object Generic。”

【问题讨论】:

    标签: javascript html google-apps-script google-apps


    【解决方案1】:

    试试这个。

    app.getElementById("name").value ="This is inputbox";
    

    得到:

    var value = app.getElementById("name").value;
    

    【讨论】:

    【解决方案2】:

    HtmlService 和 UiApp 是在 Apps Script 中创建用户界面的两种截然不同的方式,它们不能混用。有关如何在 HtmlService 中在客户端和服务器之间来回发送数据的更多信息,请参阅Communicate with Server Functions guide

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-20
      • 1970-01-01
      相关资源
      最近更新 更多