在应用程序脚本中,如何在index.html中包含script.html文件(不带<script>标签)

问题描述 投票:0回答:1

我有 google app 脚本应用程序,文件 script.html 使用下面的函数包含在 index.html 中,并且工作正常。但是,script.html有script标签,这会阻止搜索函数定义,我想将script.html包含在index.html中,而不在script.html文件中包含script标签。

包含功能:

function include(filename) {
  return HtmlService.createHtmlOutputFromFile(filename).getContent();
}
google-apps-script web-applications
1个回答
0
投票

只需将脚本选项卡放入 html 页面即可。

HTML_测试

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <input id="test" type="button" value="Click Me" onclick="testOnClick()">
    <script>
      <?!= include("JS_Test"); ?>
    </script>
  </body>
</html>

JS_测试

function testOnClick() {
  alert("Hello");
}
© www.soinside.com 2019 - 2024. All rights reserved.