。
问题描述: 在Google Apps脚本中,我想将一个变量的值传递给HTML页面进行处理,然后再将处理后的结果返回给Google Apps脚本。但是在这个过程中遇到了问题。
解决方案:
示例代码:
// Google Apps脚本
function doGet() {
var variable = "Hello World";
var template = HtmlService.createTemplateFromFile('index');
template.variable = variable;
return template.evaluate();
}
function processResult(result) {
// 处理HTML页面返回的结果
Logger.log(result);
}
// HTML模板文件(index.html)
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<h1><?= variable ?></h1>
<script>
// 处理变量并返回给Google Apps脚本
var processedResult = "Processed " + <?= variable ?>;
google.script.run.processResult(processedResult);
</script>
</body>
</html>
示例代码:
// Google Apps脚本
function doGet() {
var variable = "Hello World";
var template = HtmlService.createTemplateFromFile('index');
template.variable = variable;
return template.evaluate();
}
function processResult(result) {
// 处理HTML页面返回的结果
Logger.log(result);
}
// HTML页面中的JavaScript函数
function processVariable(variable) {
// 处理变量并返回给Google Apps脚本
var processedResult = "Processed " + variable;
google.script.run.withSuccessHandler(processResult).processResult(processedResult);
}
注意事项:
推荐的腾讯云相关产品和产品介绍链接地址:
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云