簡體   English   中英

如何在Google Apps腳本中將CSS連接到html

[英]How to connect css to html in Google Apps Scripts

我正在嘗試制作我的第一個Google App。 我有我的HTML文檔,該文檔包含HTML服務:最佳做法中概述的include語句。

<html>
    <head>
        <base target="_top">
        <?!= include('stylesheet') ?>
    </head>
    <body>
       ...
    </body>

我的code.gs文件如下:

function doGet() {
   return HtmlService.createTemplateFromFile('BooksTS2.html')
  .evaluate();
}

我的樣式表名為stylesheet.html,並且出於測試目的非常簡單:

<style>
   p {color: green;}
</style>

但是,當我運行它時,出現以下錯誤消息:ReferenceError:未定義“ include”。

在他們創建可重用函數include()的示例中,您需要將其添加到code.gs文件中:

function include(filename) {
  return HtmlService.createHtmlOutputFromFile(filename)
      .getContent();
}

您總是可以像這樣在HTML文件中直接使用打印腳本

<html>
    <head>
        <base target="_top">
    <?!= HtmlService.createHtmlOutputFromFile('stylesheet').getContent(); ?>
    </head>
    <body>
       ...
    </body>
</html>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM