如何将html变量传递给htmlservice [英] How to pass an html variable to htmlservice
本文介绍了如何将html变量传递给htmlservice的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试动态构建列表并将其嵌入到html脚本中.以下脚本的问题在于,我传递的htmlimg值没有读取html代码标签,而只是使代码在网站上可见.
I am trying to dynamically build a list and embed it into an html script. The problem with the below script is that the htmlimg value that I am passing is not reading the html code tags and just making the code visible on the site.
Code.gs
function doGet() {
var htmlimg = '<img src="http://www.fhuhs.org/files/slide1.png">';
htmlimg += '<img src="http://www.fhuhs.org/files/slide2.png">';
htmlimg += '<img src="http://www.fhuhs.org/files/slide3.png">';
htmlimg += '<img src="http://www.fhuhs.org/files/slide4.png">';
var output = HtmlService.createTemplateFromFile('slideShow');
output.htmlimg = htmlimg;
return output.evaluate();
}
slideShow.html
slideShow.html
<style>
#slideshow, #initial {
position: relative;
width: 800px;
height: 240px;
}
#slideshow > img {
position: absolute;
}
</style>
<div id="initial"> <img src="https://16077c1df3a89c327142d4d58315918890da5bae.googledrive.com/host/0B4GLYStYeHYkRGRTdHl5TVVjOHM/slide1.png"></div>
<div id="slideshow" style="display:none">
<?= htmlimg; ?>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"> </script>
<script>
//http://css-tricks.com/snippets/jquery/simple-auto-playing-slideshow/
$("#slideshow > img:gt(0)").hide();
setInterval(function() {
$('#slideshow > img:first')
.fadeOut(1000)
.next()
.fadeIn(1000)
.end()
.appendTo('#slideshow');
}, 3000);
$('#initial').hide();
$('#slideshow').show();
</script>
推荐答案
您需要调用一个将返回某些内容的函数
You need to call a function that's going to return something
Code.gs
function doGet() {
var output = HtmlService.createTemplateFromFile('slideShow');
return output.evaluate();
}
function getImages() {
var htmlimg = '<img src="http://www.fhuhs.org/files/slide1.png">';
htmlimg += '<img src="http://www.fhuhs.org/files/slide2.png">';
htmlimg += '<img src="http://www.fhuhs.org/files/slide3.png">';
htmlimg += '<img src="http://www.fhuhs.org/files/slide4.png">';
return htmlimg;
}
slideshow.html
slideshow.html
<div>
<? var images = getImages(); ?>
<?= images ?>
</div>
这篇关于如何将html变量传递给htmlservice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文