Bootstrap V4.5 Carousel远程服务器失效,本地XAMPP正常,如何解决?
Bootstrap轮播组件远程服务器失效排查方案
Bootstrap轮播组件在本地XAMPP环境正常运行,但部署到远程主机后无法工作。已尝试FTP重装文件、修改本地链接、更换浏览器,问题仍存在。
轮播组件代码
<div id="client_reviews" class="carousel slide reveal" data-ride="carousel"> <ol class="carousel-indicators "> <li data-target="#client_reviews" data-slide-to="0" class="active"></li> <li data-target="#client_reviews" data-slide-to="1"></li> <li data-target="#client_reviews" data-slide-to="2"></li> <li data-target="#client_reviews" data-slide-to="3"></li> </ol> <div class="carousel-inner" > <div class="carousel-item active p-5" align="center"> <div class=" p-5 mb-5 border border-primary rounded container"> <div class="row justify-content-center align-items-center" style="display: flex !important; align-items:stretch !important;" > <div class="d-none d-md-none d-lg-block" style="float: left; width:auto; min-height:100%; padding-top: 45px;"> <img src="lib/content_images/about_us_images/about_us_card_img_9.png" style="width: inherit; height: inherit;"> </div> <div class="p-5" style=" width:800px; height: auto;"> <p style="color:#000; font-family: Roboto, 'Roboto Black', 'Roboto Light', 'Roboto Medium', 'Roboto Thin', 'Space Grotesk', 'Space Grotesk Light', 'Space Grotesk Medium', 'Space Grotesk SemiBold'; font-size:20px; " align="left">I would like to say that this experience was great. The team was very professional and answered all our questions and was committed to completing our project on time. We are happy to have worked with dsgnr. and would hire them again and would recommend them to anyone else looking for a designer and developer. They know their stuff! </p> </div> </div> <div class="row pl-4 pb-5 justify-content-start align-items-center"> <div class="col-3 p-2" align="right"><div style="width:70px; height: 70px; background-color: antiquewhite; border-radius:100%; border: solid 1px #000; "><img src="lib/content_images/about_us_images/about_us_card_img_7.png" style=" width: inherit; height: inherit;"></div></div> <div class="col-9" align="left"><h3>Milton Austin</h3><br /> Product Manager, Slack</div> </div> </div> </div> <div class="carousel-item p-5" align="center"> <div class=" p-5 mb-5 border border-primary rounded container"> <div class="row justify-content-center align-items-center" style="display: flex !important; align-items:stretch !important;" > <div class="d-none d-md-none d-lg-block" style="float: left; width:auto; min-height:100%; padding-top: 45px;"> <img src="lib/content_images/about_us_images/about_us_card_img_9.png" style="width: inherit; height: inherit;"> </div> <div class="p-5" style=" width:800px; height: auto;"> <p style="color:#000; font-family: Roboto, 'Roboto Black', 'Roboto Light', 'Roboto Medium', 'Roboto Thin', 'Space Grotesk', 'Space Grotesk Light', 'Space Grotesk Medium', 'Space Grotesk SemiBold'; font-size:20px; " align="left">Great work ethic and very reliable! Brooklyn was our logo designer. She walked us through many iterations and guided us on all aspects of the process. Very professional, will use them again!” </p> </div> </div> <div class="row pl-4 pb-5 justify-content-start align-items-center"> <div class="col-3 p-2" align="right"><div style="width:70px; height: 70px; background-color: antiquewhite; border-radius:100%; border: solid 1px #000; "><img src="lib/content_images/about_us_images/about_us_card_img_8.png" style=" width: inherit; height: inherit;"></div></div> <div class="col-9" align="left"><h3>Jane Cooper</h3><br /> Co-founder, Catco.</div> </div> </div> </div> <div class="carousel-item p-5" align="center"> <div class=" p-5 mb-5 border border-primary rounded container"> <div class="row justify-content-center align-items-center" style="display: flex !important; align-items:stretch !important;" > <div class="d-none d-md-none d-lg-block" style="float: left; width:auto; min-height:100%; padding-top: 45px;"> <img src="lib/content_images/about_us_images/about_us_card_img_9.png" style="width: inherit; height: inherit;"> </div> <div class="p-5" style=" width:800px; height: auto;"> <p style="color:#000; font-family: Roboto, 'Roboto Black', 'Roboto Light', 'Roboto Medium', 'Roboto Thin', 'Space Grotesk', 'Space Grotesk Light', 'Space Grotesk Medium', 'Space Grotesk SemiBold'; font-size:20px; " align="left">I would like to say that this experience was great. The team was very professional and answered all our questions and was committed to completing our project on time. We are happy to have worked with dsgnr. and would hire them again and would recommend them to anyone else looking for a designer and developer. They know their stuff! </p> </div> </div> <div class="row pl-4 pb-5 justify-content-start align-items-center"> <div class="col-3 p-2" align="right"><div style="width:70px; height: 70px; background-color: antiquewhite; border-radius:100%; border: solid 1px #000; "><img src="lib/content_images/about_us_images/about_us_card_img_7.png" style=" width: inherit; height: inherit;"></div></div> <div class="col-9" align="left"><h3>Milton Austin</h3><br /> Product Manager, Slack</div> </div> </div> </div> <div class="carousel-item p-5" align="center"> <div class=" mb-5 p-5 border border-primary rounded container"> <div class="row justify-content-center align-items-center" style="display: flex !important; align-items:stretch !important;" > <div class="d-none d-md-none d-lg-block" style="float: left; width:auto; min-height:100%; padding-top: 45px;"> <img src="lib/content_images/about_us_images/about_us_card_img_9.png" style="width: inherit; height: inherit;"> </div> <div class="p-5" style=" width:800px; height: auto;"> <p style="color:#000; font-family: Roboto, 'Roboto Black', 'Roboto Light', 'Roboto Medium', 'Roboto Thin', 'Space Grotesk', 'Space Grotesk Light', 'Space Grotesk Medium', 'Space Grotesk SemiBold'; font-size:20px; " align="left">Great work ethic and very reliable! Brooklyn was our logo designer. She walked us through many iterations and guided us on all aspects of the process. Very professional, will use them again!” </p> </div> </div> <div class="row pl-4 pb-5 justify-content-start align-items-center"> <div class="col-3 p-2" align="right"><div style="width:70px; height: 70px; background-color: antiquewhite; border-radius:100%; border: solid 1px #000; "><img src="lib/content_images/about_us_images/about_us_card_img_8.png" style=" width: inherit; height: inherit;"></div></div> <div class="col-9" align="left"><h3>Jane Cooper</h3><br /> Co-founder, Catco.</div> </div> </div> </div> <a class="carousel-control-prev" href="#client_reviews" role="button" data-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="carousel-control-next" href="#client_reviews" role="button" data-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div> </div>
Bootstrap资源链接代码
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js" integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script> <script src="lib/js/jquery.min.js"></script> <script src="lib/js/bootstrap.bundle.min.js"></script> <script language="javascript" src="lib/js/functions.js"></script> <link rel="stylesheet" href="lib/css/bootstrap/bootstrap.min.css">
排查解决步骤
- 调整资源加载顺序:当前CSS文件放在JS之后,会导致样式加载延迟甚至失效。正确顺序是:页面头部加载CSS,页面底部
</body>标签前加载JS。调整后代码如下:<!-- 页面头部 --> <link rel="stylesheet" href="lib/css/bootstrap/bootstrap.min.css"> <!-- 页面底部 </body> 前 --> <script src="lib/js/jquery.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js" integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script> <script src="lib/js/bootstrap.bundle.min.js"></script> <script src="lib/js/functions.js"></script> - 检查路径大小写:远程服务器多为Linux系统,严格区分文件名大小写。核对
lib/css/bootstrap/bootstrap.min.css等路径中的文件夹、文件名是否与服务器上的实际文件完全一致,比如避免Bootstrap和bootstrap的大小写差异。 - 验证资源加载状态:打开远程页面按F12进入开发者工具,切换到「网络」标签,刷新页面查看资源加载情况:
- 出现404错误:说明路径错误,修正后重新上传文件。
- 出现500错误:联系服务器管理员检查文件权限。
- 确认jQuery兼容性:如果使用Bootstrap 4版本,需确保jQuery版本在1.9.1及以上;Bootstrap 5无需依赖jQuery,可移除jQuery引用。检查
jquery.min.js版本,不符合则更换。 - 清理冲突样式:轮播代码中的大量内联样式(如
display: flex !important)可能覆盖Bootstrap默认样式,尝试移除这些内联样式,测试轮播是否正常,再按需调整。 - 手动初始化轮播:若自动初始化失效,在
bootstrap.bundle.min.js后添加手动初始化代码:$(document).ready(function(){ $('#client_reviews').carousel({ interval: 5000 // 自定义轮播间隔,单位毫秒 }); });
内容的提问来源于stack exchange,提问作者Raspberry
相关产品推荐
相关产品推荐

