php 中的 CDN 链接包含文件
CDN links in php include files
我正在使用 Bootstrap 4.4.1 进行站点项目。我使用 CDN 链接将它们放置在关闭 </body>
之前。为了避免在所有页面中进行大量编码,我想使用一个包含以下所有脚本的 php 包含文件/我将此文件命名为 "js-remote.php"。这是在名为 "js".
的文件夹中
我在每个内容页面上都插入了代码(我正在做所有 php 页面),路径是:
<?php include '../js/js-remote.php'>
但是不起作用。我也有导航栏作为包含文件,显示了菜单,但下拉菜单无法正常工作。即使我粘贴 CDN 的完整脚本代码(不使用任何 php 包含)也不起作用。
仅当我不使用包含文件时才有效,只是将完整代码作为常规 html file.Get 粘贴到我想在 php 中使用的代码下方文件。请多多指教。
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</body>
但我不想粘贴整个脚本,只想放一行:
<?php include '../js/js-remote.php' ?>
</body>
<--! Could it work?-->
其中 "js-remote.php" 是包含上述所有 cdn 脚本的页面,将来还会有更多。
对于冗余,我们深表歉意,但这是必要的。 "js-remote.php" 文件包含:
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
这是因为您需要将脚本放在文档末尾附近。
根据 docs:
Many of our components require the use of JavaScript to function.
Specifically, they require jQuery, Popper.js, and our own JavaScript
plugins. Place the following s near the end of your pages,
right before the closing tag, to enable them. jQuery must come
first, then Popper.js, and then our JavaScript plugins.
我发现此处代码编写方式存在错误,如果它们在实际文档中,这些错误会破坏功能。
include应该写成
<?php include '../js/js-remote.php'; ?>
在您的 post 中,您在第一种情况中遗漏了分号和 ?>
,在第二种情况中遗漏了最后的引号和分号。
我正在使用 Bootstrap 4.4.1 进行站点项目。我使用 CDN 链接将它们放置在关闭 </body>
之前。为了避免在所有页面中进行大量编码,我想使用一个包含以下所有脚本的 php 包含文件/我将此文件命名为 "js-remote.php"。这是在名为 "js".
我在每个内容页面上都插入了代码(我正在做所有 php 页面),路径是:
<?php include '../js/js-remote.php'>
但是不起作用。我也有导航栏作为包含文件,显示了菜单,但下拉菜单无法正常工作。即使我粘贴 CDN 的完整脚本代码(不使用任何 php 包含)也不起作用。
仅当我不使用包含文件时才有效,只是将完整代码作为常规 html file.Get 粘贴到我想在 php 中使用的代码下方文件。请多多指教。
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</body>
但我不想粘贴整个脚本,只想放一行:
<?php include '../js/js-remote.php' ?>
</body>
<--! Could it work?-->
其中 "js-remote.php" 是包含上述所有 cdn 脚本的页面,将来还会有更多。
对于冗余,我们深表歉意,但这是必要的。 "js-remote.php" 文件包含:
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
这是因为您需要将脚本放在文档末尾附近。
根据 docs:
Many of our components require the use of JavaScript to function. Specifically, they require jQuery, Popper.js, and our own JavaScript plugins. Place the following s near the end of your pages, right before the closing tag, to enable them. jQuery must come first, then Popper.js, and then our JavaScript plugins.
我发现此处代码编写方式存在错误,如果它们在实际文档中,这些错误会破坏功能。 include应该写成
<?php include '../js/js-remote.php'; ?>
在您的 post 中,您在第一种情况中遗漏了分号和 ?>
,在第二种情况中遗漏了最后的引号和分号。