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

时间:2019-04-18 12:20:41

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

我有一个带有“下一步”按钮的自定义对话框,该按钮应该触发一个警报框出现。但是,当我单击“下一步”时,没有任何反应。

Code.gs:

function createInvoice() {

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

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

}

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>

1 个答案:

答案 0 :(得分:0)

解决方案(.html)

  • 将脚本作为最佳做法放在首位
  • 使用正确的大小写,例如:getElementById
  • 放置服务器端对象以调用警报提示
<head>
   <script>
   function Next1() {
     var selectedClient = document.getElementById("select").value;

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