1

我刚刚开始使用 GAS HTML 服务。我在弄清楚将 CSS 放在哪里时遇到了一些问题(我相信这很简单)。下面是一个简单的代码示例。在其中我只是想设置背景颜色。设置和组织它的正确方法是什么?

//Code.gs
function doGet() {
  return HtmlService.createTemplateFromFile("index").evaluate();
}

//index.html

<style>
body
{
background-color:#e5e6e8;
}
</style>

<html>

<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-    ui.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js">    </script>
  <body>  
    <a href = "#" id = "index1" class = "Anchor">I am index1</a>
    <a href = "#" id = "index2" class = "Anchor">I am index2a</a>
<div id="div">1</div>


<script>$(document).ready(function() {
    $("#index1").click(function() {
       $("#div").append("2");
      $("#index1").hide();
    });
});</script>

 </body>  
</html>
4

2 回答 2

1

样式标签应该放在 HTML 标签内。

//index.html

<html>

<style>
body
{
background-color:#e5e6e8;
}
</style>

<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-    ui.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js">    </script>
  <body>  
    <a href = "#" id = "index1" class = "Anchor">I am index1</a>
    <a href = "#" id = "index2" class = "Anchor">I am index2a</a>
<div id="div">1</div>


<script>$(document).ready(function() {
    $("#index1").click(function() {
       $("#div").append("2");
      $("#index1").hide();
    });
});</script>

 </body>  
</html>

https://developers.google.com/apps-script/html_service

于 2013-04-25T10:30:03.857 回答
1

我在某处找到了这种方法(当然不在谷歌文档中):我有非常标准的 .gs 和 index.html 。然后我将我的 css 分离到同一个项目中的 style.html 中,并将这段代码放在 index.html 中以引用样式表:<?!= include('style'); ?>.

然后在 .gs 我添加了这个:

function include(filename) {
  return HtmlService.createHtmlOutputFromFile(filename)
  .setSandboxMode(HtmlService.SandboxMode.NATIVE)
  .getContent();
}
于 2013-08-17T13:43:10.817 回答