Javascript 仅在刷新后加载 (Squarespace)

Javascript only loads after refresh (Squarespace)

我在方形空间网站上有一个 javascript 运行,但它似乎只在页面刷新一次后才有效。

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<script>
    $(document).ready(function(){
    $('.markdown-block .sqs-block-content h2').addClass('ui-closed').css('cursor','pointer');
    $(".markdown-block .sqs-block-content h2").nextUntil("h2").slideToggle();
    $(".markdown-block .sqs-block-content h2").click(function() {
      
      $(this).nextUntil("h2").slideToggle();
      $(this).toggleClass('ui-closed ui-open');
      });
    });
    </script>

在 Squarespace 中,当您的自定义 Javascript 仅在页面刷新后有效时,它很可能与 Squarespace's AJAX loading:

有关

Occasionally, Ajax may conflict with embedded custom code or anchor links. Ajax can also interfere with site analytics, logging hits on the first page only.

您可以为您的模板禁用 AJAX。或者,查看此处概述的其他方法: