繁体   English   中英

从HTML页面运行Google表格应用脚本功能并返回表单值

[英]Running a Google Sheets App script function from an HTML page with form values returned

我正在尝试将用户在Google应用程序脚本中的网页上输入的表单的值返回给函数,然后用响应通知用户。

这是我的应用脚本

function onOpen() {
   openLogin();
   SpreadsheetApp.getUi()
     .createMenu('Dialog')
     .addItem('Open', 'openLogin')
     .addToUi()
}

function openLogin() {
   var html = HtmlService.createHtmlOutputFromFile('index');
   SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
       .showModalDialog(html, 'Login Form');
}

function checkLogin() {
   SpreadsheetApp.getUi().alert('Hello, world!'); 
}

我正在尝试让checkLogin启动。 这是HTML代码。

<!DOCTYPE html>
<html>
<head>
   <base target="_top">
</head>
<body>
  <form>    
    First name:&nbsp;&nbsp;
    <input type="text" name="user_name"><br><br>
    Last name:&nbsp;&nbsp;
    <input type="password" name="user_password"><br><br>
    Staff or Student?
    <br>

    <input type="radio" name="staff" value="staff" checked> Staff<br>
    <input type="radio" name="student" value="student"> Student<br>
    <br><br>

    <input type="button" value="OK"
    onclick="google.script.host.close()" />

    <input type="button" value="Close"
    onclick="google.script.run.checkLogin()" />

  </form> 
</body>
</html>

我的错误是我将OK和Close函数调用混在一起。 应该是

<input type="button" value="OK"
onclick="google.script.run.checkLogin()" />

<input type="button" value="Close"
onclick="google.script.host.close()" />

暂无
暂无

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

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