this.parentNode
onclick="google.script.run.withSuccessHandler(showMsgForLoginAttempt)
.checkLogin(this.parentNode)" />
添加
<script>
标记到
index.html
带有成功处理程序的文件。添加
withSuccessHandler()
到
google.script.run
服务器调用。
索引html:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<form>
First name:
<input type="text" name="user_name"><br><br>
Password:
<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.withSuccessHandler(showMsgForLoginAttempt).checkLogin(this.parentNode)" />
<input type="button" value="Close"
onclick="google.script.host.close()" />
</form>
</body>
<script>
window.showMsgForLoginAttempt = function(valueFromServer) {
console.log('showMsgForLoginAttempt ran');
alert('Your attempt: ' + valueFromServer);
};
</script>
</html>
服务器代码:
function checkLogin(formObject) {
var passwordsMatch;
Logger.log('formObject: ' + formObject)
Logger.log('formObject: ' + formObject.user_name);
formObject
//SpreadsheetApp.getUi().alert('Hello, world!');
passwordsMatch = true; //check password
if (passwordsMatch) {
return true;
} else {
return false;
}
}