问题描述
我在我的项目中创建了两个名为“Input.html”和“output.html”的页面,其中单击 input.html 中的提交按钮,输出将打印在 output.html 中
代码.gs
function doGet() {
return HtmlService.createTemplateFromFile('Input')
.evaluate().setTitle("GL StyleGuide").setFaviconUrl("https://fonts.ab24dp.png");
}
在输入页面中有一个文本区域和一个提交按钮,我希望我的输出在 output.html 页面上打印。 修改:Input.html的示例html如下
<div>
<label id="label">Please Enter CSS</label>
<textarea id="input-textarea"></textarea>
<?var url = ScriptApp.getService().getUrl();?><a href='<?=url?>?v=form'><input type='button' id="submit" name='button' onclick="addRow()" value='Get Style Guide'></a>
</div>
解决方法
所以我在我的一个网络应用程序中使用的一种方法是我有一个
<div id = "app"></div>
在我想要加载另一个 HTML 的页面中。
然后我有这个功能来评估我的视图 代码.gs
function loadPartialHTML_(params) {
var htmlSrv = HtmlService.createTemplateFromFile(params);
var html = htmlSrv.evaluate().getContent();
return html;
}
然后在我的主 Html 中,我有这个函数,它接受 myView Html 并将其填充到定义的 div 中。
function loadView(options){ //loadView Function to Access Server side functions with options being an object of Parameter
var id = typeof options.id === "undefined" ? "app" : options.id; //checking if Id of Element is undefined then "app" will be used else parameter passed
var cb = typeof options.callback === "undefined" ? function(){} : options.callback; //if undefined then a blank function else function called
google.script.run.withFailureHandler(function (e){
displayToast("errorNotification",e.message);
loadingEnd();
}).withSuccessHandler(function(html){ //accessing server side function which will be supplied in object with "func:" which will return HTML
document.getElementById(id).innerHTML = html; //this is a call back funtion which gets html from server side and setting defined element to that return
typeof options.params === "undefined" ? cb() : cb(options.params); //if parameters were not supplied thn callback funtion with parameters else with parameters
})[options.func]();
}
myView HTML 将是一个只有元素的 HTML 文件,没有标题、正文等。
您可以使用事件处理程序在事件发生后加载视图。 此外,这不是我的工作,我是从一个很棒的 Youtube 频道学到的,这里有这个策略的链接,以防你卡在某个地方:Locator Strategies
我希望它能帮助您获得所需的结果。 谢谢。