【问题标题】:Google apps script: style tags work in index.html but not stylesheet.htmlGoogle 应用程序脚本:样式标签在 index.html 中有效,但在 stylesheet.html 中无效
【发布时间】:2015-07-05 14:28:55
【问题描述】:

我是 GAS 的菜鸟,所以请原谅我的愚蠢问题...

当它是 index.html 的一部分时,我的非常简单的 css 样式有效,但当它是 stylesheet.html 的一部分时无效。我究竟做错了什么?提前致谢!

index.html

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>

<script>
  $(function() {
    $( "#studPropTabs" ).tabs();
  });
</script>

<div id="studPropTabs">
  <ul>
    <li><a href="#mainTab">Basic Information</a></li>
    <li><a href="#schedTab">Schedule & Course Drops</a></li>
    <li><a href="#planTab">Planning</a></li>
    <li><a href="#miscTab">Off-campus & Partner Info</a></li>
  </ul>
  <div id="mainTab">
    <form id='propForm'>
      <fieldset>
        <div>
          <label class='mainForm' for='firstName' >First Name</label>
          <input type='text' id='firstName' />
         </div>
        <div>
          <label class='mainForm' for='lastName' >Last Name</label>
          <input type='text' id='lastName' />
        </div>
      </fieldset>
    </form>
    </div>

 </div>

stylesheet.html

<!-- This CSS package applies Google styling; it should always be included. -->
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons.css">

<style>

label {
display: inline-block;
width: 5em;
color: red;
}

</style>

code.gs

function doGet(e) {
  return HtmlService.createHtmlOutputFromFile('Index')
  .setTitle('Senior Project Proposal Form')
  .setSandboxMode(HtmlService.SandboxMode.IFRAME);
}

【问题讨论】:

    标签: html css jquery-ui google-apps-script


    【解决方案1】:

    没有总是包含的页面,你必须指定它,正如Good Practices中所说:

    在code.gs中:

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

    在 index.html 中:

    <?!= include('Stylesheet'); ?>
    

    【讨论】:

    • 感谢您的帮助!我让它工作,但前提是我使用模板化的 HTML。所以...如果你想引用 Stylesheet.html,你必须使用模板而不是 HtmlOutput。这就是我的困惑的来源。
    猜你喜欢
    • 1970-01-01
    • 2016-11-13
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-31
    • 1970-01-01
    相关资源
    最近更新 更多