Google 站点可折叠列表

Google Site Collapsible List

我找到了一些资源,据说这些资源展示了如何在 Google 站点中制作可折叠列表,但似乎没有任何效果。我试过在站点中插入一个 HTML 框,以及修改 HTML 源代码。似乎 Google Sites 正在剥离任何 javascript。有没有办法解决这个问题,Google 是否有实现此目的的功能(这不是列表模板,不适合我的目的)?

以下是我试过的资源:

tutorials.seowebpower.com/google-sites-advanced/collapsible-table

sites.cognitivescience.co/knowledgebase/resources/using-google-sites/creating-information-rich-gsites-pages

How to create expandable FAQ page in HTML?

support.google.com/sites/search?q=list

我摆弄了链接问题中的一个答案,它现在似乎对我有用,给出了两个带有隐藏答案的问题,可以切换 hide/show,你应该可以将其调整为折叠一旦 hide/show 功能存在就列出。

这在 htmlbox 中

<script>
function toggleElement(myid)
{
    if(document.getElementById(myid).style.display == 'none')
    {
        document.getElementById(myid).style.display = 'block';
    }
    else
    {
        document.getElementById(myid).style.display = 'none';
    }
}
</script>

<hr>
<button id="q1">Is this question one?</button>

<div id="a1" style="display:none">
This is the first answer.
</div>
<script>
document.getElementById('q1').onclick=function(event) {toggleElement("a1"); };
</script>

<hr>

<button id="q2">Is this question two?</button>

<div id="a2" style="display:none">
This is the second answer.
</div>
<script>
document.getElementById('q2').onclick=function(event) {toggleElement("a2"); };
</script>

<hr>

查看实际效果

https://sites.google.com/site/dpcarlisle/fold

(首次点击需要很长时间才能在此处加载内容,不确定 google 站点是否允许足够的 javascript 预加载内容,但首次使用后它会按预期工作)

  • https://developers.google.com/apps-script/guides/html/中提供的文档可以帮助您。
  • 创建普通 JavaScript 可折叠列表后,必须将代码粘贴到 Index.html 文件中。
  • 获得 Code.gsIndex.html 文件后,发布项目:Publish → Deploy as Web app,然后选择 «Anyone, even anonymous».
  • 复制 «Current web app URL:» 并将其嵌入您的 Google 站点页面:Insert → Apps Script

Code.gs

function doGet() {
  return HtmlService.createHtmlOutputFromFile('Index');
}

Index.html

<!DOCTYPE html>
<html>
<head>
  <base target="_top">
</head>
<body>
  <!-- YOUR JAVASCRIPT CODE GOES HERE -->
</body>
</html>