【问题标题】:Calling function inside an onclick using Apps Script使用 Apps 脚本在 onclick 中调用函数
【发布时间】:2018-08-15 22:59:33
【问题描述】:

我怀疑应用程序脚本服务器中有一些清理过程会阻止 onclick 命令将值传递给函数。有解决办法吗? 这是我所拥有的:

    function func() {

  var template = HtmlService.createHtmlOutputFromFile('buttons');
  var content = (template.getContent());
  Logger.log(content)
  MailApp.sendEmail({
    to: 'ggg@gmail.com',
    subject: 'subject',
    htmlBody: content

  });
}

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    Answer: <input type="text" id="myText" value="Try one button below">

<p>Try one of the answers below</p>

<button value='ttt' onclick="f1(this)">Try it</button>
<button value='ggg' onclick="f1(this)">Try it</button>
<button value='hhh' onclick="f1(this)">Try it</button>
<button value='eee' onclick="f1(this)">Try it</button>

<script>

function f1(obj){  
    if (obj.value == 'ttt'){
    document.getElementById("myText").value = 'Correct!';
    }
    else{
    document.getElementById("myText").value = 'Wrong answer..';
    }
}

</script>
  </body>
</html>

【问题讨论】:

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


    【解决方案1】:

    现代电子邮件客户端/服务不允许在电子邮件的 HTML 内容中使用 AFAIK JavaScript,因为它存在安全风险。

    相关

    【讨论】:

    • 谢谢鲁本,我担心会是这样。尽管文本字段和按钮确实出现在电子邮件中,但该函数不传递参数。得想点别的办法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-19
    • 2014-12-21
    • 1970-01-01
    • 2019-02-01
    • 2021-04-03
    • 1970-01-01
    相关资源
    最近更新 更多