0

我有两个文件:谷歌脚本中的 myPage.html 和 myCode.gs。我已将 html 文件部署为 Web 应用程序,并且我已经(在帮助下)弄清楚了如何使“提交”按钮的 onclick 事件触发 myCode.gs 文件中的 emailTech 功能就好了。我还能够将 html 文件中文本框中的值插入到从 onClick 事件调用的电子邮件中。

我还有两个复选框,如果选中,我希望将它们的值输入到由 onClick 事件触发的电子邮件中。我在 html 文件的脚本和 emailTech 函数中都尝试了各种版本的“如果检查然后”语句,但似乎都不起作用。有什么建议么?

myPage.html 文件:

<head>
    <title>Test Page</title>
</head>

<body>
    <form>
        <input type="text" value=" " name="techEmail" />
        <input type="checkbox" name="checkone" value="checkone" />Checkone
        <input type="checkbox" name="checktow" value="checktwo" />Checktwo
        <input type="button" onClick="formSubmit()" value="Submit" />

    </form>
</body>
<script type="text/javascript">
    function formSubmit() {
        google.script.run.emailTech(document.forms[0]);
    }
</script>

myCode.gs 文件:

function doGet() {
  return HtmlService.createHtmlOutputFromFile('myPage');
}

function emailTech(form){
//I want something along the lines of:
  //if form.checkone == "checked"{
    //var checkone = "checkone"
    //}
  //if form.checktwo == "checked"{
    //var checktwo = "checktwo"
    //}
  var nameBox = form.techEmail;
  var message = "This is the text box value" + nameBox + checkone + checktwo;
  MailApp.sendEmail("email@somewhere.com", "This is the subject", message );

}

另外,有没有办法在点击提交按钮时清除文本框和复选框?我不想有一个单独的重置按钮,如果可能的话,我希望它可以重置并一键发送电子邮件。提前致谢!

4

1 回答 1

0

复选框输入不应位于自闭合标签中。(那是以 . 结尾的/>。)您还需要将您的value设置与您将在处理程序中查找的内容(“已检查”)保持一致。像这样更改您的html:

    <input type="checkbox" name="checkone" value="checked" >Checkone
    <input type="checkbox" name="checktow" value="checked" >Checktwo

现在在您的服务器端处理程序中,您可以只检查是否存在“checkone”和/或“checktwo”,因为它们只会在检查时在事件中传递。您也可以按照您的计划检查该值。

只需从您的“愿望”中删除注释,修复语法,就可以了!

于 2013-05-23T17:58:18.863 回答