php - html页面中包含css和js时的相对路径问题
问题描述
我的服务器 web 目录结构就像
/www/site1/
js/
css/
partial/
-head.php
-footer.php
view/
-page1.php
-index.php
/www/site2/
head.html 包含 js 文件,例如
<script src="js/jquery.min.js"></script>
<script src="js/jquery-ui.js"></script>
<script src="js/bootstrap.min.js"></script>
head.php 文件包含在 index.php 和 view/page1.php 中。
由于 js 文件的路径,它在 index.php 上运行良好,但在 page1.php 上运行良好。在 index.php 路径变得像
/www/site1/js/jquery.min.js
在 page1.php 路径变为
/www/site1/view/js/jquery.min.js
如何在 head.php 上包含 js,以便在包含在 index 和 page1 中时可以正常工作
解决方案
尝试在源代码中添加斜杠
<script src="/js/jquery.min.js"></script>
<script src="/js/jquery-ui.js"></script>
<script src="/js/bootstrap.min.js"></script>
推荐阅读
- kotlin - 泄漏:在垃圾收集之前未调用 ByteBuf.release()。(ReactiveMongoRepository)
- gtsummary - 在 gt 中更改单元格颜色的问题
- javascript - 如何在 React 中返回没有重复的数组或求和重复的对象
- javascript - Visual Studio 2019 Javascript - 如何引用应用程序根相对路径?
- django - 为“应用程序”目录结构注册自定义用户时遇到问题
- php - 检查 PHP 表单中的字符串,如果存在则不要发送表单并重定向到感谢页面
- hapi-fhir - 带有 Springdoc-openapi-ui 的 FHIR 模型
- java - 如何避免使用流和 if else 语句?
- ios - 在 Swift 中获取 iPhone 的蓝牙 PAN IP 地址
- ssh - 如何使用私钥创建 SSH 隧道