小编Sar*_*ara的帖子

谷歌应用程序脚本:HTML - 表单提交,获取输入值

我正在尝试使用带有表单的侧边栏来获取用户输入.该代码绑定到Google表格文件.

Code.gs:

function onOpen() {
  SpreadsheetApp.getUi()
      .createMenu('Custom Menu')
      .addItem('Show sidebar', 'showSidebar')
      .addToUi();
}

function showSidebar() {
  var html = HtmlService.createHtmlOutputFromFile('Page')
      .setTitle('My custom sidebar')
      .setWidth(300);
  SpreadsheetApp.getUi()
      .showSidebar(html);
}

function processForm(formObject) {
  var ui = SpreadsheetApp.getUi();
  ui.alert("This should show the values submitted.");
}
Run Code Online (Sandbox Code Playgroud)

page.html中:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    Please fill in the form below.<br><br>
    <form id="myForm" onsubmit="google.script.run.processForm(this)">
      First name:
      <input type="text" name="firstname"><br><br>
      Last name:
      <input type="text" name="lastname"><br><br>
      Gender:<br>
      <input type="radio" name="gender" value="male" checked> Male<br>
      <input type="radio" name="gender" value="female"> …
Run Code Online (Sandbox Code Playgroud)

javascript forms user-input submit google-apps-script

4
推荐指数
1
解决办法
4844
查看次数