问题描述
我有一个文件中的引导导航栏, navbar.html
,我加载到我的HTML页面与 Jquery.load()
I have a bootstrap navbar in a file, navbar.html
and I load it into my HTML page with Jquery.load()
我在HTML网页底部有这个:
I have this at the bottom of my HTML page:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(function(){
$("#navbar-partial").load("navbar.html");
});
</script>
和< div id =navbar-partial>< / div> ;
and <div id="navbar-partial></div>
is in the HTML page.
在navbar-partial之后,我有一个主内容div和页面上的其他内容。内容加载首先,然后navbar看起来粘性如果我把navbar代码在每个文件加载首先,似乎从来没有改变,加载快,但我想提取的代码到一个文件,所以我不必须对其进行编辑。
After the navbar-partial I have a main-content div with everything else on the page. The main-content loads first, and then the navbar does which looks "tacky". If i put the navbar code in every file it loads first and appears to never change, loads fast, but I want to extract the code into one file so I dont have to edit it everywhere.
任何想要使导航条部分加载首先或更快?我将脚本标签移动到头,也没有帮助。
Any ideas on have to make the navbar-partial load first or faster? I moved the script tags into the head and that didnt help either.
感谢
推荐答案
$
只要您的代码在之后 >
<div id="navbar-partial></div>
<script>
$("#navbar-partial").load("navbar.html");
</script>
您仍然依赖于加载延迟,因此不要指望奇迹:)
You are still dependent on the loading delay, so do not expect miracles :)
这个问题的正确解决方案通常是一个服务器端的东西,但是因为你正在使用纯HTML文件,现在必须这样做。
The proper solution to this problem is normally a server-side thing, but as you are using plain HTML files, this will have to do for now.
这篇关于使jquery.load在HTML加载之前发生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!