【问题标题】:Google Apps Script TextareaGoogle Apps 脚本文本区域
【发布时间】:2016-11-22 19:32:09
【问题描述】:

我有以下基本代码来尝试更改 textarea 元素的值。使用标准 HTML 效果很好;但是,使用 Google Apps 脚本将无法正常工作。该程序将包含更多内容,其中将通过 \n 包含额外的行,因此无法使用标准输入标记 - 这只是我需要在元素中填充文本的基本部分。有谁知道这是否可以通过 GAS 实现?注意,只想使用 HTML 文件,而不是纯 GAS JavaScript。

<!DOCTYPE html>
<base target="_top">
<button id=calc>test</button>
<textarea id=t></textarea>
<script>
document.getElementById("calc").onclick=function(){
document.getElementById("t").value="test";
}
</script>

【问题讨论】:

  • 尝试调用console.log(document.getElementById("calc")),函数运行时查看是否存在。

标签: javascript html google-apps-script


【解决方案1】:

你好像忘了把“calc”和“t”放在像这样的引号内 - “id_of_an_element”

当我使用 Visual Code 检查它是否在纯 HTML 中工作时,它修复了它,但在 Google Apps Script 中它没有

我在 Google Apps Script 中测试了以下代码,它可以工作,希望对您有所帮助

<!DOCTYPE html>
<html lang="en">
<body>
<base target="_top">
<button id="calc">test</button>
<textarea id="t">my text area inital value</textarea>

<script>
  document.getElementById("calc").onclick=function(){
    document.getElementById("t").value="test";
  }
</script>

</body>
</html>

【讨论】:

  • 谢谢 Meir - 我只是对它和 GAS 的设计方式进行了更多测试,只需要引用 textarea id。它还需要引用“选择”元素 ID。基本上除了标准输入之外的所有内容。我知道这是正确的写作方式,我只是尽量保存所有字节(即使它像 Google 一样免费),我正在从中吸取教训。谷歌正在强迫它,由于限制,我只需要开始正确编码。再次感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多