javascript - 将 Javascript 变量传递给 Google 脚本函数 (Google Sheets)

标签 javascript html image google-apps-script google-sheets

我有一个 JavaScript 函数,它获取 src 值

<div>
  <img src="theUrl" id="imgID" onclick="myImageUrl()" />
</div>

<script>

  function myImageUrl() {
    var q = document.getElementById(imgID).src;
      google.script.run
       .imageCell();
  }

</script>

我似乎不知道如何将其传递到 Google Apps 函数中,以便我可以将图像 URL 实现到单元格中,例如

function imageCell() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var range = ss.getActiveRange();

  range.setValue(q);
}

更新:

感谢阿米特,但除非我遗漏了一些东西,否则该值不允许使用保存的变量。我以两种方式运行

HTML

 <div id="theImageUrl">
    <img src="http://placekitten.com/100/100" id="theImageUrl" onclick="getImage()" />      
    </div>
    <script>
        function getImage() {
            q = document.getElementById( 'theImageUrl ).src;
            google.script.run.imageCell(q);
            }
        </script>

由我的 fiddle 验证Fiddle

服务器端

function imageCell(q) {
   var ss = SpreadsheetApp.getActiveSpreadsheet();
 var range = ss.getActiveRange();

range.setValue(q);
}

*.setValue(q) 和 .setValue();

最佳答案

在 HTML 方面:

google.script.run.imageCell(q);

在服务器端:

函数 imageCell(q) { ...

关于javascript - 将 Javascript 变量传递给 Google 脚本函数 (Google Sheets),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29002585/

相关文章:

javascript ecma6 将数组项转换为键值对的对象

javascript - 倒计时时钟不会在刷新时重置

javascript - jQuery 无法从另一个按钮单击触发按钮单击

javascript - 是否有任何不能内联的 CSS 属性?

javascript - 单击单选按钮时 div 不隐藏

javascript - Affdex JS SDK - 无法从相机检测器获取回调

javascript - 我本地网页上的 moviemodeapp 脚本

javascript - 通过 jquery 或 css 更改图像大小(宽度)

javascript - JS : more efficient way to call an image

java - 存储在磁盘上的图像 - 按名称搜索