【发布时间】:2016-07-14 22:38:40
【问题描述】:
我有一个谷歌表格脚本,允许用户输入某些数据。当用户单击确定时,我希望能够将这些值传递回谷歌应用脚本中的函数。
这是我要开始工作的 Google 工作表脚本。函数 checkLogin 确实会被调用,直到我尝试从网页将值传递给它。
脚本
function onOpen() {
openLogin();
SpreadsheetApp.getUi()
.createMenu('Dialog')
.addItem('Open', 'openLogin')
.addToUi()
}
function openLogin() {
var html = HtmlService.createHtmlOutputFromFile('index');
SpreadsheetApp.getUi()
.showModalDialog(html, 'Login Form');
}
function checkLogin(user_name, user_password, staff, student) {
SpreadsheetApp.getUi().alert(user_name);
}
网页代码如下:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<form>
First name:
<input type="text" name="user_name"><br><br>
Last name:
<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.run.checkLogin(user_name, user_password, staff, student)" />
<input type="button" value="Close"
onclick="google.script.host.close()" />
</form>
</body>
</html>
我希望有人能指出我正确的方向。谢谢
【问题讨论】:
标签: javascript html google-apps-script