简体   繁体   English

自定义对话框中的按钮不起作用(Google Apps脚本)

[英]Button in Custom Dialog does not work (Google Apps Script)

I have a custom dialog box with a Next button that is supposed to trigger an alert box to appear. 我有一个自定义对话框,其中有一个Next按钮,可以触发一个警告框出现。 However nothing happens when I click on Next. 但是当我点击Next时没有任何反应。

Code.gs: Code.gs:

function createInvoice() {

  var htmlOutput = HtmlService
      .createHtmlOutputFromFile("CreateInvoice1");

  SpreadsheetApp.getUi().showModalDialog(htmlOutput, "Create New Invoice");

}

CreateInvoice1.html: CreateInvoice1.html:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <form id="CreateInvoice1form">
     <div class="block form-group">
         <label for="select"> Select Client:</label>
         <select id="select">
           <option value="Cl01">Client 1</option>
           <option value="Cl02">Client 2</option>
         </select>
     </div>
     <br><br> 
     <input type="button" value="Next" onclick="Next1()">
     <input type="button" value="Close" onclick="google.script.host.close()">
   </form> 

   <script>
   function Next1() {
     var selectedClient = document.getElementbyId("select").value;

     SpreadsheetApp.getUi().alert("You are making an invoice for"+selectedClient);
   }
   </script>

  </body>
</html>

Solution (.html) 解决方案(.html)

  • Placed the script in the head as best practice 将脚本放在头部作为最佳实践
  • Used correct case as in: getElementById 使用正确的大小写:getElementById
  • dropped server side object to call the alert prompt 删除服务器端对象以调用警报提示
<head>
   <script>
   function Next1() {
     var selectedClient = document.getElementById("select").value;

     alert("You are making an invoice for"+selectedClient);
   }
   </script>
</head>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM