【发布时间】:2020-09-10 08:16:55
【问题描述】:
尝试使用 jQuery 加载 Bootstrap 导航。它不起作用...
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script>
$(function(){
$("#nav").load("nav.html");
});
</script>
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top" id="nav">
</nav>
这里是nav.html - 简化版。而且它没有加载。
<a class="navbar-brand" href="#">Menu</a>
【问题讨论】:
-
控制台是否出现任何错误?
-
是的 Uncaught TypeError: $(...).load is not a function at HTMLDocument.
(index.html:20) at e (jquery-3.5.1.min.js: 2) 在 t (jquery-3.5.1.min.js:2) -
尝试用这个
$(document).ready(() => { $("#nav").load("nav.html"); })替换你的JS -
同样的错误...也收到此警告 jQuery.Deferred 异常:$(...).load is not a function TypeError: $(...).load is not a function at HTMLDocument .
(file:///Users/andriigorokhovskyi/MyProject/andrii1.github.io/index.html:19:49) at e (code.jquery.com/jquery-3.5.1.min.js:2:30005) at t (code.jquery.com/jquery-3.5.1.min.js:2:30307) undefined -
@AndriiGorh 您是否尝试将您的
jQuery script放在代码开头的顶部?
标签: javascript jquery jquery-load