为什么要在jQuery周围使用输出缓冲?

Why would you use output buffering around jQuery?

提问人:peter oehman 提问时间:11/18/2022 最后编辑:bibermanpeter oehman 更新时间:11/18/2022 访问量:42

问:

我正在处理一个已经有一些代码的文件,它围绕正在使用的 jQuery 使用 php 的 ob_start() 和 ob_get_clean() 函数。为什么有人会这样做有明确的理由吗?

  ob_start();
?>

<script>
    $(document).ready(function() {
    $('div.scripture').on('click', function() {
      $('div#schedule div.text').slideUp();
      text = $(this).next('div.text');
      
      if (text.is(":visible") == true) {
        text.slideUp();
      } else {
        text.slideDown();
      }
    });
    });
</script>

<?php
  $additionalJS = (!empty($additionalJS)) ? $additionalJS : NULL;
  $additionalJS .= ob_get_clean();
php jquery 输出缓冲

评论

0赞 Barmar 11/18/2022
它与jQuery无关。它只是一种与 HTML 代码连接的方式。$additionalJS
1赞 Alex Howansky 11/18/2022
如果你使用 PHP 动态生成 JS 的某些部分,你可能会做这样的事情,但这不会在这里发生,所以......不确定?这是一种相当迂回的方式——也许作者想保持缩进,不想使用 heredoc。$additionalJS = 'a really long string';

答: 暂无答案