我一直在寻找一种方法在每个页面上获得相同的导航栏。现在,我有一个加载到每个页面上的jQuery脚本,它应该替换一个div占位符;但是,当我运行该程序时,导航栏根本就不存在。JQuery get方法似乎不起作用
jQuery代码:
$(function() {
$("#dropdown").hover(function() {
$("#submenu").stop();
$("#submenu").slideToggle(500);
});
$("#submenu").hover(function()
{
$("#submenu").stop();
$("#submenu").slideToggle(500);
});
$.get("navigation.html", function(data){
$("#nav-placeholder").replaceWith(data);
});
});
导航文件:
<nav>
<a href = "index.html">CV Game Development</a>
<div class="menu">
<div id="dropdown">Tutorials</div>
<div id="submenu">
<a href="beginner.html">Beginner</a>
<a href="intermediate.html">Intermediate</a>
<a href="advanced.html">Advanced</a>
</div>
</div>
</div>
</nav>
实际的HTML文件中使用:
<html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" type="text/css" href="main.css">
<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
<script src="main.js"></script>
<head>
<title>CV Game Development</title>
<div id = "nav-placeholder"></div>
</head>
<body>
<h1 id = "intro">Welcome</h1>
<h3 id = "subintro">to the CV Game Development website</h3>
<p id = "info">Here is an abundance of information to get you started making 2D games with GameMaker: Studio.</p>
</body>
</html>
好像它应该工作,然而,这不是“T。任何帮助非常感谢,谢谢!
是什么在你的JS控制台?你采取了哪些调试步骤? –
为什么你的'
'里面'' –你应该使用'.load()'而不是发出异步请求:https://stackoverflow.com/questions/1246137/ajax-jquery-load-versus-jquery-得到。p/s:在附注中,使用jQuery对于您的问题确实是一个非常糟糕的解决方案:改为使用模板系统(您甚至不需要CMS来完成此任务)。杰基尔是一个好开始。 – Terry